-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
373 lines (343 loc) · 12.3 KB
/
index.js
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
const express = require('express');
const cookieParser = require('cookie-parser')
const app = express();
app.use(cookieParser())
const port = 3000;
app.get('/fields', (req, res) => {
res.send(`
<!DOCTYPE html>
<html>
<body>
<h1 automation="halp">i am jack's form</h1>
<form>
<input id="input_1" type="text" value="foo">input_1</input> <br />
<input id="input_2" type="text" value="bar">input_2</input> <br />
<input id="input_3" type="text" value="baz">input_3</input> <br />
<input id="input_4" type="text" value="qux">input_4</input> <br />
<input id="input_5" type="text" value="quux">input_5</input> <br />
<input id="input_6" type="text" value="quuz">input_6</input> <br />
<input id="input_7" type="text" value="wibble">input_7</input> <br />
<input id="input_8" type="text" value="wobble">input_8</input> <br />
<input id="input_9" type="text" value="flob">input_9</input> <br />
<input id="input_10" type="text">input_10</input> <br />
<input id="input_11" type="text">input_11</input> <br />
<input id="input_submit" type="submit">input_submit</input> <br />
<input id="input_disabled" type="text" disabled>input_disabled</input> <br />
</form>
</body>
</html>
`);
});
app.get('/slow', (req, res) => {
const seconds = req.query.seconds || 1;
res.send(`
<!DOCTYPE html>
<html>
<body>
<h1 automation="halp">Loading for ${seconds} second${seconds > 1 ? 's' : ''}</h1>
<img alt="I am jack's slow loading resource" src="/loadingFor?seconds=${seconds}" />
</body>
</html>
`);
});
app.get('/wait', (req, res) => {
const seconds = req.query.seconds || 1;
res.send(`
<!DOCTYPE html>
<html>
<head>
<script>
function hide() {
(new Promise((resolve) => setTimeout(resolve, ${seconds * 1000}))).then(() => { document.getElementById("will-vanish").style.display = "none"}
);}
function show() {
(new Promise((resolve) => setTimeout(resolve, ${seconds * 1000}))).then(() => { document.getElementById("will-appear").style.display = "block"}
);}
</script>
</head>
<body onLoad="hide();show();">
<h1 automation="halp">Loading for ${seconds} second${seconds > 1 ? 's' : ''}</h1>
<div id="will-vanish" >I am Jack's display:none after ${seconds} seconds</div>
<br />
<div id="will-appear" style="display: none">After ${seconds} seconds I am Jack's display:block</div>
</body>
</html>
`);
});
app.get('/consoleError', (req, res) => {
const seconds = req.query.seconds || 1;
res.send(`
<!DOCTYPE html>
<html>
<head>
<script>
function foo() {
//trigger Uncaught ReferenceError: bar is not defined
bar
}
</script>
</head>
<body onLoad="foo()">
<h1 automation="halp">I am Jack's onload console error</h1>
</body>
</html>
`);
});
app.get('/loadingFor', (req, res) => {
const startTime = Date.now();
const wait = (req.query.seconds) ? req.query.seconds * 1000 : 1000 * 60;
const intervalID = setInterval(function () {
const endTime = Date.now();
const timeElapsed = endTime - startTime;
if (timeElapsed > wait) {
res.send({hello: 'there', startTime, endTime});
return clearInterval(intervalID);
}
}, 1000);
});
app.get('/cookies', (req, res) => {
//make a default cookie
default_cookie_name = "IAmJacksDefaultCookie";
default_cookie_value = "i_am_jacks_cookie_value";
res.cookie(default_cookie_name, default_cookie_value, {maxAge: 900000, httpOnly: true, signed: false});
//show all cookies
tabulated_cookies = []
for (const cookie in req.cookies) {
tabulated_cookies.push("<tr id=" + cookie + "><td role=\"name\">" + cookie + "</td><td role=\"value\">" + req.cookies[cookie] + "</td></tr>")
}
res.send(`
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1 automation="halp">I am Jack's Cookie</h1>
<table>
${tabulated_cookies.join("")}
</table>
</body>
</html>
`);
})
//look at this to make the button and covering div always the same size, because of browser specific issues
//http://stackoverflow.com/questions/1205159/html-css-making-two-floating-divs-the-same-height
//http://stackoverflow.com/questions/2997767/how-do-i-keep-two-divs-that-are-side-by-side-the-same-height
//http://stackoverflow.com/questions/16317497/make-floating-divs-the-same-height
app.get('/notClickable', (req, res) => {
res.send(`
<!DOCTYPE html>
<html>
<body>
<h1 automation="halp">I am jack's obscured element</h1>
<form id="form">
<button id="button_1" type="submit">button_1</button>
<div id="blocker_1" style="position: absolute; display: inline; left: 0; padding-left: 100px;">I should block the button</div>
<br />
<button id="button_2" type="submit">button_2</button>
<div id="blocker_2" style="position: absolute; display: inline; left: 0; padding-left: 100px;" onClick="document.getElementById("form").removeChild(document.getElementById("blocker_2"));">I should unblock the button after one click</div>
<br />
<button id="button_3" type="submit" disabled>no click for you</button>
</form>
</body>
</html>
`);
});
//check out this gem https://jsfiddle.net/pwdst/rf3nrnzo/
app.get('/theStaleMaker', (req, res) => {
res.send(`
<!DOCTYPE html>
<html>
<body>
<h1 automation="halp">Stale Element</h1>
<form id="form">
<button id="nuke" type="submit" onClick="document.getElementById("container").removeChild(document.getElementById("stale"));">make it gone!</button>
<button id="makeStale" type="submit" onClick="$('#stale').detach()">make it stale!</button>
<button id="makeFresh" type="submit" onClick="$('#stale').attach()">make it fresh!</button>
</form>
<div id="container">
<span id="ordinary">I am jack's ordinary element</span><br />
<span id="stale">I am jack's stale element</span><br />
</div>
</body>
</html>
`);
});
//check out this gem https://jsfiddle.net/pwdst/rf3nrnzo/
app.get('/alert', (req, res) => {
res.send(`
<!DOCTYPE html>
<html>
<body>
<h1 automation="halp">Spawn Alert</h1>
<form id="form" onSubmit="return false;">
<button id="alert" type="submit" onClick="window.alert('i am jacks alert')">summon the alert</button>
</form>
</body>
</html>
`);
});
app.get('/hover', (req, res) => {
res.send(`
<!DOCTYPE html>
<html>
<head>
<style>
#will-appear {
display: none;
}
a:hover + #will-appear {
display: block;
}
</style>
</head>
<body>
<h1 automation="halp">Hover Action</h1>
<br />
<div id="content">
<a id="hover-target">I am Jack's hover action</a>
<div id="will-appear">I am Jack's smirking div</div>
</div>
</body>
</html>
`);
});
app.get('/range', (req, res) => {
const min = req.query.min || 1;
const max = req.query.max || 100;
const default_value = req.query.defaultValue || 50;
const input_id = 'range-input'
const output_id = 'range-output'
res.send(`
<!DOCTYPE html>
<html>
<head>
<script>
function updateValue(val) {
input = document.getElementById("${input_id}");
output = document.getElementById("${output_id}");
output.innerText = val;
output.setAttribute("value", val);
input.setAttribute("value", val);
}
</script>
</head>
<body>
<h1 automation="halp">I am Jack's range input</h1>
<input type="range" name="range" id="${input_id}" min="${min}" max="${max}" defaultValue="${default_value}" value="${default_value}" onchange="updateValue(this.value)">
<br />
<output id="${output_id}" value="${default_value}">${default_value}</output>
</form>
</body>
</html>
`);
});
app.get('/buttons-links', (req, res) => {
res.send(`
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Duplicate button/link text</title>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<h2 automation="halp">Multi Buttons</h1>
<form id="btn-form">
<button id="button-1" type="button" onClick="$('#btn-text-1').show();">Do it!</button>
<button id="button-2" type="button" onClick="$('#btn-text-2').show();">Do it!</button>
<button id="button-3" type="button" onClick="$('#btn-text-3').show();">Do it!</button>
</form>
<div id="btn-container">
<span id="btn-text-1">Button 1 clicked...</span><br />
<span id="btn-text-2">Button 2 clicked...</span><br />
<span id="btn-text-3">Button 3 clicked...</span><br />
</div>
<h2 automation="halp">Multi Links</h1>
<form id="link-form">
<a href="#" id="link-1" onClick="$('#link-text-1').show();">Do it!</a>
<a href="#" id="link-2" onClick="$('#link-text-2').show();">Do it!</a>
<a href="#" id="link-3" onClick="$('#link-text-3').show();">Do it!</a>
</form>
<div id="link-container">
<span id="link-text-1">Link 1 clicked...</span><br />
<span id="link-text-2">Link 2 clicked...</span><br />
<span id="link-text-3">Link 3 clicked...</span><br />
</div>
<script>
const spans = ["btn-text-1", "btn-text-2", "btn-text-3", "link-text-1", "link-text-2", "link-text-3"];
$.each(spans, function( i, val ) {
const id = '#' + val
console.log("Hiding " + id);
$(id).hide();
});
</script>
</body>
</html>
`);
});
app.get('/dropdown', function (req, res) {
res.send(`
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dropdown</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.4/css/select2.min.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.4/js/select2.min.js"></script>
</head>
<body>
<h2>Dropdown</h1>
<div>
<span>Default select</span>
<select name="default-select">
<option value="1">Option one</option>
<option value="2">Option two</option>
<option value="3">Option three</option>
</select>
</div>
<div>
<span>Select2</span>
<select class="select2" name="default-select">
<option value="1">Option one</option>
<option value="2">Option two</option>
<option value="3">Option three</option>
</select>
</div>
<script>
$('.select2').select2();
</script>
</body>
</html>
`);
});
app.get('/hidden', (req, res) => {
res.send(`
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hidden div</title>
</head>
<body>
<div hidden>
This is a hidden element
</div>
</body>
</html>
`);
});
const server = app.listen(port, () => {
console.log(`Running! on http://localhost:%s`, port);
console.log(`Invoke like this http://localhost:%s/fields`, port)
console.log(`Invoke like this http://localhost:%s/slow?seconds=10`, port)
console.log(`Invoke like this http://localhost:%s/notClickable`, port)
console.log(`Invoke like this http://localhost:%s/wait?seconds=5`, port)
console.log(`Invoke like this http://localhost:%s/cookies`, port)
console.log(`Invoke like this http://localhost:%s/alert`, port)
console.log(`Invoke like this http://localhost:%s/hover`, port)
console.log(`Invoke like this http://localhost:%s/range?min=100&max=1000&defaultValue=500`, port)
console.log(`Invoke like this http://localhost:%s/buttons-links`, port)
console.log(`Invoke like this http://localhost:%s/dropdown`, port)
console.log(`Invoke like this http://localhost:%s/hidden`, port)
});