-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
52 lines (45 loc) · 1.69 KB
/
popup.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
const blockedCompaniesKey = "blockedCompanies";
const addButton = document.getElementById("addButton");
const companyInput = document.getElementById("companyInput");
const companyList = document.getElementById("companyList");
function saveBlockedCompanies(companies) {
chrome.storage.local.set({ [blockedCompaniesKey]: companies });
}
function addCompanyToList(companyName) {
const listItem = document.createElement("li");
listItem.textContent = companyName;
const removeButton = document.createElement("button");
removeButton.textContent = "Remove";
removeButton.addEventListener("click", () => {
listItem.remove();
const blockedCompanies = JSON.parse(localStorage.getItem(blockedCompaniesKey));
const index = blockedCompanies.indexOf(companyName);
blockedCompanies.splice(index, 1);
saveBlockedCompanies(blockedCompanies);
});
listItem.appendChild(removeButton);
companyList.appendChild(listItem);
}
addButton.addEventListener("click", () => {
const companyName = companyInput.value.trim();
if (companyName) {
chrome.storage.local.get(blockedCompaniesKey, (result) => {
const blockedCompanies = result[blockedCompaniesKey] || [];
if (!blockedCompanies.includes(companyName)) {
blockedCompanies.push(companyName);
saveBlockedCompanies(blockedCompanies);
addCompanyToList(companyName);
companyInput.value = "";
}
});
}
});
function init() {
chrome.storage.local.get(blockedCompaniesKey, (result) => {
const blockedCompanies = result[blockedCompaniesKey] || [];
blockedCompanies.forEach((companyName) => {
addCompanyToList(companyName);
});
});
}
document.addEventListener("DOMContentLoaded", init);