|
| 1 | +import HtmlTranslate from './utils/htmlTranslate.js' |
| 2 | +import './platform.js' |
| 3 | + |
| 4 | +window.onload = async (event) => { |
| 5 | + const [idea, started, duration, strictMode, postpone, |
| 6 | + postponePercent, backgroundColor] = await window.breaks.sendBreakData() |
| 7 | + |
| 8 | + new HtmlTranslate(document).translate() |
| 9 | + |
| 10 | + document.ondragover = event => |
| 11 | + event.preventDefault() |
| 12 | + |
| 13 | + document.ondrop = event => |
| 14 | + event.preventDefault() |
| 15 | + |
| 16 | + document.querySelector('#close').onclick = async event => |
| 17 | + await window.breaks.finishBreak() |
| 18 | + |
| 19 | + document.querySelector('#postpone').onclick = async event => |
| 20 | + await window.breaks.postponeBreak() |
| 21 | + |
| 22 | + document.querySelector('.break-idea').textContent = idea[0] |
| 23 | + document.querySelector('.break-text').textContent = idea[1] |
| 24 | + |
| 25 | + const progress = document.querySelector('#progress') |
| 26 | + const progressTime = document.querySelector('#progress-time') |
| 27 | + const postponeElement = document.querySelector('#postpone') |
| 28 | + const closeElement = document.querySelector('#close') |
| 29 | + const mainColor = await window.settings.get('mainColor') |
| 30 | + document.body.classList.add(mainColor.substring(1)) |
| 31 | + document.body.style.backgroundColor = backgroundColor |
| 32 | + |
| 33 | + document.querySelectorAll('.tiptext').forEach(async tt => { |
| 34 | + const keyboardShortcut = await window.settings.get('endBreakShortcut') |
| 35 | + tt.innerHTML = await window.breaks.formatKeyboardShortcut(keyboardShortcut) |
| 36 | + }) |
| 37 | + |
| 38 | + window.setInterval(async () => { |
| 39 | + if (await window.settings.get('currentTimeInBreaks')) { |
| 40 | + document.querySelector('.breaks > :last-child').innerHTML = |
| 41 | + (new Date()).toLocaleTimeString() |
| 42 | + } |
| 43 | + if (Date.now() - started < duration) { |
| 44 | + const passedPercent = (Date.now() - started) / duration * 100 |
| 45 | + await window.breaks.canSkip(strictMode, postpone, passedPercent, postponePercent) |
| 46 | + postponeElement.style.display = |
| 47 | + await window.breaks.canPostpone(postpone, passedPercent, postponePercent) ? 'flex' : 'none' |
| 48 | + closeElement.style.display = |
| 49 | + await window.breaks.canSkip(strictMode, postpone, passedPercent, postponePercent) ? 'flex' : 'none' |
| 50 | + progress.value = (100 - passedPercent) * progress.max / 100 |
| 51 | + progressTime.innerHTML = await window.breaks.formatTimeRemaining(Math.trunc(duration - Date.now() + started), |
| 52 | + await window.settings.get('language')) |
| 53 | + } |
| 54 | + }, 100) |
| 55 | + await window.breaks.signalLoaded() |
| 56 | +} |
0 commit comments