-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsettings.js
38 lines (27 loc) · 987 Bytes
/
settings.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
document.addEventListener('DOMContentLoaded', function() {
var form = document.getElementById('settingsForm');
var rulesInput = document.getElementById('rules');
function loadRules() {
// Load the rules from storage and set the input value
chrome.storage.sync.get('rules', function(data) {
if (data.rules) {
rulesInput.value = data.rules.join('\n');
}
});
}
// Load the rules when the page is loaded
loadRules();
// Save the rules when the form is submitted
form.addEventListener('submit', function(e) {
e.preventDefault();
var rules = rulesInput.value.split('\n').map(function(rule) {
return rule.trim();
}).filter(function(rule) {
return rule.length > 0;
});
chrome.storage.sync.set({rules: rules}, function() {
// Reload the rules after they are saved
loadRules();
});
});
});