-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
27 lines (22 loc) · 881 Bytes
/
background.js
File metadata and controls
27 lines (22 loc) · 881 Bytes
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
// Initialize wallpapers and index on install
chrome.runtime.onInstalled.addListener(() => {
chrome.storage.local.get(['wallpapers', 'currentIndex'], (data) => {
if (!data.wallpapers) {
chrome.storage.local.set({ wallpapers: [], currentIndex: 0 });
}
});
// Set up alarm for wallpaper rotation every 5 minutes
chrome.alarms.create('wallpaperRotate', { periodInMinutes: 5 });
});
// Listen for alarm to rotate wallpaper index
chrome.alarms.onAlarm.addListener((alarm) => {
if (alarm.name === 'wallpaperRotate') {
chrome.storage.local.get(['wallpapers', 'currentIndex'], (data) => {
const wallpapers = data.wallpapers || [];
let currentIndex = data.currentIndex || 0;
if (wallpapers.length === 0) return;
currentIndex = (currentIndex + 1) % wallpapers.length;
chrome.storage.local.set({ currentIndex });
});
}
});