-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontent.js
90 lines (76 loc) · 2.09 KB
/
content.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const myStyleElement = document.createElement("style");
const blurr = useBlurr ? "text-shadow: rgba(0, 0, 0, 0.8) -10px 0px 30px !important;" : "";
const cssRuleElement = `span[class*="price"],
span[class="tmm-olp-links"] *
{
color: transparent !important;
${blurr}
user-select: none;
}
`;
let extensionEnabled = true;
const setEnabled = (boolean) => {
extensionEnabled = boolean;
};
const overlay_on = () => {
overlay_set("block");
};
const overlay_off = () => {
overlay_set("none");
};
const overlay_set = (displayStyle) => {
createOverlay();
if (document.getElementById("hide-overlay")) {
document.getElementById("hide-overlay").style.display = displayStyle;
}
};
const hide_price = () => {
document.head.appendChild(myStyleElement);
myStyleElement.sheet.insertRule(cssRuleElement, 0);
};
const show_price = () => {
document.head.appendChild(myStyleElement);
myStyleElement.sheet.deleteRule(0);
};
const createOverlay = () => {
if (!document.getElementById("hide-overlay") && document.childNodes[1]) {
var newDiv = document.createElement("div");
newDiv.setAttribute("id", "hide-overlay");
document.childNodes[1].appendChild(newDiv);
}
};
/**
* Content to Background communication
*/
chrome.runtime.sendMessage({ provide_enabled: "extensionEnabled" }, function (response) {
extensionEnabled = response.enabled;
});
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
setEnabled(request.enabled);
if (request.enabled == true) {
sendResponse({ setting: "enabled" });
createOverlay();
hide_price();
} else {
sendResponse({ setting: "disabled" });
overlay_off();
show_price();
}
});
/**
* Extension hide/show
*/
createOverlay();
document.addEventListener("DOMContentLoaded", (event) => {
if (extensionEnabled) {
hide_price();
overlay_off();
}
});
document.addEventListener("readystatechange", (event) => {
if (extensionEnabled) {
if (document.readyState != "complete") {
overlay_on();
}
}
});