-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.js
More file actions
50 lines (43 loc) · 1.57 KB
/
settings.js
File metadata and controls
50 lines (43 loc) · 1.57 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
document.addEventListener('DOMContentLoaded', () => {
const input = document.getElementById('input');
const intervalInput = document.getElementById('interval');
const shuffleToggle = document.getElementById('shuffleToggle');
const saveButton = document.getElementById('saveButton');
const status = document.getElementById('status');
let imageUrls = [];
input.addEventListener('change', (e) => {
const files = [...e.target.files];
imageUrls = [];
files.forEach(file => {
if (file.type.startsWith('image/')) {
const url = URL.createObjectURL(file);
imageUrls.push(url);
}
});
status.textContent = `Loaded ${imageUrls.length} images, but not saved yet. Click Save to apply.`;
});
saveButton.addEventListener('click', () => {
if (imageUrls.length === 0) {
status.textContent = "No wallpapers selected.";
return;
}
const intervalVal = parseInt(intervalInput.value, 10);
if (isNaN(intervalVal) || intervalVal < 5) {
status.textContent = "Interval must be a number >= 5 seconds.";
return;
}
chrome.storage.local.set({
wallpapers: imageUrls,
interval: intervalVal,
shuffle: shuffleToggle.checked,
currentIndex: 0
}, () => {
status.textContent = `Saved ${imageUrls.length} wallpapers with interval ${intervalVal} seconds.`;
});
});
// Load saved settings on open
chrome.storage.local.get(['interval', 'shuffle'], (data) => {
if (data.interval) intervalInput.value = data.interval;
if (data.shuffle) shuffleToggle.checked = data.shuffle;
});
});