-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
31 lines (27 loc) · 984 Bytes
/
background.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
chrome.runtime.onInstalled.addListener(() => {
chrome.alarms.create('checkReminders', { periodInMinutes: 1 });
});
chrome.alarms.onAlarm.addListener((alarm) => {
if (alarm.name === 'checkReminders') {
checkReminders();
}
});
function checkReminders() {
chrome.storage.local.get('pendingTabs', (result) => {
const now = new Date().getTime();
const pendingTabs = result.pendingTabs || [];
pendingTabs.forEach((tab, index) => {
if (tab.reminderTime && now >= tab.reminderTime) {
chrome.notifications.create({
type: 'basic',
iconUrl: 'icon.png',
title: 'Tab Reminder',
message: `Time to check this tab: ${tab.title}`
});
// Remove the reminder after notification
delete pendingTabs[index].reminderTime;
chrome.storage.local.set({ pendingTabs: pendingTabs });
}
});
});
}