-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.js
1529 lines (1274 loc) · 30.9 KB
/
script.js
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var jsont; // JSONPコールバック関数公開用
(function (window, $) {
var String = this.String;
var Date = this.Date;
var Math = this.Math;
var isNaN = this.isNaN;
var parseInt = this.parseInt;
var parseFloat = this.parseFloat;
var decode = this.decodeURIComponent;
// ベンダー プレフィックス
var webkit = 'webkit', moz = 'moz';
function prefix(object, key, vendors) {
if (key in object) {
return key;
}
var uc = key.charAt(0).toUpperCase() + key.substr(1);
for (var i = 0; i < vendors.length; i++) {
var prefixed = vendors[i] + uc;
if (prefixed in object) {
return prefixed;
}
}
return key;
}
var AudioContext = this[prefix(this, 'AudioContext', [webkit])];
var Utterance = this.SpeechSynthesisUtterance;
// 内部設定
// 表示更新間隔
var interval = Math.ceil(1000 / 24);
while (!(interval % 2 && interval % 5)) { interval++; }
// 時刻取得タイムアウト
var period = 3000;
// サーバリスト
var ids = [
'ntp-a4.nict.go.jp',
'ntp-a1.nict.go.jp',
'ntp-b1.nict.go.jp'
];
var path = '/cgi-bin/jsont?';
// 発振音の音量
var gain = Math.SQRT1_2 / 2;
// ヘルプのアドレス
var readme = 'https://github.com/yuru4c/117/blob/master/README.md';
// 共用変数
var date = new Date(70, 0);
var epoch = +date;
var days = ['日', '月', '火', '水', '木', '金', '土'];
var location = window.location;
var hidden = prefix($, 'hidden', [webkit, moz]);
var visibilitychange = hidden.slice(0, -6) + 'visibilitychange';
var context;
var direct, destination;
var latency;
var lang = 'ja-JP';
var langRe = /^ja/i;
var synthesis = window.speechSynthesis;
function l(handle) {
return function (e) {
if (e == null) { e = event; }
if (!('target' in e)) {
e.target = e.srcElement;
}
return handle.call(this, e);
};
}
// 設定画面
var pref; // #pref要素
var refetch; // #refetch要素 再取得ボタン
var diffText, leapText, lastText; // 補正, 閏秒, 最終更新 TextNode
var form; var fk; var fv; var fa;
var parsed;
var invalid;
var lis = []; // 時刻補正ログ li要素[]
var logTexts = []; // 時刻補正ログ TextNode[]
var unknown = '不明';
// 文字列
function dstr(d) { // 符号反転
return (d < 0 ? '+' : '') + -d;
}
function rstr(d, r) { // 時差, RTT
return dstr(d) + ' ± ' + (r + r % 2) / 2;
}
// 表示更新
function result() {
diffText.data = dstr(diff);
}
function lresult() {
var str = (step == null ? unknown :
(step > 0 ? '+' : '') + step / 1000) + ' @ ';
if (leap == null) {
str += unknown;
} else {
date.setTime(leap);
str += date.toLocaleString();
}
leapText.data = str;
}
function log(i, str) {
logTexts[i].data = str;
}
function validate() {
invalid = true;
var value = fv.value;
if (value) {
switch (fk.selectedIndex) {
case 1:
parsed = parseInt(value, 10);
invalid = isNaN(parsed);
break;
case 2:
parsed = parseInt(value, 10);
invalid = !(-2 <= parsed && parsed <= +2);
break;
case 3:
parsed = Date.parse(value);
invalid = isNaN(parsed);
break;
}
}
fa.disabled = invalid;
}
function onsubmit() {
if (invalid) { return false; }
fv.blur();
switch (fk.selectedIndex) {
case 1:
diff = -parsed;
result();
break;
case 2:
step = parsed * 1000;
lresult();
break;
case 3:
leap = parsed - parsed % 60000;
lresult();
break;
}
testleap(new Date() - diff);
pcode = null;
this.reset();
validate();
return false;
}
function toggle() {
var parent = this.parentNode;
while (parent != null) {
var next = parent.nextSibling;
while (next != null) {
if (next.nodeType == 1) {
next.style.display = this.checked ? '' : 'none';
return;
}
next = next.nextSibling;
}
parent = parent.parentNode;
}
}
function focused() {
$.activeElement.select();
}
function onfocus() {
window.setTimeout(focused);
}
// 設定
var config = {
s: false, d: 10, f: 2,
t: false, m: true,
y: false, a: 3,
k: false, k1: 21, k2: 6,
h0: false, h1: false, h2: false, h3: false,
h4: false, h5: false, h6: false,
v: false, i: 10, n: 1, p: 0,
j: false, z: true,
x: false,
l: false, g: false, r: false,
c: false, w: false,
_: false,
ntp: true,
before: 9, after: 1,
next: '',
prev: '',
jjy: false
};
var inputs = {};
var button;
var inputTag = 'INPUT', selectTag = 'SELECT';
var dClass = 'disabled', emClass = 'em';
var xids = [
's', 'v', 't', 'm', 'y',
'j', 'l', 'x', 'c', '_', 'w', 'z', 'g', 'r'
];
var wids = ['h0', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
function prev() {
return config.i != 10 || config.n == 4;
}
function d(input, disabled) {
if (disabled == null) {
disabled = input.disabled;
} else {
input.disabled = disabled;
}
input.parentNode.className = disabled ? dClass : '';
}
function em(input, not) {
if (not) return;
var parent = input.parentNode;
var className = parent.className;
parent.className = className ?
className + ' ' + emClass : emClass;
}
function disable() {
d(inputs.d, config.s);
d(inputs.f, config.s);
d(inputs.t, config.s);
d(inputs.m, config.s || config.t);
d(inputs.y, config.s);
d(inputs.a, config.s || config.y);
d(inputs.k1, !config.k);
d(inputs.k2, !config.k);
d(inputs.i, config.v);
d(inputs.n, config.v);
d(inputs.p, config.v || !prev());
d(inputs.j, config.v || config.i >= 3600);
d(inputs.z, config.v || config.i >= 60);
d(inputs.x, config.v);
d(inputs.g, config.v || config.l);
d(inputs.r, config.l);
d(inputs.c, config.v);
d(inputs.w, config.v);
d(select, config.v);
for (var id in binds) {
binds[id].disable(config.v);
}
d(inputs.before, config.v);
d(inputs.after, config.v);
d(inputs.next, config.v || config.n != -1);
d(inputs.prev, config.v || config.p != -1);
for (var i = 0; i < radios.length; i++) {
d(radios[i], !config.jjy);
}
}
function dirty() {
button.disabled = false;
}
function resume() {
if (!context) {
context = new AudioContext();
direct = context.destination;
destination = context.createGain();
destination.gain.value = gain;
destination.connect(direct);
latency = context.baseLatency;
if (latency == null) {
latency = 0;
}
}
if (context.resume != null) {
context.resume();
}
}
function speak() {
synthesis.speak(new Utterance(' '));
}
function reset() {
for (var i = 0; i < code.length; i++) {
pulses[i].className = '';
}
active = null;
pcode = null;
var parent = bar.parentNode;
if (parent != null) {
parent.removeChild(bar);
pt = null;
}
}
function oncheck() {
switch (this.id) {
case 's':
if (!this.checked) {
resume();
}
break;
case 'v':
if (!this.checked) {
speak();
}
break;
case 'l': case 'r':
changed = true;
break;
case 'jjy':
if (this.checked) {
resume();
} else {
reset();
}
break;
}
config[this.id] = this.checked;
disable();
switch (this.id) {
case 'jjy':
break;
case 's': case 'v':
d(this);
default:
dirty();
}
}
function onselect() {
config[this.id] = +this.value;
disable();
dirty();
}
function oninput() {
config[this.id] = this.value;
dirty();
}
function register(id) {
var input = $.getElementById(id);
if (input == null) return;
switch (input.tagName) {
case inputTag:
switch (input.type) {
case 'checkbox':
input.checked = config[id];
input.onclick = oncheck;
break;
default:
input.value = config[id];
input.onfocus = onfocus;
input.oninput = oninput;
input.onchange = oninput;
break;
}
break;
case selectTag:
input.value = config[id];
input.onchange = onselect;
break;
}
inputs[id] = input;
}
function alt(altKey) {
pref.className = altKey ? 'alt' : '';
}
var onkeydown = l(function (event) {
var altKey = event.altKey;
alt(altKey);
var key = String.fromCharCode(event.keyCode ^ 32);
if (key in inputs) {
var input = inputs[key];
if (input.disabled) return;
var target = event.target;
var tagName = target.tagName;
var not = !(
tagName == selectTag ||
tagName == inputTag && target.type == 'text');
if (not || altKey) {
input.focus();
if (altKey) {
if (not) {
input.click();
}
return false;
}
}
}
});
var onkeyup = l(function (event) {
alt(event.altKey);
});
// 詳細設定
var select;
var voiceURI;
var voices = [];
var voice;
var params = {volume: null, rate: null, pitch: null};
var binds = {};
var frequency;
var radios;
function setVoice(changed) {
voice = voices[select.selectedIndex];
if (changed) {
dirty();
}
}
function onvoiceschanged() {
var vs = this.getVoices();
var restore = false;
var selection = 0, i;
voices.length = 0;
for (i = select.length - 1; i >= 0; i--) {
select.remove(i);
}
for (i = 0; i < vs.length; i++) {
var v = vs[i];
var lang = v.lang;
if (lang && !langRe.test(lang)) continue;
var l = voices.push(v);
var uri = v.voiceURI;
var def = v['default'];
var option = $.createElement('option');
option.appendChild($.createTextNode(
def ? v.name + ' (既定値)' : v.name));
select.add(option);
if (voiceURI != null && uri == voiceURI) {
restore = true;
selection = l;
voiceURI = null;
}
if (restore) continue;
restore = voice != null && uri == voice.voiceURI;
if (restore || !selection && def) {
selection = l;
}
}
if (selection) {
select.selectedIndex = selection - 1;
}
setVoice(!restore);
}
function onchange() {
voiceURI = null;
setVoice(true);
}
function count(str) {
if (str != null) {
var point = str.indexOf('.');
if (point != -1) {
return str.length - point - 1;
}
}
return 0;
}
function toFixed(num, digits) {
var str = num.toString();
return count(str) < digits ? num.toFixed(digits) : str;
}
var handler = l(function (event) {
var param = binds[this.id]
.handle(event.target, event.type == 'change');
if (param != null) {
params[this.id] = param;
dirty();
}
});
function Bind(id) {
var param = params[id];
var span = $.getElementById(id);
this.parent = span.parentNode;
var inputs = span.getElementsByTagName('input');
this.input = inputs[0];
this.range = inputs[1];
this.value = +this.range.defaultValue;
this.min = +this.range.min;
this.max = +this.range.max;
this.digits = count(this.range.step);
if (param == null) {
params[id] = param = this.value;
}
this.input.value = toFixed(param, this.digits);
this.range.value = param;
this.input.placeholder = this.value.toFixed(this.digits);
this.input.onfocus = onfocus;
span.oninput = handler;
span.onchange = handler;
}
var bind = Bind.prototype;
bind.handle = function (target, change) {
var value = parseFloat(target.value);
switch (target.type) {
case 'range':
this.input.value = value.toFixed(this.digits);
return change ? value : null;
default:
if (isNaN(value)) {
value = this.value;
} else {
if (value < this.min) { value = this.min; }
if (value > this.max) { value = this.max; }
}
if (change) {
this.input.value = toFixed(value, this.digits);
}
this.range.value = value;
return value;
}
};
bind.disable = function (disabled) {
this.input.disabled = disabled;
this.range.disabled = disabled;
this.parent.className = disabled ? dClass : '';
};
function onclick() {
for (var i = 0; i < radios.length; i++) {
var radio = radios[i];
if (radio.checked) {
frequency = radio.value * 1000 / 3;
return;
}
}
}
// 読み込み・保存
var cb = '\\', cq = '"';
var sb = cb + '$&';
var rs = /\s/, rb = /\\\\/g, rq = /\\"/g, re = /\\(?=\s|")/g;
var ro = /\\|"/g, rp = /%/g;
var c0 = '0', c1 = '1';
var sh = ' --', se = '=', ss = '-';
function sets(ids, str) {
for (var i = 0; i < ids.length; i++) {
config[ids[i]] = str.charAt(i) == c1;
}
}
function intOf(str, defaultValue) {
var value = parseInt(str, 10);
return isNaN(value) ? defaultValue : value;
}
function custom(arg) {
var index = arg.indexOf(se);
if (index == -1) {
index = arg.length;
}
var key = arg.substring(0, index);
var value = arg.substr(index + 1);
switch (key) {
case 'off':
config.ntp = false;
break;
case 'voice':
voiceURI = value;
break;
case 'volume': case 'rate': case 'pitch':
var f = parseFloat(value);
if (isNaN(f)) break;
params[key] = f;
break;
case 'timing':
var ts = value.split(ss);
config.before = intOf(ts[0], config.before);
config.after = intOf(ts[1], config.after);
break;
case 'next': case 'prev':
config[key] = value;
break;
}
}
function set(arg) {
if (arg.charAt(0) != '-') return;
var c = arg.charAt(1);
var v = arg.substr(2);
switch (c) {
case 'x': sets(xids, v); break;
case 'w': sets(wids, v); break;
case 'f': case 'n': case 'p':
config[c] = intOf(v, 0);
break;
case 'a': config.a = intOf(v, 3); break;
case 's': config.d = intOf(v, 10); break;
case 'v': config.i = intOf(v, 10); break;
case 'q':
var ks = v.split(ss);
config.k = true;
config.k1 = intOf(ks[0], 0);
config.k2 = intOf(ks[1], config.k1);
break;
case '-': custom(v); break;
}
}
function load() {
var hash = location.hash;
if (!hash) return;
var str = decode(hash.substr(1));
var i = 0;
for (var c; c = str.charAt(i); i++) {
if (rs.test(c)) continue;
var v = '';
var b = i;
do {
if (c == cb) { i++; continue; }
if (rs.test(c)) break;
if (c != cq) continue;
v += str.substring(b, i).replace(re, '');
b = i + 1;
while (c = str.charAt(++i)) {
if (c == cb) { i++; continue; }
if (c == cq) break;
}
v += str.substring(b, i).replace(rq, cq);
b = i + 1;
} while (c = str.charAt(++i));
v += str.substring(b, i).replace(re, '');
set(v.replace(rb, cb));
}
}
function gets(ids, flag) {
var flags = '';
for (var i = 0; i < ids.length; i++) {
if (config[ids[i]]) {
flag = true;
flags += c1;
} else {
flags += c0;
}
}
return flag ? flags : null;
}
function quote(str) {
return cq + str
.replace(ro, sb)
.replace(rp, '%25') + cq;
}
function save() {
var hash = '-x' + gets(xids, true);
var w = gets(wids, false);
if (w) {
hash += ' -w' + w;
}
hash += ' -f' + config.f;
if (config.a != 3) {
hash += ' -a' + config.a;
}
hash += ' -n' + config.n;
hash += ' -p' + config.p;
hash += ' -s' + config.d;
hash += ' -v' + config.i;
if (config.k) {
hash += ' -q' + (config.k1 + ss + config.k2);
}
if (!config.ntp) {
hash += sh + 'off';
}
if (config.before != 9 || config.after != 1) {
hash += sh + 'timing' + se +
(config.before + ss + config.after);
}
if (!config.v) {
for (var id in params) {
var param = params[id];
if (param != 1) {
hash += sh + id + se + param;
}
}
if (voice != null) {
hash += sh + 'voice' + se + quote(voice.voiceURI);
}
}
if (config.n == -1) {
hash += sh + 'next' + se + quote(config.next);
}
if (config.p == -1) {
hash += sh + 'prev' + se + quote(config.prev);
}
location.hash = hash;
d(inputs.s);
d(inputs.v);
this.disabled = true;
}
function help() {
window.open(readme);
}
// 時刻補正 JSONP (http://www.nict.go.jp/JST/http.html)
var diff = 0; // クライアント時刻 - サーバ時刻 (ミリ秒)
var leap, step, leaps;
var leaping, stepped = false;
var head; // head要素 appendChild(script)用
var srcs = [];
var running, first; // 実行中, 最初の受信フラグ
var maxL, minU; // 時差 下限の最大値, 上限の最小値 (ミリ秒)
var i, length = ids.length;
var lastIt; // 最後(待機中)の発信時刻 (秒)
var script; // JSONP script要素
var timeoutId; // タイムアウト Timeout ID
// 補正された現在時刻を取得
function getNow() {
var now = new Date() - diff;
if (leaping) {
if (!stepped && now >= leaps) {
diff += step;
now -= step;
result();
stepped = true;
}
if (stepped && now >= leap) {
leaping = false;
stepped = false;
}
}
return now;
}
function half(n) { // n/2を0側へ丸める
return (n - n % 2) / 2;
}
function testleap(time) {
leaping = step && leap > time;
stepped = false;
if (leaping) {
leaps = step < 0 ? leap + step : leap;
}
}
// コールバック関数
function jsonp(json) {
var receivedDate = new Date(); // 受信時刻 直ちに取得
var it = json.it; // Initiated Time (秒)
if (it != lastIt) return; // 待機中の応答でなければ無視
window.clearTimeout(timeoutId); // タイムアウト解除
var serverTime = json.st * 1000; // (ミリ秒)
var l = it * 1000 - serverTime; // 時差 下限 (ミリ秒)
var u = receivedDate - serverTime; // 時差 上限 (ミリ秒)
// 誤差軽減
if (first) { // 最初の受信
first = false;
maxL = l;
minU = u;
} else {
if (l > maxL) { maxL = l; }
if (u < minU) { minU = u; }
}
diff = half(maxL + minU);
leap = json.next * 1000;
step = json.step * 1000;
testleap(serverTime);
result();
log(i, rstr(half(l + u), u - l) + ' ⇒ ' +
rstr(diff, minU - maxL) + ' ms');
next();
}
function send() { // JSONPリクエスト
script = $.createElement('script');
script.onerror = error;
script.type = 'text/javascript';
var src = srcs[i];
lastIt = new Date() / 1000; // 発信時刻 (秒)
script.src = src + lastIt;
head.appendChild(script); // 直ちに送信
}
function error() {
window.clearTimeout(timeoutId);
log(i, '× エラー');
next();
}
function timeout() { // タイムアウト
lastIt = null;
script.onerror = null;
head.removeChild(script);
log(i, '× タイムアウト');
next();
}
function next() { // 次のサーバへ
i++;
fetch();
}
function fetch() { // サーバ時刻を取得
if (i < length) {
log(i, '取得中...');
window.setTimeout(send); // リクエスト
timeoutId = window.setTimeout(timeout, period);
} else { // 完了
// 表示更新
if (!first) {
date.setTime(getNow());
lastText.data = date.toLocaleString();
lresult();
pcode = null;
}
form.className = '';
fk.disabled = false;
fv.disabled = false;
validate();
refetch.disabled = false;
refetch.value = '再取得';
running = false;
}
}
// サーバ時刻取得開始
function start() {
if (running) return; // 同時実行不可
running = true;
// 表示更新
refetch.disabled = true;
refetch.value = '取得中';
form.className = dClass;
fk.disabled = true;
fv.disabled = true;
fa.disabled = true;
for (var j = 1; j < length; j++) {
log(j, '保留');
}
jsont = jsonp; // コールバック関数を公開
first = true; // 最初
i = 0;
fetch();
}
// 表示
var h12;
var titleText, hrs, mins, secs, ms; // TextNodes
var pm, ps, pt; // 前の値 (上位含む)
var pstep, changed;
var active;
var original;
var refreshId;
function write(textNode, value, unit, add) { // 書き換え
var num = value % unit; // 表示する値
if (add) {
num += unit;
}
// ゼロ埋め
var padding = '';
for (var d = 10; d < unit; d *= 10) {
if (num < d) { padding += '0'; }
}
textNode.data = padding + num; // 書き換え
return (value - num) / unit; // 上位の値を返却
}
function minutely(now) {
date.setTime(now);
write(mins, date.getMinutes(), 60);
var h = date.getHours();
hrs.data = config.l || config.r && h == 12 ||
h < 12 ? h : h - 12;
h12.className = config.l ? 'h24' : h < 12 ? 'am' : 'pm';
titleText.data =
date.getFullYear() + '年' +
(date.getMonth() + 1) + '月' +
date.getDate() + '日 ' +
days[date.getDay()] + '曜日';
if (config.jjy) {
for (var i = 0; i < code.length; i++) {
pulses[i].className = 'code-' + code[i];