/
index.html
executable file
·165 lines (139 loc) · 4.92 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<html>
<head>
<title>Rest Your Eyes</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href='https://fonts.googleapis.com/css?family=Kaushan+Script' rel='stylesheet' type='text/css'>
<style>
body {
position: relative;
text-align: center;
}
* {
font-family: 'Kaushan Script', cursive;
}
a {
color: rgb(70,70,70);
}
button {
margin-top: 1rem;
width: 10rem;
cursor: pointer;
padding: 0.5rem 1.5rem;
background-color: rgba(0,0,0,0);
color: black;
border: none;
border-radius: 4px;
text-shadow: none;
box-shadow: 0 0 0 2px black inset !important;
outline: 0;
}
button:hover,
button:focus,
button:active {
background: black;
color: white;
box-shadow: 0 0 0 2px white inset !important;
}
.main-display, button, input {
font-size: 1.25rem;
}
#jEyeRest-alert-interval {
text-align: center;
margin-left: 0.5rem;
}
#jEyeRest {
position: absolute;
top: 25%;
width: 100%;
}
#jEyeRest-timer {
font-size: 3rem;
}
#jEyeRest-logo {
margin-top: 10rem;
margin-bottom: 1rem;
}
.main-display {
line-height: 5rem;
}
</style>
</head>
<body>
<div id="jEyeRest">
<h1>Rest your eyes before you go blind, fool.</h1>
<div class="alertOff">
<div class="main-display">
Minute(s) until you stand your butt up:
<input id="jEyeRest-alert-interval" type="text" maxlength="4" size="4"/>
</div>
<button id="jEyeRest-start-interval">Start</button>
</div>
<div class="alertOn" hidden>
<div class="main-display">
<span id="jEyeRest-timer">00:00</span> minute(s) until you stand your butt up
</div>
<button id="jEyeRest-stop-interval">Stop</button>
</div>
<div id="jEyeRest-logo">jEyeRest - by <a href="http://xmiao2.github.io">Xiaohang Miao</a></div>
</div>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
function renderTimer(timer) {
// Render formatted time
$("#jEyeRest-timer").html(("0"+Math.floor((timer/3600000)%60)).substr(-2) + ":" + ("0"+Math.floor((timer/60000)%60)).substr(-2) + ":" + ("0"+Math.floor((timer/1000)%60)).substr(-2));
}
function clearAlert() {
window.clearInterval(window.alertInterval);
window.clearInterval(window.renderInterval);
$("body").css("background-color", window.JEYEREST_DEFAULTS.BGCOLOR_INIT);
$(".alertOff").show();
$('.alertOn').hide();
}
$("#jEyeRest-start-interval").on("click", function(event){
var self = this;
$(".alertOff").hide();
$('.alertOn').show();
$("body").css("background-color", window.JEYEREST_DEFAULTS.BGCOLOR_RUN);
// Validate Input
var minutes = $("#jEyeRest-alert-interval").val();
if(!minutes || isNaN(minutes) || minutes <= 0) {
minutes = window.JEYEREST_DEFAULTS.MINUTES;
} else if(minutes < 1) {
minutes = 1;
} else if(minutes > 1440) { // # of minutes in a day
minutes = 1440;
}
$("#jEyeRest-alert-interval").val(minutes);
// Process input
var interval = minutes * 60 * 1000;
var timer = interval;
var timerInterval = 1000;
renderTimer(timer);
// Timer Interval
window.renderInterval = setInterval(function(){
timer -= timerInterval;
renderTimer(timer);
}, timerInterval);
// Alert Interval
window.alertInterval = setInterval(function(){
clearAlert();
alert("Stand your butt up and rest your eyes NOW!!!");
},interval);
});
$("#jEyeRest-stop-interval").on("click", function(event){
clearAlert();
})
$(function(){
window.JEYEREST_DEFAULTS = {
MINUTES: 20,
BGCOLOR_INIT: "#78A3CC",
BGCOLOR_RUN: "#B6D68D"
};
window.alertInterval = {};
window.renderInterval = {};
$("body").css("background-color", JEYEREST_DEFAULTS.BGCOLOR_INIT);
$("#jEyeRest-alert-interval").attr("placeholder", JEYEREST_DEFAULTS.MINUTES);
});
</script>
</body>
</html>