-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocal.html
306 lines (262 loc) · 10 KB
/
local.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Big Clock</title>
<meta name="description" content="A clock, but BIG. The current time in your current time zone.">
<meta name="keywords" content="clock, big, current time, now">
<meta name="author" content="virtualgeoff">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="color-scheme" content="light dark">
<link rel="icon" href="data:,">
<meta name="apple-mobile-web-app-capable" content="yes">
<style>
html, body {min-height:100%; margin:0; padding:0;}
body {font-size:1em; font-family:'Courier', monospace;}
h1 {}
p {}
small {font-size:0.75em;}
a {text-decoration:none; opacity:60%}
a:hover {text-decoration:underline; opacity:100%}
/* nav */
#nav {position:fixed; left:0.5em; top:0; margin:0.6em; z-index:99;}
#nav.shifted {top:5.0em;}
#nav ul {display:none; width:auto; margin:0; padding:0.5em 1em 0.5em 0.3em; list-style:none; border:1px solid #000;}
#nav:hover ul {display:block;}
#nav li {margin:0; padding:0; white-space:nowrap;}
#nav li a {display:block; margin:0; padding:0.3em;}
#nav > a {font-size:1.5em;}
/* main layout */
#date, #time, #zone {margin:0; padding:0; font-size:4em; font-weight:normal; text-align:center;}
#date {padding-top:2em; line-height:0.75; opacity:0.3;}
#time {margin-top:1em; font-size:10em; line-height:0.75; white-space:nowrap;}
#zone {margin-top:2em; line-height:0.9; opacity:0.3;}
/* colors */
body {color:#111; background:#fff;}
a {color:#111;}
a:visited {color:#111;}
#nav ul {background:#fff; border-color:#111;}
body.Light {color:#111; background:#fff;}
body.Light a {color:#111;}
body.Light a:visited {color:#111;}
body.Light #nav ul {background:#fff; border-color:#111;}
body.Dark {color:#eee; background:#000;}
body.Dark a {color:#ddd;}
body.Dark a:visited {color:#ddd;}
body.Dark #nav ul {background:#000; border-color:#ddd;}
@media all and (prefers-color-scheme: dark) {
body {color:#eee; background:#000;}
a {color:#ddd;}
a:visited {color:#ddd;}
#nav ul {background:#000; border-color:#ddd;}
}
</style>
<script>
/* jshint esversion: 5 */
var date, time, zone, now;
var showHundredths = false;
var colors = {dynamic:false};
var isChrome = false;
var iPad = false;
function checkIPad() {
// check device
if (navigator.userAgent.match(/iPad/i) || ((navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1) && !window.MSStream)) {
iPad = true;
}
}
function toggleNav(e) {
var navlist = document.getElementById('navlist');
navlist.style.display = (navlist.style.display === 'block') ? 'none' : 'block';
return false;
}
function checkFullscreenAvailable() {
// check if fullscreen is available, and if so, add a link
// note: iPhone does not support fullscreen
var dE = document.documentElement;
if (dE.requestFullscreen || dE.webkitRequestFullScreen) {
document.getElementById('navlist').innerHTML += '<li><a href="#" title="Make full screen" onclick="return toggleFullscreen();">Fullscreen</a></li>';
}
}
function checkFullscreen() {
// check if currently in fullscreen mode
// should be able to do this with CSS : html:fullscreen / html:-webkit-full-screen
// or by checking existence of document.fullscreenElement or document.webkitFullscreenElement
// but on Safari it doesn't remember if you navigate between pages while in fullscreen
// (other browsers don't let you navigate between pages in fullscreen anyway)
// BUT... we can check screen and window dimensions!
if ((window.innerWidth === screen.width) && (window.innerHeight === screen.height) ||
(window.innerWidth === screen.height) && (window.innerHeight === screen.width)) {
// add class to #nav to move it away from big x
if (iPad) { document.getElementById('nav').className = 'shifted'; }
} else {
if (iPad) { document.getElementById('nav').className = ''; }
}
}
function toggleFullscreen(e) {
// toggle fullscreen mode
var d = document, dE = d.documentElement;
if (d.fullscreenElement || d.webkitFullscreenElement) {
if (d.exitFullscreen) {
d.exitFullscreen();
} else if (d.webkitCancelFullScreen) {
d.webkitCancelFullScreen();
}
} else {
if (dE.requestFullscreen) {
dE.requestFullscreen();
} else if (dE.webkitRequestFullScreen) {
dE.webkitRequestFullScreen();
}
}
return false;
}
function storageAvailable(type) {
// check for Storage API
try {
var storage = window[type],
x = '__storage_test__';
storage.setItem(x, x);
storage.removeItem(x);
return true;
} catch(e) {
return e instanceof DOMException && (
e.code === 22 || e.code === 1014 ||
e.name === 'QuotaExceededError' ||
e.name === 'NS_ERROR_DOM_QUOTA_REACHED'
) && storage.length !== 0;
}
}
function getOptions() {
// load options from localStorage on page load, and set colors, font, ...
if (!storageAvailable('localStorage')) { return; }
var colorScheme = localStorage.getItem('colorScheme');
var fontFamily = localStorage.getItem('fontFamily');
showHundredths = (localStorage.getItem('showHundredths') == 'true') ? true : false; // convert from string!
if (colorScheme) {
document.body.className = colorScheme;
if (colorScheme === 'Dynamic') {
colors.dynamic = true;
} else if (colorScheme === 'Custom') {
colors.text = localStorage.getItem('colorText') || '#000000';
colors.bg = localStorage.getItem('colorBG') || '#ff7700';
changeColors();
}
}
if (fontFamily) {
document.body.style.fontFamily = fontFamily;
}
}
function setDynamicColors(now) {
// set colors based on the current local time
colors.h = (now.getHours() + now.getMinutes()/60) * 15; // 0-360°
colors.s = now.getMinutes() + 40; // 40-100%
colors.l = (now.getSeconds() + now.getMilliseconds()/1000) + 20; // 20-80%;
colors.bg = 'hsl(' + colors.h + ', ' + colors.s + '%, '+ colors.l + '%)';
colors.text = (colors.l > 50) ? '#111' : '#ddd';
changeColors();
}
function changeColors() {
// change text, link, and background colors
document.body.style.backgroundColor = colors.bg;
document.body.style.color = colors.text;
document.getElementById('navlist').style.backgroundColor = colors.bg;
document.getElementById('navlist').style.borderColor = colors.text;
for (var i=0; i<document.links.length; i++) {
document.links[i].style.color = colors.text;
}
}
function resize() {
// size and postion the text
// could use vw units and display:flex, but want to stick to CSS 2.1
var w = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,
h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight,
vw = w/100,
fs = 19, // font size
lh = 0.75, // line height
mh; // margin height
// set font size and reduce if too wide
time.style.fontSize = fs * vw + 'px'; // = 19vw
while ((time.scrollWidth > time.clientWidth) && (fs > 12)) {
fs--;
time.style.fontSize = fs * vw + 'px';
console.log('font size: ' + fs + 'vw, ' + (fs * vw) + 'px');
}
date.style.fontSize = 5 * vw + 'px';
zone.style.fontSize = 5 * vw + 'px';
// calculate margins to space evenly
mh = (h - ((fs + 15) * lh * vw)) / 4; // 15 = 3 lines * 5vw
date.style.paddingTop = mh + 'px';
time.style.marginTop = mh + 'px';
zone.style.marginTop = mh + 'px';
// finally, check if fullscreen
checkFullscreen();
}
function update() {
// local time (12 hr)
now = new Date();
// toTimeString is always hh:mm:ss GMT±xxxx (TZ), but there's no quick way to get local date in ISO-8601 format, so
date.innerText = now.toLocaleDateString();
// Chrome gets toLocaleTimeString() wrong!
if (isChrome && navigator.language) {
time.innerHTML = ' ' + now.toLocaleTimeString(navigator.language) + ' ';
} else {
time.innerHTML = ' ' + now.toLocaleTimeString() + ' ';
}
zone.innerHTML = now.toTimeString().substring(12, 15) + ':' + now.toTimeString().substring(15, 17) +
'<br><small>' + now.toTimeString().substring(18) + '</small>';
if (colors.dynamic) { setDynamicColors(now); }
if (showHundredths) {
if (window.requestAnimationFrame) {
window.requestAnimationFrame(update);
} else {
setTimeout(update, 1000/30);
}
} else {
setTimeout(update, (1000 - now.getMilliseconds()));
}
}
function init() {
date = document.getElementById('date');
time = document.getElementById('time');
zone = document.getElementById('zone');
// is the browser Chrome?
if ((navigator.userAgent.indexOf('Chrome') != -1) && (navigator.userAgent.indexOf('Edg') === -1)) {
isChrome = true;
}
if (navigator.language) { console.log('isChrome: ' + isChrome + '\nnavigator.language: ' + navigator.language); }
checkIPad();
checkFullscreenAvailable();
getOptions();
update();
resize();
}
if (window.addEventListener) {
window.addEventListener('DOMContentLoaded', init);
window.addEventListener('resize', resize);
} else {
window.onload = init;
window.onresize = resize;
}
</script>
</head>
<body>
<div id="nav">
<a href="./" onclick="return toggleNav();"><b>☰</b></a><br>
<ul id="navlist">
<li><a href="./">The time (ISO 8601)</a></li>
<li><a href="./local.html">Local time format</a></li>
<li><a href="./utc.html">UTC</a></li>
<li><a href="./stopwatch.html">Stopwatch</a></li>
<li><a href="./timer.html">Timer</a></li>
<li><a href="./about.html">About</a></li>
<li><a href="./settings.html">Settings</a></li>
</ul>
</div>
<p id="date"><small>A clock, but BIG.<br> The current local time:</small></p>
<h1 id="time">00:00:00</h1>
<p id="zone"><small>This page requires Javascript!</small></p>
<!-- stats -->
<script async defer src="https://api.virtualgeoff.com/latest.js"></script>
<noscript><img src="https://api.virtualgeoff.com/noscript.gif" alt="" referrerpolicy="no-referrer-when-downgrade"></noscript>
</body>
</html>