Sitelet https://github.com/rystaf/wikiwhen/commit/391f7d1f2ad821b592f4b3d2fdd881f6e5737491
Skip to content

Commit 391f7d1

Browse files
committed
wordleized
1 parent 08b1447 commit 391f7d1

2 files changed

Lines changed: 20 additions & 16 deletions

File tree

‎app.js‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
min = 1880
22
weight = 50
3-
now = (new Date()).getFullYear()
3+
now = new Date()
44
var year
55
var countries = []
66
var country
77
var picks = []
88
var r = 0
99
document.getElementById("score").value = 0
10+
var random = module.exports(now.getDate()+now.getMonth()+now.getYear())
1011
getRandom = photos => {
1112
if (!photos) { return "" }
12-
i = Math.floor(Math.random()*photos.length)
13+
i = Math.floor(random()*photos.length)
1314
member = photos[i]
14-
console.log("pick", member.title)
1515
source = member?.thumbnail?.source
16+
console.log("pick", member.title, source)
1617
if (member.title.slice(0,4) == "File" && !source) {
1718
return getRandom(photos)
1819
}
@@ -28,6 +29,10 @@ getPhoto = async (category, once) => {
2829
resp = await fetch(`https://commons.wikimedia.org/w/api.php?action=query&format=json&origin=*&prop=pageimages&generator=categorymembers&formatversion=2&pithumbsize=1000&pilicense=free&gcmtitle=Category%3A${category}&gcmtype=file|subcat&gcmlimit=max`)
2930
members = await resp.json()
3031
pick = getRandom(members?.query?.pages)
32+
if (pick == "") {
33+
year = (curYear - Math.floor(random()*(curYear-min)))
34+
return getPhoto(year + " photographs by country")
35+
}
3136
if (/[0-9]{4} photographs by country/.test(category)) {
3237
console.log("Main")
3338
countries = members?.query?.pages?.map(x => x?.title?.slice(29)?.replace(/^the /,"")).sort()
@@ -40,7 +45,8 @@ getPhoto = async (category, once) => {
4045
return pick
4146
}
4247
getNext = async () => {
43-
year = (now - Math.floor(Math.random()*(now-min)))
48+
curYear = now.getFullYear()
49+
year = (curYear - Math.floor(random()*(curYear-min)))
4450
var photo
4551
if (!picks[r]) {
4652
photo = await getPhoto(year + " photographs by country")
@@ -56,8 +62,8 @@ getNext = async () => {
5662
let range = document.createElement("input")
5763
range.type = "range"
5864
range.min = min
59-
range.max = now
60-
range.value = (min+Math.ceil((now-min)/2))
65+
range.max = curYear
66+
range.value = (min+Math.ceil((curYear-min)/2))
6167
let text = document.createElement("input")
6268
text.type="text"
6369
text.value=range.value
@@ -122,26 +128,20 @@ getNext = async () => {
122128
document.body.appendChild(document.createElement("br"))
123129
document.body.appendChild(submit)
124130
if (photo.round == "5/5") {
125-
submit.value= "New"
126-
let link = document.createElement("input")
127-
link.type = "text"
128-
link.id = "link"
129-
link.value = window.location.origin + window.location.pathname
130-
link.value+="?p="
131-
link.value+=btoa(picks.map(x => [x.pageid,x.country,x.year].join('.')).join('-'))
131+
submit.remove()
132132
let share = document.createElement("input")
133133
share.value = "Share"
134134
share.type = "Submit"
135135
share.addEventListener("click", ()=>navigator.share({
136136
title: "Wiki When",
137-
text: `I scored ${score.value} at ${document.getElementById("link").value}`,
138-
url: document.getElementById("link").value
137+
text: `I scored ${score.value} at ${window.location.origin}}`,
138+
url: window.location.origin
139139
}))
140140
if (navigator.share) {
141141
document.body.appendChild(share)
142142
}
143143
document.body.appendChild(document.createElement("br"))
144-
document.body.append(link)
144+
document.body.appendChild(document.createElement("br"))
145145
} else {
146146
submit.value= "Next"
147147
}

‎index.html‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@
99
<body>
1010
<h1>Wiki When</h1>
1111
<label for="score">Score: <input id="score" type="text" value="0" disabled></label>
12+
<script type="text/javascript">
13+
var module = {}
14+
</script>
15+
<script src="https://unpkg.com/arbit"></script>
1216
<script src="app.js"></script>
1317
</body>

0 commit comments

Comments
 (0)