-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
225 lines (210 loc) · 8.21 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
<!DOCTYPE html>
<html>
<head>
<title>Word Bites Solver</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<script src="https://unpkg.com/vue@next"></script>
<style>
.material-icons {
font-size: 28px;
}
.input {
width: 80%;
}
.container {
padding-left: 30px;
}
.flex {
flex-direction: row;
display: flex;
height: 220px;
align-items: center;
justify-content: center;
}
.letter {
margin: 3px;
width: 75px;
height: 75px;
background-color: #e09c08;
font-family: Helvetica;
text-align: center;
font-size: 62px;
border-radius: 6px;
line-height: 1.15;
}
.horizontal {
width: 125px;
}
.vertical {
height: 145px;
}
.pos0 {
align-self: flex-end;
}
.pos1 {
align-self: flex-start;
}
</style>
</head>
<body>
<div id="app">
<div class="container" v-if="Object.keys(current).length == 0">
<br>
<h4 class="title is-4">GamePigeon Word Bites Solver</h4>
<p>Enter ONLY LETTERS -- without any commas or other separating characters.</p>
<br>
<div class="field">
<p class="control has-icons-left">
<input id="single" class="input" type="text" placeholder="Single Letters">
<span class="icon is-medium is-left">
<span class="material-icons">
font_download
</span>
</span>
</p>
</div>
<div class="field">
<p class="control has-icons-left">
<input id="horiz" class="input" type="text" placeholder="Horizontal Boxes">
<span class="icon is-medium is-left">
<span class="material-icons">
crop_16_9
</span>
</span>
</p>
</div>
<div class="field">
<p class="control has-icons-left">
<input id="vert" class="input" type="text" placeholder="Vertical Boxes">
<span class="icon is-medium is-left">
<span class="material-icons">
crop_portrait
</span>
</span>
</p>
</div>
<div class="file" v-if="nofile">
<label class="file-label">
<input class="file-input" type="file" name="image" id="fileinput">
<span class="file-cta">
<span class="file-icon">
<span class="material-icons">
file_upload
</span>
</span>
<span class="file-label">
Or select a game screenshot
</span>
</span>
</label>
</div>
<div v-else>
<progress class="progress is-small is-primary input" max="100">15%</progress>
</div>
<br>
<button id="solve" class="button is-primary">Solve!</button>
</div>
<div v-else>
<br><br><br>
<center class="title is-2">{{ current.word }}</center>
<br><br>
<div class="flex">
<div v-for="letter in current.combination" :class="letterClass(letter)">{{ letter.letters[0].toUpperCase() }} {{ letter.letters[1].toUpperCase() }}</div>
</div>
<br><br><br>
<center>
<a id="clickToNext">Press Space or click here to go the next word</a>, or refresh to do a new puzzle.
</center>
</div>
</div>
<script src="https://cdn.jsdelivr.net/gh/gf3/Levenshtein@master/lib/levenshtein.js"></script>
<script type="module">
function getBase64(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => {
let encoded = reader.result.toString().replace(/^data:(.*,)?/, '');
if ((encoded.length % 4) > 0) {
encoded += '='.repeat(4 - (encoded.length % 4));
}
resolve(encoded);
};
reader.onerror = error => reject(error);
});
}
let app = Vue.createApp({
data() {
return {
current: {},
words: [],
nofile: true
}
},
methods: {
letterClass(letter) {
if (letter.ltype == "Single") {
return "letter";
} else if (letter.ltype == "Horizontal") {
return "letter horizontal";
} else if (letter.ltype == "Vertical") {
return "letter vertical pos" + letter.pos;
}
}
}
}).mount('#app');
const nextWord = () => {
if (app.words.length > 0) {
let idx = 0;
let lvn = new Levenshtein(app.current.levinword, app.words[0].levinword);
for (let i = 1; i < app.words.length; ++i) {
const testlvn = new Levenshtein(app.current.levinword, app.words[i].levinword);
if (testlvn.distance < lvn.distance) {
lvn = testlvn;
idx = i;
}
}
const newCurrent = app.words.splice(idx, 1);
app.current = newCurrent[0];
} else {
window.location.reload();
}
}
import init, {run} from "./solver/pkg/wordbites.js";
init().then(() => {
document.getElementById("solve").addEventListener("click", () => {
let letters = document.getElementById("single").value.toLowerCase().trim().split("");
letters = letters.concat(document.getElementById("horiz").value.toLowerCase().trim().match(/.{2}/g).map(val => val.split("").join("-")));
letters = letters.concat(document.getElementById("vert").value.toLowerCase().trim().match(/.{2}/g).map(val => val.split("").join("|")));
console.log(letters.join(","));
console.log(run(letters.join(",")));
app.words = run(letters.join(","));
app.current = app.words.shift();
console.log(app);
document.addEventListener("keydown", e => {
if (e.code == "Space") {
nextWord();
}
});
app.$nextTick(() => {
document.getElementById("clickToNext").addEventListener("click", nextWord);
});
});
document.getElementById("fileinput").addEventListener("change", async () => {
app.nofile = false;
const data = await getBase64(document.getElementById("fileinput").files[0]);
const res = await fetch("https://us-central1-wordbites.cloudfunctions.net/wordbites-2", {
method: "POST",
body: data,
});
const rd = await res.json();
document.getElementById("single").value = rd["single"].join("");
document.getElementById("horiz").value = rd["wide"].join("");
document.getElementById("vert").value = rd["tall"].join("");
document.getElementById("solve").click();
});
});
</script>
</body>
</html>