-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpopup.js
More file actions
35 lines (29 loc) · 1.21 KB
/
popup.js
File metadata and controls
35 lines (29 loc) · 1.21 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
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
if (message.type && message.type === 'updateUI') {
updateDisplay();
}
});
document.addEventListener('DOMContentLoaded', function() {
updateDisplay();
document.getElementById('reset').addEventListener('click', function() {
chrome.storage.local.set({'count': 0, 'time': 3*60*60}, function() {
updateDisplay();
});
chrome.runtime.sendMessage({reset: true});
});
setInterval(updateDisplay, 1000);
});
function updateDisplay() {
chrome.storage.local.get(['count', 'time'], function(result) {
document.getElementById('count').textContent = result.count || '0';
document.getElementById('time').textContent = formatTime(result.time || 3*60*60);
document.getElementById('time').style.color = 'white';
document.getElementById('time').style.fontWeight = '550';
});
}
function formatTime(seconds) {
let hours = Math.floor(seconds / 3600);
let minutes = Math.floor((seconds % 3600) / 60);
seconds = seconds % 60;
return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
}