-
Notifications
You must be signed in to change notification settings - Fork 0
/
!clock.htm
235 lines (192 loc) · 5.97 KB
/
!clock.htm
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
<!DOCTYPE html> <!-- Must be specified lest serious malfunction in IE8 (probably IE10 and below). -->
<meta charset="UTF-8" />
<meta name="viewport" content="user-scalable=no" />
<title>!Clock</title>
<!--
JavaScript based digital clock. ("Date" API based)
Highly customizable.
Intended to just work with random browsers.
Firefox 45 below lack support for "innerText": replace all occurrences of which in "<script>" to "innerHTML", as workaround.
(caveat the difference between "innerText" "innerHTML")
-->
<noscript>
<pre style="white-space: pre-wrap; word-wrap: break-word; tab-size: 4">
JavaScript support required.
Check the unrendered source for details.
</pre>
</noscript>
<script>
getElementById = function ( x, id ) {
// >>>> (0)
var x0 = ( ! /^\d+$/.test( id ) ?
x.children[id] : /* While numeric id cause misbehaviors in major implementations. */
x.children.namedItem( id ) ); // "HTMLCollection.namedItem" is case-insensitive in IE.
if ( x0 ) {
return ( ! x0[1] ? x0 : x0[0] );
// And may return more than just the first element if multiple ones eligible...
} else if ( x === undefined ) {
return;
}; // Using "if ... else ..." here is ~~not~~ merely a preference. [ No difference observed. Nor possible semantically. ]
/*
[[
( x0 ) && return ( ! x0[1] ? x0 : x0[0] );
( x === undefined ) && return;
]]
“Unexpected token "return"”
*/
for ( var i = 0; i < x.children.length; ++ i ) {
if ( x0 = getElementById( x.children[i], id ) ) { return x0; };
};
// <<<< (0)
};
// ----
onload = function () {
// >>>> (0)
function tzparse ( x, i ) {
// >>>> (1)
var _ = getElementById( x, "tz" ), _ = ( _ ? _.innerText : "" );
//
// Merely demonstrating the syntax.
// The "," in JavaScript is much semantical non-sense. (replaceable by ";")
//
// RegEx reference: https://regex101.com/?regex=^(%5B%2B%5C-%5D)(%5Cd%7B2%7D):(%5Cd%7B2%7D)%24&flags=
//
if ( _ = _.match( /^([+\-])(\d{2}):(\d{2})$/ ) ) {
tz[i] = ( _[1] === "+" ? {
h: Number( _[2] ),
m: Number( _[3] )
} : {
h: - Number( _[2] ),
m: - Number( _[3] )
} );
} else {
tz[i] = { h: 0, m: 0 };
};
tz[i] = [ tz[i] ].concat( [
getElementById( x, "Y" ),
getElementById( x, "M" ),
getElementById( x, "D" ),
getElementById( x, "h" ),
getElementById( x, "m" ),
getElementById( x, "s" ),
getElementById( x, "d" )
] );
// <<<< (1)
};
window.tz = []; // Not prefixing "window." failed in IE8 and IE6.
{
var
x = document.getElementById( "0" ),
n = 0 }; // "n" works as intended.
if ( x ) {
tzparse( x, 0 );
n = 1;
};
try {
x = document.getElementById( "1" ).children;
for ( var i = 0; i < x.length; ++ i ) {
tzparse( x[i], i + n );
};
} catch ( e ) {
};
init();
setInterval( init, 1000 );
( document.body ) || (
document.body = document.getElementsByTagName( "body" )[0]
);
document.body.children[0].style.display = "block";
// <<<< (0)
};
function init () {
// >>>> (0)
(function ( x ) {
var i = 0;
for ( ; i < tz.length; ) {
// >>>> (1)
var t = new Date( x );
t.setUTCHours(
( t.getUTCHours() + tz[i][0]["h"] ),
( t.getUTCMinutes() + tz[i][0]["m"] ) );
tz[i][1].innerText = t.getUTCFullYear();
tz[i][2].innerText = _0( t.getUTCMonth() + 1 );
tz[i][3].innerText = _0( t.getUTCDate() );
tz[i][4].innerText = _0( t.getUTCHours() );
tz[i][5].innerText = _0( t.getUTCMinutes() );
tz[i][6].innerText = _0( t.getUTCSeconds() );
( tz[i][7] ) && ( tz[i][7].innerText = t.getUTCDay() );
//
// "," may be of use under similar contexts.
// For support for block statement "{ ... }" [1] under such is broken.
//
// [1] Caveat "{ ... }" in JavaScript may also mean Object notation depending on the context.
//
++ i;
// <<<< (1)
}; })( new Date() );
//
// `(function () { ... })();` form somewhat resembles the isolated block structure in some other languages. (which might be simply expressed as `{ ... };`)
//
function _0 ( num ) {
return String( num > 9 ? num : "0" + num );
};
// <<<< (0)
};
</script>
<style>
q { quotes: none; }
html { background-color: #000; color: #FFF; } /* Contrast */
html { background-color: #e6e6e6; color: #146c9c; } /* Bright */
html { background-color: #283e59; color: #dcf2e8; } /* Mid */
html { background-color: #0c1d18; color: #acbeb6; } /* Dark */
/* Last occurrence of repetitive definitions takes precedence. */
div.body > div {
text-align: center;
} /* IE6 doesn't support CSS combinators. */
/* Workaround: Change the selector definition to `body`. */
.up { font-size: 200%; }
.dn { font-size: 50%; }
.thin { opacity: 0.35; }
</style>
<!--
Adjust "font-size" on need.
"vw" unit doesn't work on too old browsers.
-->
<div class="body" style="
display: none; /* Overridden upon `onload`. */
white-space: nowrap;
font-family: monospace;
font-size: 5.5vw;
">
<div id="0" class="up"><br/>
<!--
Main clock.
Modify "#tz" to change time zone.
.
See "tzparse" for time zone parsing logic.
-->
CE <q id="Y"></q>-<q id="M"></q>-<q id="D"></q><br/>
<div style="font-size: 200%">
<q id="h"></q><q class="dn">:</q><q id="m"></q><q class="dn">:</q><q id="s"></q><br/>
</div>
<div class="dn">
<q id="tz" style="font-size: 120%">+08:00</q><br/>
<q class="thin">(</q>Day <q id="d" style="font-size: 120%; vertical-align: -5%"></q><q class="thin">)</q>
</div>
</div>
<hr/>
<!--
Auxiliary clocks.
Adapt the elements inside to configure.
"#1" is also removable.
"Element.children" in IE8 and below also counts XML comments.
-->
<div id="1" class="body">
<div><br/>CE <q id="Y"></q>-<q id="M"></q>-<q id="D"></q> <q id="h"></q>:<q id="m"></q>:<q id="s"></q> <q id="tz">UTC</q></div>
<div><br/>CE <q id="Y"></q>-<q id="M"></q>-<q id="D"></q> <q id="h"></q>:<q id="m"></q>:<q id="s"></q> <q id="tz">-07:00</q></div>
</div>
</div>
<!--
References:
|*| https://developer.mozilla.org/en-US/search?q=${Term}
|*| https://caniuse.com/?search=${Term}
-->