-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlegito.js
66 lines (55 loc) · 1.82 KB
/
legito.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
let productionDomains = [
'www.legito.cz',
'www.legito.com',
'legito.com',
'legito.cz',
];
chrome.runtime.onInstalled.addListener(() => {
chrome.storage.sync.set({productionDomains});
console.log('Setting default production domains');
});
//Change tab events
chrome.tabs.onUpdated.addListener(function (activeInfo) {
chrome.storage.sync.get("productionDomains", ({productionDomains}) => {
chrome.tabs.query({active: true, currentWindow: true}, ([currentTab]) => {
if (currentTab.url) {
var url = new URL(currentTab.url)
var domain = url.hostname
if (productionDomains.includes(domain)) {
chrome.scripting.executeScript({
target: {tabId: currentTab.id},
function: productionWarning,
});
} else {
chrome.scripting.executeScript({
target: {tabId: currentTab.id},
function: removeProductionWarning,
});
}
}
})
})
});
function removeProductionWarning() {
let exist = document.getElementById('warning-text-legito');
if (!exist) {
return;
}
exist.remove();
}
function productionWarning() {
let exist = document.getElementById('warning-text-legito');
if (exist) {
return;
}
let warningDiv = document.createElement('div');
warningDiv.id = 'warning-text-legito';
warningDiv.style.background = 'red';
warningDiv.style.color = 'white';
warningDiv.style.textAlign = 'center';
let h1 = document.createElement('h1');
let content = document.createTextNode('PRODUKCE POZOR');
h1.appendChild(content);
warningDiv.append(h1);
document.body.prepend(warningDiv);
}