-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
33 lines (29 loc) · 1.11 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
let previousWatchlist = [];
// Listen for messages from content scripts
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === "updateWatchlist") {
const currentWatchlist = message.items;
// Find changes
const changes = currentWatchlist.filter(item =>
!previousWatchlist.some(prev => prev.title === item.title && prev.isPaid === item.isPaid)
);
console.log("changes=", changes);
// Notify about changes
if (changes.length > 0) {
changes.forEach(change => {
console.log("change=", change);
/*
chrome.notifications.create({
type: "basic",
iconUrl: "FreeWatch.png",
title: "Watchlist Update",
message: `${change.title} is now ${change.isPaid ? "Paid Content" : "Included with Prime"}`
});
*/
});
}
// Update the watchlist state
previousWatchlist = currentWatchlist;
sendResponse({ success: true });
}
});