-
Notifications
You must be signed in to change notification settings - Fork 4
/
options.js
53 lines (45 loc) · 1.89 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
document.addEventListener('DOMContentLoaded', function() {
const websiteInput = document.getElementById('websiteInput');
const addSiteButton = document.getElementById('addSite');
const whitelistElement = document.getElementById('whitelist');
// load and display the whitelisted sites
function loadWhitelist() {
chrome.storage.sync.get(['whitelistedSites'], function(result) {
const whitelistedSites = result.whitelistedSites || [];
whitelistElement.innerHTML = '';
whitelistedSites.forEach((site, index) => {
const li = document.createElement('li');
li.textContent = site;
const removeButton = document.createElement('button');
removeButton.textContent = 'Remove';
removeButton.onclick = () => removeSite(index);
li.appendChild(removeButton);
whitelistElement.appendChild(li);
});
});
}
function addSite() {
const newSite = websiteInput.value.trim();
if (newSite) {
chrome.storage.sync.get(['whitelistedSites'], function(result) {
const whitelistedSites = result.whitelistedSites || [];
whitelistedSites.push(newSite);
chrome.storage.sync.set({ whitelistedSites }, function() {
websiteInput.value = '';
loadWhitelist();
});
});
}
}
function removeSite(index) {
chrome.storage.sync.get(['whitelistedSites'], function(result) {
const whitelistedSites = result.whitelistedSites || [];
whitelistedSites.splice(index, 1);
chrome.storage.sync.set({ whitelistedSites }, function() {
loadWhitelist();
});
});
}
addSiteButton.addEventListener('click', addSite);
loadWhitelist();
});