-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
66 lines (65 loc) · 1.7 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
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8"/>
<title>Time Machine Tester</title>
<style>
input{
width:100%;
}
</style>
</head>
<body>
<a href="./TimeMachine.user.js">-->Install the script<--</a><br/>
<form>
</form>
<textarea></textarea>
<script>
"use strict";
//it's easy to break this demo launching script without any events
document.addEventListener("DOMContentLoaded",()=>{
let initialTime=Date.now();
let frm=document.getElementsByTagName("FORM")[0];
let createTimerElement=function(name,cb){
let el=document.createElement("INPUT");
el.type="datetime";
el.name=name;
let lbl=document.createElement("LABEL");
lbl.for=name;
lbl.textContent=name;
frm.appendChild(lbl);
frm.appendChild(el);
frm.appendChild(document.createElement("BR"));
let step=(timestamp) => {
el.value=new Date(cb(timestamp));
requestAnimationFrame(step);
};
requestAnimationFrame(step);
}
createTimerElement("Date.now()",()=>Date.now());
createTimerElement("new Date()",()=>new Date().getTime());
createTimerElement("performance.now()",()=>initialTime+performance.now());
{
createTimerElement("requestAnimationFrame()",(ts)=>initialTime+ts);
}
{
const amount=1000;
let intervalTime=Date.now();
console.log(setInterval.toSource());
setInterval(()=>{intervalTime+=amount;},amount);
createTimerElement("setInterval",()=>intervalTime);
}
{
const amount=1000;
let timeOutTime=Date.now();
let sTo=function (){
timeOutTime+=amount;
setTimeout(sTo,amount);
};
setTimeout(sTo,amount);
createTimerElement("setTimeout",()=>timeOutTime);
}
},false);
</script>
</body>
</html>