-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.js
More file actions
46 lines (40 loc) · 1.46 KB
/
options.js
File metadata and controls
46 lines (40 loc) · 1.46 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
const rulesTextarea = document.getElementById('rules');
const saveButton = document.getElementById('save');
const statusDiv = document.getElementById('status');
const minWidthCheck = document.getElementById('minWidthCheck');
const minWidthValue = document.getElementById('minWidthValue');
// Load saved options and display them
function restoreOptions() {
chrome.storage.sync.get({
autoSplitRules: [],
minWidthEnabled: false,
minWidthValue: 1200
}, (items) => {
rulesTextarea.value = items.autoSplitRules.join('\n');
minWidthCheck.checked = items.minWidthEnabled;
minWidthValue.value = items.minWidthValue;
minWidthValue.disabled = !items.minWidthEnabled;
});
}
// Save the options to chrome.storage.sync
function saveOptions() {
const rules = rulesTextarea.value.split('\n').filter(rule => rule.trim() !== '');
const minWidthEnabled = minWidthCheck.checked;
const widthValue = parseInt(minWidthValue.value, 10);
chrome.storage.sync.set({
autoSplitRules: rules,
minWidthEnabled: minWidthEnabled,
minWidthValue: widthValue
}, () => {
// Update status to let user know options were saved.
statusDiv.textContent = 'Options saved.';
setTimeout(() => {
statusDiv.textContent = '';
}, 1500);
});
}
document.addEventListener('DOMContentLoaded', restoreOptions);
saveButton.addEventListener('click', saveOptions);
minWidthCheck.addEventListener('change', () => {
minWidthValue.disabled = !minWidthCheck.checked;
});