-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinject.js
48 lines (29 loc) · 866 Bytes
/
inject.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
function injectCSS() {
const key = `ngcCSSInject__${window.location.hostname}`;
chrome.storage.sync.get([key], function(result) {
const css = result[key];
if (css) {
const elementStyle = document.createElement('style');
elementStyle.setAttribute('id', 'ngc-css-inject');
elementStyle.innerHTML = css;
document.head.appendChild(elementStyle);
}
});
}
function removeExistingCSS() {
const element = document.getElementById('ngc-css-inject');
if (element) {
element.parentNode.removeChild(element);
}
}
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.setCSS === true) {
removeExistingCSS();
injectCSS();
} else if (request.setCSS === false) {
removeExistingCSS();
}
sendResponse({success: true});
});
removeExistingCSS();
injectCSS();