-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
119 lines (108 loc) · 4.48 KB
/
popup.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
function checkBlackList(value) {
if (typeof value === 'object' && value !== null) {
value = value.blackList;
}
if (value === true) {
document.querySelector('#blacklistInput').classList.add('inBlacklist');
document.querySelector('#blacklistInput').classList.remove('notInBlacklist');
} else if (value === false) {
document.querySelector('#blacklistInput').classList.add('notInBlacklist');
document.querySelector('#blacklistInput').classList.remove('inBlacklist');
}
}
const cookieOrNotCookie = data => {
if (data.popupCookieIsDisable === true) {
document.getElementById('cookieIsDisable').innerHTML = chrome.i18n.getMessage("cookiesPopupHasBeenClosed");
} else {
document.getElementById('cookieIsDisable').innerHTML = chrome.i18n.getMessage("noCookiesPopupWasFound");
}
// check blacklist
if (data.isBlacklisted === true) {
checkBlackList(true);
} else {
checkBlackList(false);
}
};
const reportWebsite = data => {
let width = document.getElementById('reportWebsite').offsetWidth;
document.getElementById('reportWebsite').innerHTML = '<div class="loader"><span></span><span></span><span></span></div>';
document.getElementById('reportWebsite').className = 'load';
document.getElementById('reportWebsite').disabled = true;
document.getElementById('reportWebsite').style.minWidth = width + 'px';
// send to hugolevet.fr data.url;
fetch('https://bazar.hugolevet.fr/disablecookies/json/reportWebsite.php?url=' + encodeURIComponent(data.url))
.then(function (response) {
return response.json();
})
.then(function (data) {
// update button
if (data.success === true) {
document.getElementById('reportWebsite').innerHTML = chrome.i18n.getMessage("sent");
document.getElementById('reportWebsite').className = 'sent';
document.getElementById('reportWebsite').disabled = true;
} else {
document.getElementById('reportWebsite').innerHTML = chrome.i18n.getMessage("errorOccured");
document.getElementById('reportWebsite').className = 'error';
document.getElementById('reportWebsite').disabled = false;
}
});
};
function localizeHtmlPage() {
//Localize by replacing __MSG_***__ meta tags
var objects = document.getElementsByTagName('html');
for (var j = 0; j < objects.length; j++) {
// change lang tag in html
objects[j].setAttribute('lang', chrome.i18n.getMessage('@@ui_locale'));
// change other
var obj = objects[j];
var valStrH = obj.innerHTML.toString();
var valNewH = valStrH.replace(/__MSG_(@{0,2}\w+)__/g, function (match, v1) {
return v1 ? chrome.i18n.getMessage(v1) : "";
});
if (valNewH != valStrH) {
obj.innerHTML = valNewH;
}
}
}
window.addEventListener('DOMContentLoaded', () => {
// translate HTML page
localizeHtmlPage();
// get DOM info
// get if cookie popup have been disable
// get if is blacklisted
chrome.tabs.query({
active: true,
currentWindow: true
}, tabs => {
chrome.tabs.sendMessage(tabs[0].id, { from: 'popup', subject: 'DOMInfo' }, cookieOrNotCookie);
});
// bind report website button
document.getElementById('reportWebsite').addEventListener('click', () => {
if (document.getElementById('reportWebsite').disabled === false) {
chrome.tabs.query({
active: true,
currentWindow: true
}, tabs => {
chrome.tabs.sendMessage(tabs[0].id, { from: 'popup', subject: 'getWebsite' }, reportWebsite);
});
}
});
// bind blacklist button
document.getElementById('blacklistInput').addEventListener('click', () => {
if (document.getElementById('blacklistInput').classList.contains('notInBlacklist')) {
chrome.tabs.query({
active: true,
currentWindow: true
}, tabs => {
chrome.tabs.sendMessage(tabs[0].id, { from: 'popup', subject: 'blacklist' }, checkBlackList);
});
} else {
chrome.tabs.query({
active: true,
currentWindow: true
}, tabs => {
chrome.tabs.sendMessage(tabs[0].id, { from: 'popup', subject: 'unblacklist' }, checkBlackList);
});
}
});
});