-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
30 lines (27 loc) · 1.07 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
const currentVersion = '1.0'; // The current version of your extension
function checkForUpdate() {
fetch('https://github.com/ApeDevOne/test-repo/raw/main/update.json')
.then(response => response.json())
.then(data => {
if (data.version !== currentVersion) {
chrome.notifications.create({
type: 'basic',
iconUrl: 'icon.png',
title: 'Update Available',
message: `A new version (${data.version}) is available. Click to update.`,
buttons: [{ title: 'Update Now' }],
}, function(notificationId) {
chrome.notifications.onButtonClicked.addListener(function(buttonIndex) {
if (buttonIndex === 0) {
chrome.tabs.create({ url: data.url });
}
});
});
}
})
.catch(error => console.error('Error checking for updates:', error));
}
// Call this function periodically, e.g., every hour
setInterval(checkForUpdate, 3600000); // 1 hour in milliseconds
// Also call immediately when the extension starts
checkForUpdate();