-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
33 lines (28 loc) · 1.21 KB
/
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
32
33
// When chrome extension is installed, clear previous notifications, and set the default theme to light.
// This is mostly used in development to prevent previous saved data clogging up a new version.
chrome.runtime.onInstalled.addListener((details) => {
if (details.reason == "install") {
chrome.storage.sync.set({"theme": "light"}, ()=>{});
chrome.storage.sync.set({"notifications": []}, ()=>{});
}
})
// Initialize OneSignal project and notifications.
OneSignal.init({
appId: "1e71fe3f-1946-42ca-9e77-956a87cb8b3c",
googleProjectNumber: "1036103748498"
});
/**
* When a push notification is received, log the notification in chrome storage for future retrieval.
* @param {object} json - notification JSON
* @param {string} url - url the notification would open
*/
function onNotificationReceived(json, url) {
chrome.storage.sync.get(["notifications"], (result) => {
let currentNotification = json;
let notificationArray = result.notifications;
currentNotification.date = new Date().toISOString();
currentNotification.url = url;
notificationArray.push(json);
chrome.storage.sync.set({"notifications": notificationArray}, ()=>{});
});
}