Spaces:
Running
Running
File size: 1,364 Bytes
c9536fa |
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 |
document.getElementById('addSite').addEventListener('click', addSite);
function addSite() {
const site = document.getElementById('site').value.trim();
if (site) {
chrome.storage.sync.get('blockedSites', (data) => {
const blockedSites = new Set(data.blockedSites || []);
blockedSites.add(site);
chrome.storage.sync.set({ blockedSites: Array.from(blockedSites) }, () => {
updateSiteList();
document.getElementById('site').value = '';
});
});
}
}
function removeSite(site) {
chrome.storage.sync.get('blockedSites', (data) => {
const blockedSites = new Set(data.blockedSites || []);
blockedSites.delete(site);
chrome.storage.sync.set({ blockedSites: Array.from(blockedSites) }, updateSiteList);
});
}
function updateSiteList() {
chrome.storage.sync.get('blockedSites', (data) => {
const siteList = document.getElementById('siteList');
siteList.innerHTML = '';
(data.blockedSites || []).forEach((site) => {
const li = document.createElement('li');
li.textContent = site;
const removeButton = document.createElement('button');
removeButton.textContent = 'Remove';
removeButton.onclick = () => removeSite(site);
li.appendChild(removeButton);
siteList.appendChild(li);
});
});
}
updateSiteList(); |