-
-
Notifications
You must be signed in to change notification settings - Fork 535
Expand file tree
/
Copy pathmicrobreak-renderer.js
More file actions
61 lines (50 loc) · 2.27 KB
/
Copy pathmicrobreak-renderer.js
File metadata and controls
61 lines (50 loc) · 2.27 KB
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
import HtmlTranslate from './utils/htmlTranslate.js'
import './platform.js'
window.onload = async (event) => {
const [idea, started, duration, strictMode, postpone,
postponePercent, backgroundColor] = await window.breaks.sendBreakData()
new HtmlTranslate(document).translate()
document.ondragover = event =>
event.preventDefault()
document.ondrop = event =>
event.preventDefault()
document.querySelector('#close').onclick = async event =>
await window.breaks.finishBreak()
document.querySelector('#postpone').onclick = async event =>
await window.breaks.postponeBreak()
document.querySelector('.microbreak-idea').textContent = idea
const progress = document.querySelector('#progress')
const progressTime = document.querySelector('#progress-time')
const postponeElement = document.querySelector('#postpone')
const closeElement = document.querySelector('#close')
const mainColor = await window.settings.get('mainColor')
document.body.classList.add(mainColor.substring(1))
document.body.style.backgroundColor = backgroundColor
document.querySelectorAll('.tiptext').forEach(async tt => {
const keyboardShortcut = await window.settings.get('endBreakShortcut')
tt.innerHTML = await window.utils.formatKeyboardShortcut(keyboardShortcut)
})
window.setInterval(async () => {
if (await window.settings.get('currentTimeInBreaks')) {
document.querySelector('.breaks > :last-child').innerHTML =
(new Date()).toLocaleTimeString()
}
if (Date.now() - started < duration) {
const passedPercent = (Date.now() - started) / duration * 100
if (await window.utils.canPostpone(postpone, passedPercent, postponePercent)) {
postponeElement.classList.remove('hidden')
} else {
postponeElement.classList.add('hidden')
}
if (await window.utils.canSkip(strictMode, postpone, passedPercent, postponePercent)) {
closeElement.classList.remove('hidden')
} else {
closeElement.classList.add('hidden')
}
progress.value = (100 - passedPercent) * progress.max / 100
progressTime.innerHTML = await window.utils.formatTimeRemaining(Math.trunc(duration - Date.now() + started),
await window.settings.get('language'))
}
}, 100)
await window.breaks.signalLoaded()
}