-
Notifications
You must be signed in to change notification settings - Fork 2
/
blacklist.js
34 lines (33 loc) · 1.26 KB
/
blacklist.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
(() => {
// const manifest = chrome.runtime.getManifest();
// document.getElementById("version").textContent = 'v' + manifest.version;
init();
async function init() {
let data = await chrome.storage.local.get(['blocked']);
data = data.blocked ? data.blocked : [];
if(data.length) {
const table = document.querySelector("table tbody");
// https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/template
data.map(row => {
const tr = document.getElementById("row");
const td = tr.content.querySelectorAll("td");
td[0].textContent = row;
const clone = document.importNode(tr.content, true);
clone.querySelector("md-text-button").addEventListener("click", async(e) => {
e.target.closest("tr").remove();
let domains = await chrome.storage.local.get(['blocked']);
domains = domains.blocked ? domains.blocked : [];
chrome.storage.local.set({"blocked": domains.filter(j => j !== row)});
});
table.appendChild(clone);
});
} else {
const empty = document.createElement("div");
empty.classList.add("block", "has-text-centered", "py-6");
empty.textContent = "Empty.";
const root = document.querySelector("#main");
root.innerHTML = '';
root.appendChild(empty);
}
}
})();