-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
324 lines (305 loc) · 11.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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Anagrams on web</title>
<script>
function get_request_url() {
if (document.location.protocol == "http:")
return "ws://" + document.location.host + "/ws";
else if (document.location.protocol == "https:")
return "wss://" + document.location.host + "/ws";
else
return "wtf://" + document.location.host + "/ws";
}
function describe_form() {
var r = "q=" + encodeURIComponent(search.value);
if (wmin.value != "")
r += "&wmin=" + wmin.value;
if (wmax.value != "")
r += "&wmax=" + wmax.value;
if (candup.checked)
r += "&dups";
if (incomp.checked)
r += "&inc";
if (rseed.value != "")
r += "&r=" + rseed.value;
if (lmin.value != "")
r += "&lmin=" + lmin.value;
if (lmax.value != "")
r += "&lmax=" + lmax.value;
if (wth.value != "")
r += "&with=" + wth.value;
return r;
}
function import_form_data(txt) {
search.value = "";
wmin.value = "";
wmax.value = "";
lmin.value = "";
lmax.value = "";
candup.checked = false;
incomp.checked = false;
chkb.checked = false;
rseed.value = "";
wth.value = "";
txt.split('&').forEach(function(p) {
var ps = p.split('=');
if (ps.length == 2) {
ps[1] = decodeURIComponent(ps[1]);
if (ps[0] == "q")
search.value = ps[1];
else if (ps[0] == "wmin")
wmin.value = ps[1];
else if (ps[0] == "wmax")
wmax.value = ps[1];
else if (ps[0] == "lmin")
lmin.value = ps[1], chkb.checked = true;
else if (ps[0] == "lmax")
lmax.value = ps[1], chkb.checked = true;
else if (ps[0] == "r")
rseed.value = ps[1], chkb.checked = true;
else if (ps[0] == "with")
wth.value = ps[1], chkb.checked = true;
} else if (ps.length == 1) {
if (ps[0] == "dups")
candup.checked = true, chkb.checked = true;
else if (ps[0] == "inc")
incomp.checked = true, chkb.checked = true;
}
});
trigger(candup);
trigger(incomp);
trigger(chkb);
}
function as_text(form_info) {
var q = "";
var mn = "";
var mx = "";
var lmn = "";
var lmx = "";
var rs = "";
var du = false;
var inc = false;
var wt = "";
form_info.split('&').forEach(function(p) {
var ps = p.split('=');
if (ps.length == 2) {
ps[1] = decodeURIComponent(ps[1]);
if (ps[0] == "q")
q = ps[1];
else if (ps[0] == "wmin")
mn = ps[1];
else if (ps[0] == "wmax")
mx = ps[1];
else if (ps[0] == "lmin")
lmn = ps[1];
else if (ps[0] == "lmax")
lmx = ps[1];
else if (ps[0] == "r")
rs = ps[1];
else if (ps[0] == "with")
wt = ps[1];
} else if (ps.length == 1) {
if (ps[0] == "dups")
du = true;
else if (ps[0] == "inc")
inc = true;
}
});
var r = q;
if (mn != "" || mx != "")
r += "; " + (mn == "" ? "1" : mn) + ".." + (mx == "" ? "inf" : mx);
if (rs != "" && rs != "0")
r += "; #" + rs;
if (du || inc)
r += "; " + (du ? "D" : "") + (inc ? "I" : "");
if (lmn != "" || lmx != "")
r += "; W: " + + (lmn == "" ? "1" : lmn) + ".." + (lmx == "" ? "inf" : lmx);
if (wt != "")
r += "; -" + wt;
return r;
}
function fetch(form_info, record) {
ws = new WebSocket(get_request_url() + "?" + form_info);
document.getElementById("responce").innerHTML = "";
document.title = "Anagrams on web (" + as_text(form_info) + ")";
if (record)
window.history.pushState("","", "?" + form_info);
ws.onmessage = function(event) {
event.data.split("\n").forEach(function(elem) {
if (elem != "") {
resp.appendChild(document.createTextNode(elem));
resp.appendChild(document.createElement("br"));
}
});
};
ws.onclose = function(event) {
delete window.ws;
};
ws.onerror = function(event) {
resp.appendChild(document.createTextNode("Ошибка сети (попробуйте ещё раз)"));
resp.appendChild(document.createElement("br"));
};
}
function search_stop() {
if (typeof ws !== 'undefined') {
ws.close();
}
}
function search_start(record) {
search_stop();
fetch(describe_form(), record);
}
function check_get_param() {
if (window.location.search.startsWith("?")) {
import_form_data(window.location.search.substr(1, window.location.search.length - 1));
search_start(false);
}
}
function onload() {
resp = document.getElementById("responce");
search = document.getElementById("search");
wmin = document.getElementById("search_wmin");
wmax = document.getElementById("search_wmax");
lmin = document.getElementById("search_lmin");
lmax = document.getElementById("search_lmax");
candup = document.getElementById("candup");
rseed = document.getElementById("random_seed");
incomp = document.getElementById("incomplete");
chkb = document.getElementById("chkb_input");
wth = document.getElementById("with");
window.onpopstate = function(event) {
check_get_param();
};
check_get_param();
}
function trigger(elem) {
var head2 = document.getElementById("header2");
if (elem.checked == false) {
elem.parentNode.className = "chkb_outer";
if (elem.id == "chkb_input")
head2.className = "header2 hidden";
} else {
elem.parentNode.className = "chkb_outer chkb_on";
if (elem.id == "chkb_input")
head2.className = "header2";
}
}
</script>
<style>
body, div, input {
margin: 0px;
padding: 0px;
border: 0px;
}
body {
width: 100%;
min-width: 500px;
}
.header {
background-color: #DEF7F6;
}
.header2 {
background-color: #D3EBEA;
}
form > div {
height: 21px;
margin-top: 5px;
margin-bottom: 5px;
margin-left: 5px;
border: 0.5px solid black;
display: inline-block;
}
.forminfo {
border: 0px;
}
form > div > input {
height: 100%;
}
#search {
width: 200px;
}
input[type=number] {
width: 30px;
}
div.logoimg {
height: 32px;
width: 40px;
margin-right: 5px;
background-size: cover;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABACAYAAACNx/A2AAAACXBIWXMAAAsTAAALEwEAmpwYAAABfUlEQVR42u2cQa7CMAwF4akb/i3g/meCW8CSv0UI2iSN7cSMl1Rqm+m82m0ljtfH/XmgmksgACAAAQhACoAABCAAKQACcLZaeu7scvr7+Pv1cQ9d5PnLed06nJes4W1ti4K3tY0IZ7sHRlrYaqgbwKxwiHC2MSajqbKCknl0MTdwDV6khWvwWi0UkRzMwFf7omP8zb6eMQ7pwpnMlTUEbwtLIfSyUFbxHaluhuelqAhaxLhH86jdh8s9MLOZioTk0UxaINVYqBEXPfrs193AEvsiYlxi394Yh7+Nmd1oeS7WysK98d1joTziG2Fhjw5bcmH0K1Gb5mXCr82EGgVGT8N7PrptGS7iu6+WUayZFaxGglRzLE9Ia8fis+ZsXTjbbWFpWUx09/X4ZGnyKJdxjksX4dlirOhF1Brt1X1Ljdao8a25gJ7xfb+AYkBOcA+cuTFp5EWWJCGi+74mQcQ3yRgza4yP/GdCwkEagACkAAhAAAKQAiAAAQhAaq3+ASL/kJynYzgXAAAAAElFTkSuQmCC);
float: left;
}
.chkb_on {
background-color: yellow;
}
#responce {
margin-top: 10px;
margin-left: 10px;
}
.hidden {
display: none;
}
</style>
</head>
<body onload="onload()">
<div class="header">
<div class="logoimg"></div>
<form onsubmit="search_start(true); return false">
<div>
<input id="search" type="text" placeholder="Александр Пушкин"/>
</div>
<div class="forminfo">от</div>
<div class="formbtn">
<input id="search_wmin" type="number" placeholder="1" min="1" max="10"/>
</div>
<div class="forminfo">до</div>
<div class="formbtn">
<input id="search_wmax" type="number" placeholder="10" min="1" max="10"/>
</div>
<div class="forminfo">слов</div>
<div class="formbtn">
<input type="submit" value="Отправить"/>
</div>
<div class="chkb_outer">
<input type="checkbox" onchange="trigger(this)" style="opacity: 0; width: 8px; height: 0;" id="chkb_input"/>
<label for="chkb_input" class="chkb_inner" style="position: relative; left: -8px">...</label>
</div>
</form>
</div>
<div class="header2 hidden" id="header2">
<form>
<div class="chkb_outer">
<input type="checkbox" onchange="trigger(this)" style="opacity: 0; width: 8px; height: 0;" id="candup"/>
<label for="candup" class="chkb_inner" style="position: relative; left: -8px">с повторениями</label>
</div>
<div class="chkb_outer">
<input type="checkbox" onchange="trigger(this)" style="opacity: 0; width: 8px; height: 0;" id="incomplete"/>
<label for="incomplete" class="chkb_inner" style="position: relative; left: -8px">неполные комбинации</label>
</div>
<div class="forminfo">ключ рандома</div>
<div class="formbtn">
<input id="random_seed" type="number" placeholder="0" min="0" max="1000000"/>
</div>
</form>
<form>
<div class="forminfo">длина слов от</div>
<div class="formbtn">
<input id="search_lmin" type="number" placeholder="1" min="1" max="100"/>
</div>
<div class="forminfo">до</div>
<div class="formbtn">
<input id="search_lmax" type="number" placeholder="99" min="1" max="99"/>
</div>
<div class="forminfo">символов</div>
<div>
<input id="with" type="text" placeholder="со словами"/>
</div>
</form>
</div>
<noscript>Для работы данной страницы необходим javascript</noscript>
<div id="responce">
</div>
</body>
</html>