-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
46 lines (39 loc) · 1.06 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
// add global style
function addStyles() {
var styles = `.visible-ad {
border: 1px solid blue;
padding: 1px;
}`;
var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = styles;
document.getElementsByTagName('head')[0].appendChild(style);
}
// toggler functions
function showAdBorder() {
var ads = Array.from(document.getElementsByClassName('ads-ad'));
ads.map(function(e) { e.classList.add('visible-ad') });
}
function removeAdBorder() {
var ads = Array.from(document.getElementsByClassName('ads-ad'));
ads.map(function(e) { e.classList.remove('visible-ad')});
}
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.command === 'init') {
showAdBorder();
} else {
removeAdBorder();
}
sendResponse({ result: 'OK' });
})
//on init perform based on chrome stroage value
window.onload=function(){
addStyles();
chrome.storage.sync.get('hide', function(data) {
if(data.hide){
showAdBorder();
}else{
removeAdBorder();
}
});
}