-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
213 lines (206 loc) · 5.76 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<!DOCTYPE html>
<meta name=viewport content="width=device-width, user-scalable=no">
<link href='http://fonts.googleapis.com/css?family=Chela+One|Special+Elite|Boogaloo|Jolly+Lodger' rel='stylesheet' type='text/css'>
<style type="text/css">
body {
background: #363;
color: white;
text-align: center;
}
* {
margin-left: auto;
margin-right: auto;
}
h1 {
font-size: 300%;
font-family: "Chela One";
font-weight: normal;
color: white;
text-shadow: 0.06em 0.06em 0 black;
letter-spacing: 0.08em;
margin: 0;
}
#running {
font-size: 200%;
color: #aaf;
text-shadow: 0.06em 0.06em 0 black;
font-family: "Boogaloo";
margin-top: 1em;
}
#words {
font-family: "Special Elite";
font-size: 160%;
padding: 0.4em;
color: white;
background: rgba(0,0,0,0.5);
line-height: 1.3;
letter-spacing: 0.06em;
}
#linktorepo a {
font-size: 200%;
color: #aaf;
text-shadow: 0.06em 0.06em 0 black;
font-family: "Boogaloo";
margin-top: 1em;
text-decoration: none;
}
button {
font-family: "Boogaloo";
font-size: 200%;
border-color: gray;
border-radius: 0.6em;
padding: 0.3em;
background: #050;
color: white;
text-shadow: 0.08em 0.08em 0 black;
}
button:focus {
outline: none;
border-color: white;
}
#gobutton {
font-size: 250%;
}
#error {
font-size: 200%;
font-family: "Jolly Lodger";
margin: 0.5em;
color: #FAA;
text-shadow: 0.08em 0.08em 0 black;
}
#results {
border-spacing: 0;
font-family: "Boogaloo";
font-size: 150%;
margin-top: 1em;
margin-bottom: 1em;
max-width: 20em;
}
#results tr:first-child td {
border-bottom: thin gray outset;
}
#results tr:nth-child(2) td {
border-top: thin gray outset;
}
#results th, td {
padding: 0.2em 0.8em;
}
#results tr:nth-child(even) {
background: rgba(0,0,0,0.1);
}
#results td:first-child {
border-right: thin gray outset;
}
#results td:nth-child(2) {
border-left: thin gray outset;
}
</style>
<title>puz.link - find connections between words</title>
<h1>puz·link</h1>
<div id=running style="display:none">Analyzing....</div>
<div id=error style="display:none"></div>
<table id=results></table>
<form>
<p><textarea id=words name=words rows=8 cols=20 placeholder="Input a set of words." autofocus required></textarea>
<p><button type=button onclick="go()" id=gobutton>Find links</button>
<p><button type=button onclick="loadexample()" id=examplebutton>Load example</button>
</form>
<div id=linktorepo style="display:none"><a href="linktorepo.html">If you are not a member of team Control Group, please click here</a></div>
<script>
var dom = {
words: document.getElementById("words"),
results: document.getElementById("results"),
running: document.getElementById("running"),
error: document.getElementById("error"),
linktorepo: document.getElementById("linktorepo"),
}
if (window.location.hostname == "puz.link") {
dom.linktorepo.style.display = "block"
}
function ptoz(p) {
if (p > 0.5) return -ptoz(1 - p)
var a = 0.147, c = Math.log(4 * p * (1 - p)), d = 2 / (Math.PI * a) + c / 2
return Math.sqrt(2 * (Math.sqrt(d * d - c / a) - d))
}
function stars(z) {
var n = Math.floor(Math.min(Math.max(z / 1, 0), 5))
return "\u2605".repeat(n) + "\u2606".repeat(5 - n)
}
function getquery() {
var words = dom.words.value.replace(/[\-\.\,\'\"]/g, "").toLowerCase().split(/\s+/)
if (words == "") {
throw "No words found"
}
if (!words.every(function (word) { return word.match(/^[a-z\+]*$/) })) {
throw "Only letters a-z without accents supported"
}
dom.words.value = words.join(" ")
return JSON.stringify({
words: words,
ordered: true,
})
}
function seterror(message) {
dom.error.innerHTML = message
dom.error.style.display = "block"
}
function update(data) {
dom.running.style.display = "none"
if (data.error) {
seterror(data.error)
return
}
var links = data.links
links.sort(function (a, b) { return a.p - b.p })
function addCell(row, text, title) {
var node = document.createTextNode(text)
var cell = row.insertCell()
if (title) cell.setAttribute("title", title)
cell.appendChild(node)
}
var head = dom.results.createTHead().insertRow()
addCell(head, "significance")
addCell(head, "link description")
for (var j = 0 ; j < links.length ; ++j) {
var z = ptoz(links[j].p)
var row = dom.results.insertRow()
addCell(row, stars(z), "z = " + z.toFixed(1))
addCell(row, links[j].description)
}
}
function go() {
dom.results.innerHTML = ""
dom.error.style.display = "none"
dom.running.style.display = "block"
try {
var query = getquery()
} catch (e) {
seterror(e)
return false
}
var req = new XMLHttpRequest()
req.onload = function () { console.log(this, this.responseText) ; update(JSON.parse(this.responseText)) }
var url = "report?query=" + encodeURIComponent(query)
console.log(url)
req.open("GET", url, true)
req.send(null)
return false
}
var examples = [
"press hill apes nerds times ordinary mill",
"chokechain hourhand lithograph shibboleth shortsighted thermophile",
"amontillados blooming calcutta dilemma piazzas squareness",
"antithetic crosshatches gaggle nonconsenting pneumococcal prestidigitation smogless trunnions",
"grimaced formally questionable discouraged communicated chysalis saccharin",
"thumbtacks monologue frigidities statuesque testimony satirizing flawed",
"arcdetriomphescalemodel uvwavedetector gearstick firstprize thiefgamemanual monopoly tuvalutravelguide",
"rib node emission lamp ward cent cam",
"citygates impulsive clickspam baptistry leviathan policecar coupdetat sforzando cartwheel",
"lowered levitate inanimate paradise leveraged sizes tuxedo",
]
function loadexample() {
document.getElementById("words").value = examples[Math.floor(Math.random() * examples.length)]
return false
}
//update({"links": [{"p": 0.078125, "type": "word length", "description": "Word lengths are all odd."}, {"p": 4.292028654168572e-08, "type": "acrostic", "description": "center letters are identical (e)"}]})
</script>