forked from gilatnaveh1/time-watch-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
49 lines (40 loc) · 1.46 KB
/
popup.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
let displayReminder = true;
const port = chrome.runtime.connect({
name: "Sample Communication"
});
window.onload = async ()=>{
console.log("onload");
const reminderButton = document.getElementById('reminder');
if(displayReminder) {
const twAlarm = await chrome.alarms.get("TimeWatchAlarm");
if(!twAlarm){
reminderButton.style.display = "block";
}
/*chrome.storage.sync.get("showReminder", (items) => {});*/
}
reminderButton?.addEventListener('click', async function () {
let date = new Date();
date.setMonth(date.getDay() >= 21 ? date.getMonth() + 1 : date.getMonth());
date.setDate(21);
date.setHours(14,0,0,0);
const answer = confirm("A reminder will be shown at " + new Intl.DateTimeFormat('en-GB').format(date));
if(answer){
chrome.runtime.sendMessage({to: "TW_BACKGROUND", body: "SET_REMINDER", date});
displayReminder = false;
}
window.close();
// await chrome.storage.sync.set({showReminder: "false"});
});
document.getElementById('start')?.addEventListener('click', async function () {
const ctab = await getCurrentTab()
chrome.runtime.sendMessage({to: "TW_BACKGROUND", body: "START", tabId: ctab.id});
});
};
const getCurrentTab = function () {
let queryOptions = {active: true, currentWindow: true};
return new Promise((resolve, reject) => {
chrome.tabs.query(queryOptions, (tabs) => {
resolve(tabs[0])
});
});
};