-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
139 lines (110 loc) · 2.94 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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>futurelink demo</title>
<style>
body {
font-family: sans-serif;
text-align: center;
}
h1 {
margin-top: 100px;
margin-bottom: 0;
font-size: 80px;
font-weight: normal;
}
h2 {
font-size: 40px;
font-weight: normal;
}
p {
font-size: 25px;
}
.results {
display: none;
margin-top: 60px;
padding: 40px 60px;
background-color: lightblue;
border: 4px red solid;
}
.results p {
margin-top: 10px;
margin-bottom: 10px;
}
.big-if-true {
font-size: 100px;
}
.mobile-only {
display: none;
}
iframe {
margin-top: 40px;
}
@media all and (max-width: 480px) {
.not-mobile {
display: none;
}
.mobile-only {
display: block;
}
h1 {
font-size: 60px;
}
h2 {
font-size: 30px;
}
}
</style>
</head>
<body>
<h1>futurelink</h1>
<h2>literally predicts the future</h2>
<h2 class="mobile-only">and literally doesn't work on mobile :(</h2>
<h2 class="mobile-only">(try from a desktop)</h2>
<p class="not-mobile">(click the link)</p>
<p class="not-mobile">→ <a href class="demo-link">click me!</a> ←</p>
<div class="results">
<p>the click event was fired at <span class="click-time"></span></p>
<p>the hover event was fired <span class="hover-time"></span>ms before that</p>
<p>futurelink guessed you were going to click on the link</p>
<p class="big-if-true"><span class="future-time"></span>ms</p>
<p>before the click event</p>
</div>
<p>
<iframe src="https://ghbtns.com/github-btn.html?user=samknows&repo=futurelink&type=star&count=true&size=large" frameborder="0" scrolling="0" width="120px" height="30px"></iframe>
</p>
<script src="futurelink.js"></script>
<script>
var demoLinkEl = document.querySelector('.demo-link');
var resultsEl = document.querySelector('.results');
var clickTimeEl = resultsEl.querySelector('.click-time');
var hoverTimeEl = resultsEl.querySelector('.hover-time');
var futureTimeEl = resultsEl.querySelector('.future-time');
var times = {};
var teardown = futurelink({
links: [demoLinkEl],
future: function () {
times.future = Date.now();
},
hover: function () {
times.hover = Date.now();
}
});
demoLinkEl.addEventListener('click', function (e) {
e.preventDefault();
times.click = Date.now();
resultsEl.style.display = 'inline-block';
demoLinkEl.parentElement.style.display = 'none';
clickTimeEl.innerHTML = new Date(times.click).toISOString().slice(11, -1);
hoverTimeEl.innerHTML = (times.click - times.hover) || 0;
futureTimeEl.innerHTML = (times.click - times.future) || 0;
// This isn't really doing much here, just for testing during development
teardown();
});
</script>
</body>
</html>