-
Notifications
You must be signed in to change notification settings - Fork 0
/
new_tab.js
51 lines (40 loc) · 1.12 KB
/
new_tab.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
var bg = document.getElementById('bg')
var time = document.getElementById('time')
chrome.storage.sync.get({
clockEnabled: true,
color: "",
}, (opt) => {
if (opt.clockEnabled) {
refreshTime()
} else {
time.style.display = 'none'
}
bg.style.background = (opt.color.length > 0) ? opt.color : newGradient()
})
window.setTimeout(() => {
bg.style.opacity = 1
}, 15)
window.setInterval(() => {
refreshTime()
}, 15000)
function newGradient() {
var rands = []
for (var i = 0; i < 6; i++) {
rands.push(Math.floor(Math.random() * 255) + 1)
}
var c1 = 'rgb(' + rands[0] + ',' + rands[1] + ',' + rands[2] + ')'
var c2 = 'rgb(' + rands[3] + ',' + rands[4] + ',' + rands[5] + ')'
return 'linear-gradient(to top right, ' + c1 + ',' + c2 + ')'
}
function refreshTime(date = new Date()) {
var hours = date.getHours()
var ampm = hours < 12 ? 'AM' : 'PM'
if (hours > 12)
hours -= 12
if (hours == 0)
hours = 12
var mins = date.getMinutes()
if (mins < 10)
mins = '0' + mins
time.innerText = hours + ':' + mins + ' ' + ampm
}