-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontent.js
62 lines (51 loc) · 2.05 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
const isBlockedPage = () => {
const {host} = document.location;
if (host.endsWith("irishtimes.com")) {
return document.querySelector('#intercept-modal .meter-modal');
} else if (host.endsWith("independent.ie")) {
return document.querySelector('.datawallProtected');
} else {
return false;
}
};
if (isBlockedPage()) {
// send a message to the background script in case we need to do something with the browser (e.g remove cookies)
// that we can't do in this (content) script
chrome.runtime.sendMessage({
"blockedPageUrl": document.location.href
});
}
const setDisplayProperty = (selector, displayValue) => {
const element = document.querySelector(selector);
if (element) {
element.style.display = displayValue;
}
};
// listen for messages sent by the background script
chrome.runtime.onMessage.addListener(
(request, sender, sendResponse) => {
if (request.blockedPageHostname.endsWith("independent.ie")) {
setDisplayProperty(".datawallProtected", "block");
setDisplayProperty(".w136", "none");
}
const unblockedNotice = document.createElement("div");
unblockedNotice.innerHTML = `This page was unblocked by the
<a href='https://github.com/donalmurtagh/irish-newspapers-unblocker' target='_blank'><u>Irish Newspapers Unblocker</u></a>
Chrome extension <small>(click to close)</small>`;
unblockedNotice.style.cssText = `
color: #333;
position: fixed;
bottom: 0px;
margin: 0;
background-color: #e4f0f5;
padding: 7px;
font-size: 15px;
border: 0 solid #3d7e9a;
border-left-width: 5px;
cursor: pointer`;
unblockedNotice.addEventListener("click", (event) => {
document.body.removeChild(unblockedNotice);
});
document.body.appendChild(unblockedNotice);
}
);