-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
54 lines (48 loc) · 1.69 KB
/
options.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
document.addEventListener('DOMContentLoaded', async () => {
const result = await browser.storage.local.get('smoothViSettings');
const settings = result.smoothViSettings || { minStep: 100, maxStep: 550 };
const minStepInput = document.getElementById('minStep');
const maxStepInput = document.getElementById('maxStep');
const saveButton = document.getElementById('saveButton');
const statusElement = document.getElementById('status');
// Initialize input values
minStepInput.value = settings.minStep;
maxStepInput.value = settings.maxStep;
const showStatus = (message, successful = true) => {
statusElement.textContent = message;
statusElement.className = successful ? 'success' : 'error';
// Clear status after 3 seconds
setTimeout(() => {
statusElement.textContent = '';
statusElement.className = '';
}, 3000);
};
const saveSettings = async () => {
const minStep = parseInt(minStepInput.value);
const maxStep = parseInt(maxStepInput.value);
if (isNaN(minStep) || isNaN(maxStep)) {
showStatus('Please enter valid numbers', false);
return;
}
if (minStep < 1 || maxStep < 1) {
showStatus('Values must be greater than 0', false);
return;
}
// Broadcast settings to all tabs
const tabs = await browser.tabs.query({});
tabs.forEach(tab => {
browser.tabs.sendMessage(tab.id, {
type: 'smoothViSettingsUpdate',
settings: { minStep, maxStep }
});
});
await browser.storage.local.set({
smoothViSettings: {
minStep: minStep,
maxStep: maxStep
}
});
showStatus('Settings saved');
};
saveButton.addEventListener('click', saveSettings);
});