forked from dfabulich/choicescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandomtest.html
86 lines (80 loc) · 2.99 KB
/
randomtest.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
<!DOCTYPE html>
<html>
<head>
<title>Randomtest</title>
</head>
<body>
<p>Iterations: <input type="number" id="iterations" value="10000"></p>
<p>Seed: <input type="number" id="seed" value="0"></p>
<p><input type="checkbox" id="showText"> Show full text during game</p>
<p><input type="checkbox" id="showCoverage"> Show line coverage statistics after test</p>
<p><input type="checkbox" id="autoScroll"> Automatically scroll to the bottom</p>
<button id="start">Start Randomtest</button>
<script>
var worker = new Worker("randomtest.js");
var messages = [];
worker.onmessage = function(x) {
var msg = x.data.msg;
messages.push(msg);
console.log(msg);
}
setInterval(function() {
if (messages.length) {
var frag = document.createDocumentFragment();
var length = messages.length;
for (var i = 0; i < length; i++) {
printBody(messages[i], frag);
frag.appendChild(document.createElement("br"));
};
document.body.appendChild(frag);
messages = [];
if (queryArgs.autoScroll) window.scroll(0,document.height);
}
}, 100);
function printBody(msg, parent) {
if (msg === null || msg === undefined || msg === "") return;
if (!parent) parent = document.body;
if (msg == " ") {
// IE7 doesn't like innerHTML that's nothing but " "
parent.appendChild(document.createTextNode(" "));
return;
}
msg = (msg+"").replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/\[b\]/g, '<b>')
.replace(/\[\/b\]/g, '</b>')
.replace(/\[i\]/g, '<i>')
.replace(/\[\/i\]/g, '</i>');
var frag = document.createDocumentFragment();
temp = document.createElement('div');
temp.innerHTML = msg;
while (temp.firstChild) {
frag.appendChild(temp.firstChild);
}
parent.appendChild(frag);
}
var queryArgList = (""+window.location.search).substr(1).split(/&/);
var queryArgs = {};
for (var i = queryArgList.length - 1; i >= 0; i--) {
var parts = queryArgList[i].split(/=/);
if ("false" === parts[1]) parts[1] = false;
queryArgs[parts[0]] = parts[1];
};
if (queryArgs.iterations) document.getElementById("iterations").value = queryArgs.iterations;
if (queryArgs.seed) document.getElementById("seed").value = queryArgs.seed;
if (queryArgs.showText) document.getElementById("showText").checked = queryArgs.showText;
if (queryArgs.showCoverage) document.getElementById("showCoverage").checked = queryArgs.showCoverage;
if (queryArgs.autoScroll) document.getElementById("autoScroll").checked = queryArgs.autoScroll;
document.getElementById("start").onclick = function() {
iterations = document.getElementById("iterations").value;
randomSeed = document.getElementById("seed").value*1;
var showText = document.getElementById("showText").checked;
var showCoverage = document.getElementById("showCoverage").checked;
document.body.innerHTML = "";
worker.postMessage({iterations:iterations, randomSeed:randomSeed, showText:showText, showCoverage:showCoverage});
}
</script>
</body>
</html>