forked from skribbliohints/skribbliohints.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
387 lines (357 loc) · 16.4 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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
<!DOCTYPE html>
<html lang='en'>
<head>
<title>skribbl.io hints - Search the default word list used by skribbl.io</title>
<meta name="description" content="The most complete public word list. Search the list by entering the hint that skribbl.io gives you, for example: _____b____">
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width = device-width, initial-scale = 1">
<meta name="google-site-verification" content="-WSPNA0Q4EhYOEZRbIHmz6kERwO56vF7Bfze7Ec-d8c" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<style>
.b {
border: 1px solid black;
border-radius: 3px;
padding: 1px;
float: left;
}
@media (max-width : 600px) {
input {
margin: 3px;
font-size: 20px;
}
.b {
margin: 3px;
font-size: 20px;
}
}
</style>
<script src='Chart.bundle.min.js'></script>
<script src='grapher.js'></script>
<script>
let words = null;
let sorts = [
(a,b) => (words[b].publicGameCount || 0) - (words[a].publicGameCount || 0),
(a,b) => (words[b].difficultyWeight || 0) - (words[a].difficultyWeight || 0),
(a,b) => (words[b].count || 0) - (words[a].count || 0)
];
let word_by_idString = {};
const IDEAL_MINIMUM_DIFFICULTY_WEIGHT = 50;
const LANGUAGE_TO_PATH_MAP = {
"English": "words.json",
"German": "German.json",
"Spanish": "Spanish.json"
};
const NAME_MAP = {
"count": "Total number of times seen (mostly in private games)",
"publicGameCount": "Number of times seen in public games",
"difficultyWeight": "Number of players observed (including bot)"
};
function getTransformedNumericalValue(key, value) { // this abstraction is used for graphing
if(key === 'lastSeenTime') {
return value;
} else if(key === 'difficulty') {
return ((1 - value) * 100);
} else if(key === 'difficultyTile') {
return (value * 100);
} else if(key in NAME_MAP) {
return value;
}
return value;
}
function renderKey(key, value, showValue=true) {
// key and value should be escaped to prevent HTML/JavaScript injection
const transformed_numerical_value = getTransformedNumericalValue(key, value);
if(key === 'lastSeenTime') {
return 'Last seen' + (showValue ? ': ' + String(new Date(transformed_numerical_value)) : '');
} else if(key === 'difficulty') {
return "Percent of players that guess correctly (including the bot)" + (showValue ? ": " + String(transformed_numerical_value) + '%' : '');
} else if(key === 'difficultyTile') {
return "Difficulty percentile" + (showValue ? ": " + transformed_numerical_value.toFixed(1) + "%" : '');
} else if(key in NAME_MAP) {
return NAME_MAP[key] + (showValue ? ': ' + transformed_numerical_value : '');
}
return key + (showValue ? ': ' + transformed_numerical_value : '');
}
function expand(idString) {
const el = document.getElementById(idString);
const word = word_by_idString[idString];
if(el.style.width !== '100%') {
el.style.width = '100%';
el.innerHTML = word + `<button style="float: right;" onClick='collapse("${idString}");'>X</button><ul>` +
Object.keys(words[word]).reduce((acc, key) =>
acc + '<li>' + renderKey(key, words[word][key]) + "</li>",
'')
+ '</ul>';
}
}
function collapse(idString) {
// it doesn't work if I don't use setTimeout here
setTimeout(function(){
const word = word_by_idString[idString];
const el = document.getElementById(idString);
el.innerHTML = word;
el.style.width = 'initial';
}, 1);
}
function myEscape(text) {
return text.split('').map(c => ({'<':'<','>':'>','&':'&'}[c] || c)).join('');
}
function myRecursiveEscape(a) {
// a may be of any type except function
let result;
if(typeof a === 'number' || typeof a === 'boolean' || typeof a === 'undefined') {
result = a;
} else if(typeof a === 'string') {
result = myEscape(a);
} else if(typeof a === 'object') {
if(a === null) {
result = null;
} else {
result = {};
for(const key in a) {
result[myEscape(key)] = myRecursiveEscape(a[key]);
}
}
}
return result;
}
function apply_whiteness(val_between_0_and_1, whiteness) {
return 1 - ((1 - val_between_0_and_1) * (1 - whiteness));
}
function get_rgb_string(color_parts_between_0_and_1) {
return "rgb(" + color_parts_between_0_and_1.map(v => Math.floor(v * 255)).join(',') + ')';
}
function get_0_1_rgb_values(difficulty, whiteness) {
return [apply_whiteness(Math.pow(difficulty, 0.125), whiteness), apply_whiteness(Math.pow(1 - difficulty, 0.125), whiteness), whiteness];
}
function getTableInnerHTML(words, sorts=[], filters=[], useColor) {
let parts = [];
let word_array = Object.keys(words);
for(const f of filters) {
word_array = word_array.filter(f);
}
word_array = word_array.sort((a,b) => {
for(const s of sorts) {
if(s(a,b) !== s(b,a)) {
return s(a,b);
}
}
return 0;
});
let idNumber = 0;
for(const word of word_array) {
let backgroundColorString = '';
if((useColor || document.getElementById('colorCheckbox').checked) && words[word].publicGameCount) {
const whiteness = 1 - Math.min(1, words[word].difficultyWeight / IDEAL_MINIMUM_DIFFICULTY_WEIGHT);
const color_parts_between_0_and_1 = get_0_1_rgb_values(words[word].difficultyTile, whiteness);
backgroundColorString = "background-color: " + get_rgb_string(color_parts_between_0_and_1) + ';';
}
// word has already been escaped
const idString = 'wordDiv' + String(idNumber);
word_by_idString[idString] = word;
parts.push(`<div class="b" id="${idString}" style="${backgroundColorString}" onClick="expand('${idString}')">${word}</div>`);
idNumber++;
}
if(parts.length === 0) {
parts.push('No matching words');
}
return parts.join('\n');
}
function getFilterFromSkribblioHint(skribblioHint) {
const re = new RegExp('^' + skribblioHint.split('').map(char => char === '_' ? '[a-zA-ZÁ-ü0-9./]' : (char === '.' ? '\\.' : char)).join('') + '$');
return a => skribblioHint === '' || re.test(a);
}
// non-ascii letters:
// German: äöüÄÖÜß
// Spanish: upper and lower vowels with accent, upper and lower ñ, and ü
function searchBoxOnInput() {
const input = this.value;
let filters = [];
filters.push(getFilterFromSkribblioHint(input));
document.querySelector('#wordlist').innerHTML = getTableInnerHTML(words, sorts, filters, document.getElementById('colorCheckbox').checked);
}
function colorCheckboxOnClick() {
searchBoxOnInput.bind(document.getElementById('searchBox'))();
document.getElementById('colorKey').style.display = this.checked ? "initial" : "none";
}
function showGrapherCheckboxOnClick() {
document.getElementById('grapher').style.display = this.checked ? "initial" : "none";
}
function getListOfWordAttributes() {
const list_of_word_attributes = [];
for(const word of Object.keys(words)) {
for(const key in words[word]) {
if(list_of_word_attributes.find(el => String(el) === String(key)) === undefined) {
list_of_word_attributes.push(key);
}
}
}
return list_of_word_attributes;
}
function getAttribute(axisSelect) {
return getListOfWordAttributes().find(attr => renderKey(attr, null, false) === axisSelect.value);
}
function showGraph() {
document.getElementById('graphDiv').innerHTML = '';
if(xAxisSelect.value !== 'Select') {
const xAxisSelect = document.getElementById('xAxisSelect');
const xAxisAttribute = getAttribute(xAxisSelect);
const yAxisSelect = document.getElementById('yAxisSelect');
const yAxisAttribute = getAttribute(yAxisSelect);
let data = [];
if(yAxisSelect.value === document.getElementById('numWordsWithXOption').textContent) {
const frequency_map = {};
for(const word in words) {
const transformed_numerical_value = getTransformedNumericalValue ( xAxisAttribute , words[word][xAxisAttribute] );
frequency_map[transformed_numerical_value] = (frequency_map[transformed_numerical_value] || 0) + 1;
}
data = Object.keys(frequency_map).map(key => [key, frequency_map[key]]);
} else {
for(const word in words) {
data.push([
getTransformedNumericalValue ( xAxisAttribute , words[word][xAxisAttribute] ) ,
getTransformedNumericalValue ( yAxisAttribute , words[word][yAxisAttribute] ) ,
word
]);
}
}
document.getElementById('graphDiv').appendChild(getGraph(data, xAxisSelect.value, yAxisSelect.value));
const rdiv = document.createElement('div');
rdiv.style.textAlign = 'center';
const cleanedData = data
.filter(point =>
point[0] !== undefined && point[1] !== undefined && !isNaN(point[0]) && !isNaN(point[1])
).map(point =>
[Number(point[0]), Number(point[1])] // The values in data are not numbers for some reason.
);
let sxy = cleanedData.reduce((acc,e) => acc + e[0]*e[1], 0);
let sx2 = cleanedData.reduce((acc,e) => acc + e[0]*e[0], 0);
let sy2 = cleanedData.reduce((acc,e) => acc + e[1]*e[1], 0);
let sx = cleanedData.reduce((acc,e) => acc + e[0], 0);
let sy = cleanedData.reduce((acc,e) => acc + e[1], 0);
let r = (cleanedData.length*sxy - sx*sy)/Math.sqrt((cleanedData.length * sx2 - Math.pow(sx, 2)) * (cleanedData.length * sy2 - Math.pow(sy, 2)));
rdiv.textContent = "r = " + r.toFixed(4);
document.getElementById('graphDiv').appendChild(rdiv);
}
}
function getGrapherOption(text) {
const option = document.createElement('option');
option.textContent = renderKey(text, null, false);
return option;
}
function handleLanguageChange(event) {
fetchWords(LANGUAGE_TO_PATH_MAP[event.target.value]);
}
function fetchWords(path) {
var oReq = new XMLHttpRequest();
oReq.addEventListener("load", function() {
// parse the words then escape
words = myRecursiveEscape(JSON.parse(this.response));
// attach difficulty 'tiles to words
Object.keys(words)
.filter(w => words[w].difficulty != undefined)
.sort((w1, w2) => words[w1].difficulty - words[w2].difficulty)
.forEach((word, index, array) => {
words[word].difficultyTile = index / array.length
});
const xAxisSelect = document.getElementById('xAxisSelect');
const yAxisSelect = document.getElementById('yAxisSelect');
xAxisSelect.innerHTML = "<option>Select</option>";
yAxisSelect.innerHTML = "<option id='numWordsWithXOption'>Number of words with the X value</option>";
for(const word_attribute of getListOfWordAttributes()) {
xAxisSelect.appendChild(getGrapherOption(renderKey(word_attribute, null, false)));
yAxisSelect.appendChild(getGrapherOption(renderKey(word_attribute, null, false)));
}
document.querySelector('#wordlist').innerHTML = getTableInnerHTML(
words,
sorts,
[getFilterFromSkribblioHint(document.querySelector('#searchBox').value)]
);
showGraph();
});
oReq.open("GET", path);
oReq.send();
}
function onLoad() {
document.getElementById("languageSelect").addEventListener('change', handleLanguageChange);
const ctx = document.getElementById('colorCanvas').getContext('2d');
const OFFSET_X = 0;
const OFFSET_Y = 20;
const CANVAS_WIDTH = document.getElementById('colorCanvas').width;
const CANVAS_HEIGHT = document.getElementById('colorCanvas').height;
const NUM_STEPS = 500;
for(let difficulty = 0; difficulty < 1; difficulty += 1.0 / NUM_STEPS) {
for(let whiteness = 0; whiteness < 1; whiteness += 1.0 / NUM_STEPS) {
ctx.fillStyle = get_rgb_string(get_0_1_rgb_values(difficulty, whiteness));
ctx.fillRect(OFFSET_X + (difficulty * (CANVAS_WIDTH - OFFSET_X)), OFFSET_Y + (whiteness * (CANVAS_HEIGHT - OFFSET_Y)), 1, 1);
}
}
ctx.fillStyle = 'black';
ctx.font = '15px Arial';
ctx.fillText('Easy', OFFSET_X, 15);
ctx.fillText('Hard', CANVAS_WIDTH - 35, 15);
if(!document.getElementById('colorCheckbox').checked) {
document.getElementById('colorKey').style.display = "none";
}
if(!document.getElementById('showGrapherCheckbox').checked) {
document.getElementById('grapher').style.display = "none";
}
fetchWords(LANGUAGE_TO_PATH_MAP[document.getElementById("languageSelect").value]);
}
</script>
</head>
<body onLoad="onLoad()">
<div class='container'>
<h2 style='text-align: center;'>skribbl.io default word list database</h2>
<div>
<div class="alert alert-warning">
This word list is outdated. This is the word list skribbl.io used prior to November 9, 2022, when more words were added.
</div>
<p style='margin: 5px 10px;'>
Below is a list of words that skribbl.io uses in public games.<br>
Enter the hint provided by skribbl.io (e.g. <span style='letter-spacing: 2px;'>_oa__</span>) to search the list.
</p>
<form>
<input type='checkbox' id='colorCheckbox' name='colorCheckbox' onClick='colorCheckboxOnClick.bind(this)()'>
<label for='colorCheckbox'>Show difficulty of word using color</label>
<br>
<div id='colorKey'>
<canvas id='colorCanvas' width='200' height='40'></canvas><br>
<span style='font-size: 12px'>Colors closer to white indicate low confidence. Perfect white indicates no data.</span>
<br>
</div>
<input type='checkbox' id='showGrapherCheckbox' name='showGrapherCheckbox' onClick='showGrapherCheckboxOnClick.bind(this)()'>
<label for='showGrapherCheckbox'>Show data grapher</label>
<div style='float: right;'>
Language: <select id="languageSelect">
<option value="English">English</option>
<option value="German">German</option>
<option value="Spanish">Spanish</option>
</select>
</div>
<br>
<div id='grapher'>
X Axis
<select id='xAxisSelect' onchange='showGraph()'>
<!-- options are added by JavaScript code -->
</select>
<br>
Y Axis
<select id='yAxisSelect' onchange='showGraph()'>
<!-- options are added by JavaScript code -->
</select>
<div id='graphDiv'></div>
<div id='rDiv'></div>
</div>
</form>
</div>
<form>
<input type='text' id='searchBox' oninput='searchBoxOnInput.bind(this)()' placeholder='Search by blanks, for example _____b____' style="width: 100%; letter-spacing: 2px; margin: 3px;">
</form>
<div id='wordlist' style="margin: 3px;">
Retrieving word list. This may take up to 30 seconds.
</div>
</div>
</body>
</html>