-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent-script.js
61 lines (47 loc) · 1.41 KB
/
content-script.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
window.onload = async () => {
const src = chrome.runtime.getURL("modules/counter.js");
const counterScript = await import(src);
const { App } = counterScript;
App.setTags();
const allInputs = document.body.querySelectorAll("input");
let current_theme = (await chrome.storage.local.get(["theme"]))["theme"];
const initVisible = (await chrome.storage.local.get(["active"]))["active"];
const app = new App(allInputs, current_theme);
if (initVisible === 'false') {
app.remove();
}
chrome.runtime.onMessage.addListener(({ theme, active }) => {
if (theme !== undefined) {
current_theme = theme;
app.update(current_theme);
}
if (active === 'false') {
app.remove();
} else if (active === 'true') {
app.update(current_theme)
}
});
MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
const observer = new MutationObserver(function (mutations, observer) {
// fired when a mutation occurs
if (active === 'false') return;
app.remove();
app.init(current_theme);
// ...
});
allInputs.forEach((elem) => {
if (
elem.type === "text" ||
elem.type === "password" ||
elem.type === "number" ||
elem.type === "search" ||
elem.type === "email"
) {
observer.observe(elem, {
subtree: true,
attributes: true,
childList: true,
});
}
});
};