-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
62 lines (53 loc) · 1.99 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
53
54
55
56
57
58
59
60
61
62
document.addEventListener("DOMContentLoaded", () => {
loadCSSRules();
});
function loadCSSRules() {
chrome.storage.sync.get("cssRules", (data) => {
const cssRules = data.cssRules || [];
const rulesContainer = document.getElementById("rulesContainer");
rulesContainer.innerHTML = "";
cssRules.forEach((rule, index) => {
const ruleElement = document.createElement("div");
ruleElement.className = "rule";
const patternElement = document.createElement("input");
patternElement.type = "text";
patternElement.value = rule.urlPattern;
patternElement.className = "urlPatternInput";
const cssElement = document.createElement("textarea");
cssElement.className = "cssInput";
cssElement.value = rule.css;
const deleteButton = document.createElement("button");
deleteButton.textContent = "Delete";
deleteButton.className = "deleteButton";
deleteButton.addEventListener("click", () => {
deleteCSSRule(index);
});
ruleElement.appendChild(patternElement);
ruleElement.appendChild(cssElement);
ruleElement.appendChild(deleteButton);
rulesContainer.appendChild(ruleElement);
});
});
}
function deleteCSSRule(index) {
chrome.storage.sync.get("cssRules", (data) => {
const cssRules = data.cssRules || [];
cssRules.splice(index, 1);
chrome.storage.sync.set({ cssRules }, loadCSSRules);
});
}
document.getElementById("saveButton").addEventListener("click", () => {
const urlPattern = document.getElementById("urlPattern").value;
const customCSS = document.getElementById("customCSS").value;
if (urlPattern && customCSS) {
chrome.storage.sync.get("cssRules", (data) => {
const cssRules = data.cssRules || [];
cssRules.push({ urlPattern, css: customCSS });
chrome.storage.sync.set({ cssRules }, () => {
loadCSSRules();
document.getElementById("urlPattern").value = "";
document.getElementById("customCSS").value = "";
});
});
}
});