-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.js
More file actions
59 lines (50 loc) · 2.32 KB
/
options.js
File metadata and controls
59 lines (50 loc) · 2.32 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
51
52
53
54
55
56
57
58
59
// FFSleep Options JS
const api = (typeof browser !== 'undefined') ? browser : chrome;
document.addEventListener('DOMContentLoaded', async () => {
const autoSleepToggle = document.getElementById('auto-sleep-toggle');
const sleepMinutesInput = document.getElementById('sleep-minutes');
const whitelistTextArea = document.getElementById('whitelist');
const totalSavedSpan = document.getElementById('total-saved');
const resetStatsBtn = document.getElementById('reset-stats');
const statusMsg = document.getElementById('status-msg');
// Load current settings
const { settings } = await api.storage.local.get('settings');
if (settings) {
autoSleepToggle.checked = settings.autoSleepEnabled;
sleepMinutesInput.value = settings.autoSleepMinutes;
whitelistTextArea.value = settings.whitelist.join('\n');
totalSavedSpan.textContent = `${settings.totalMemorySavedMB.toLocaleString()} MB`;
}
// Save functions
async function saveSettings() {
const { settings: current } = await api.storage.local.get('settings');
const newSettings = {
...current,
autoSleepEnabled: autoSleepToggle.checked,
autoSleepMinutes: parseInt(sleepMinutesInput.value, 10) || 30,
whitelist: whitelistTextArea.value.split('\n').map(s => s.trim()).filter(s => s !== '')
};
await api.storage.local.set({ settings: newSettings });
showStatus('Settings saved automatically');
}
function showStatus(text) {
statusMsg.textContent = text;
statusMsg.style.opacity = '1';
setTimeout(() => {
statusMsg.style.opacity = '0';
}, 2000);
}
// Event Listeners
autoSleepToggle.addEventListener('change', saveSettings);
sleepMinutesInput.addEventListener('change', saveSettings);
whitelistTextArea.addEventListener('blur', saveSettings);
resetStatsBtn.addEventListener('click', async () => {
if (confirm('Are you sure you want to reset your memory statistics?')) {
const { settings: current } = await api.storage.local.get('settings');
current.totalMemorySavedMB = 0;
await api.storage.local.set({ settings: current });
totalSavedSpan.textContent = '0 MB';
showStatus('Statistics reset');
}
});
});