-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepo.js
104 lines (93 loc) · 2.65 KB
/
repo.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
'use strict';
function randomize(){
const hands = [
'hours-hand',
'minutes-hand',
'seconds-hand',
];
for(const hand in hands){
const style = core_elements[hands[hand]].style;
style.backgroundColor = '#' + core_random_hex();
style.border = '1px solid #000';
style.height = '10px';
style.left = '50%';
style.position = 'fixed';
style.top = (core_storage_data['radius'] + 100) + 'px';
style.transformOrigin = 'left';
style.width = (hand * (core_storage_data['radius'] / 3) + (core_storage_data['radius'] / 3)) + 'px';
}
const style = core_elements['face'].style;
style.backgroundColor = '#' + core_random_hex();
style.borderRadius = core_storage_data['radius'] + 'px';
style.height = (core_storage_data['radius'] * 2) + 'px';
style.left = '50%';
style.marginLeft = -core_storage_data['radius'] + 'px';
style.position = 'fixed';
style.top = '105px';
style.width = style.height;
for(const hand in hands){
core_elements[hands[hand]].style.backgroundColor = '#' + core_random_hex();
}
core_elements['face'].style.backgroundColor = '#' + core_random_hex();
}
function repo_init(){
core_repo_init({
'events': {
'randomize': {
'onclick': randomize,
},
},
'info': '<button id=randomize type=button>Randomize Colors</button>',
'reset': randomize,
'storage': {
'radius': 300,
},
'storage-menu': '<table><tr><td><input class=mini id=radius min=1 step=any type=number><td>px Radius</table>',
'title': 'Clock.htm',
'ui-elements': [
'face',
'hours-hand',
'minutes-hand',
'seconds-hand',
'time',
],
});
second();
randomize();
core_interval_modify({
'id': 'clock',
'interval': 1000,
'sync': true,
'todo': second,
});
}
function rotate_hand(id, percent){
core_elements[id].style.transform =
'rotate(' + (360 * percent - 90) + 'deg)';
}
function second(){
const date = timestamp_to_date();
const formatted = time_format({
'date': date,
});
document.title = formatted;
core_elements['time'].textContent = formatted;
if(date['hour'] > 11){
date['hour'] -= 12;
}
date['hour'] = date['hour'] / 12;
date['minute'] = date['minute'] / 60;
date['second'] = date['second'] / 60;
rotate_hand(
'hours-hand',
date['hour'] + date['minute'] / 12
);
rotate_hand(
'minutes-hand',
date['minute'] + date['second'] / 60
);
rotate_hand(
'seconds-hand',
date['second']
);
}