-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
113 lines (75 loc) · 2.28 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
<!DOCTYPE html>
<html>
<head>
<title>Do nothing for 1 minute</title>
<link rel="stylesheet" href="./index.css">
<link rel="shortcut icon" type="image/ico" href="./favicon.ico"/>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6022876081781991" crossorigin="anonymous"></script>
</head>
<body>
<h1> Can you do nothing for <strong>1</strong> minute?</h1>
<p id="timer"> 60 </p>
<div id="share">
<a href="https://twitter.com/intent/tweet?button_hashtag=Mindfulness&ref_src=twsrc%5Etfw&text=I did nothing for 1 minute - can you? https://donothingfor1minute.cggaurav.net" class="twitter-hashtag-button" data-show-count="false" data-size="Large">Yay 🥳 / Tweet this</a><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</div>
<p id="cheater"> 👎 </p>
<audio autoplay loop>
<source src="./weightless.m4a">
</audio>
</body>
<script>
const WAIT_INTERVAL = 1500
const START_INTERVAL = 500
let TIMER = 60
function cheating() {
if (TIMER > 0) {
document.getElementById("cheater").style.visibility = "visible"
TIMER = 60
document.getElementById("timer").innerHTML = TIMER
setInterval(() => {
document.getElementById("cheater").style.visibility = "hidden"
// Another way of doing it
}, WAIT_INTERVAL)
}
}
function startTimer() {
setInterval(() => {
if (!document.hasFocus()) {
cheating()
}
if (TIMER > 0) {
TIMER -= 1
}
document.getElementById("timer").innerHTML = TIMER
if (TIMER === 0) {
document.getElementById("timer").innerHTML = "🎉"
document.getElementById("share").style.display = "block"
// TODO, clear setInterval()
}
}, 1000)
}
// Let folks read the page
setTimeout(() => {
startTimer()
// Events
document.addEventListener("mousemove", (e) => {
cheating()
})
document.addEventListener("keydown", (e) => {
cheating()
})
document.addEventListener("touchmove", (e) => {
cheating()
})
document.addEventListener("touchstart", (e) => {
cheating()
})
window.onscroll = (e) => {
cheating()
}
document.addEventListener("scroll", (e) => {
cheating()
})
}, START_INTERVAL)
</script>
</html>