forked from Sulagna-Dutta-Roy/GGExtensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
27 lines (23 loc) · 909 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
// background.js
// Listen for changes to bookmarks and update stored bookmarks
chrome.bookmarks.onCreated.addListener(updateStoredBookmarks);
chrome.bookmarks.onRemoved.addListener(updateStoredBookmarks);
chrome.bookmarks.onChanged.addListener(updateStoredBookmarks);
// Sync bookmarks across devices using Chrome Storage API
function syncBookmarks() {
chrome.bookmarks.getTree(function(bookmarkTreeNodes) {
chrome.storage.sync.set({ 'bookmarks': bookmarkTreeNodes }, function() {
console.log('Bookmarks synced successfully.');
});
});
}
// Update stored bookmarks when changes occur
function updateStoredBookmarks() {
syncBookmarks();
}
// Initialize bookmark syncing on extension install or update
chrome.runtime.onInstalled.addListener(function(details) {
if (details.reason === 'install' || details.reason === 'update') {
syncBookmarks();
}
});