This repository was archived by the owner on Jan 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathattack.js
More file actions
57 lines (53 loc) · 1.24 KB
/
Copy pathattack.js
File metadata and controls
57 lines (53 loc) · 1.24 KB
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
ff = (navigator.userAgent.indexOf('Firefox') !== -1);
timeLimit = ff ? 5 : 2;
varLimit = ff ? 2 : 3;
iterations = 20;
lastRun = null;
function run() {
iterations = +iterations;
took = (
Array(iterations)
.fill(0)
.map(collect)
.reduce(function(a, b) { return a+b; }, 0)
) / iterations;
if (location.search.indexOf('debug') !== -1) {
debug.appendChild(document.createTextNode(`\n\ntook ${took} ms on average`));
}
return took;
}
function collect(_, i) {
var start = performance.now();
heavyTask(i);
var end = performance.now();
return end - start;
}
function heavyTask(arg) {
var buffer = [];
for (var i = 0; i <= arg; i++) {
var el = document.createElement('script');
el.textContent = 'console.log(' + i + ')';
document.head.appendChild(el);
buffer.push(el);
}
for (var i = 0; i <= arg; i++) {
document.head.removeChild(buffer[i]);
}
}
if (!('fill' in [])) {
Array.prototype.fill = function(val) {
for (var i = 0; i < this.length; i++) {
this[i] = val;
}
return this;
};
}
(function check() {
var val = run();
if (val > timeLimit) {
res.textContent = 'Y U NO CLOSE DEVTOOLS!!';
} else {
res.textContent = 'if you open devtools, I would know and this text would change :)';
}
setTimeout(check, 500);
})();