-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinjector.js
45 lines (37 loc) · 1.23 KB
/
injector.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
(async function(){
const response = await fetch(chrome.runtime.getURL("brands.json"))
const jsonObj = await response.json()
warningImgUrl = chrome.runtime.getURL("images/boycot.jpeg");
injectScript('helpers.js')
setTimeout(() => {
let currURL = location.href;
let script;
let siteName;
if (currURL.includes("jumia.com")){
[script,siteName]=injectScript('jumia-blocker.js')
}
else if (currURL.includes("souq.com")){
[script,siteName]=injectScript('souq-blocker.js')
}
else if (currURL.includes("amazon")){
[script,siteName]=injectScript('amazon-blocker.js')
}
else if (currURL.includes("ebay")){
[script,siteName]=injectScript('ebay-blocker.js')
}
if(script) script.onload = function() {
this.remove();
let event = new CustomEvent(`SendJsonUrl-${siteName}`, {
detail: {jsonObj,warningImgUrl}
})
document.dispatchEvent(event);
};
}, .1);
})()
function injectScript(scriptName){
let siteName = scriptName.split("-")[0];
let scrpt = document.createElement('script');
scrpt.src = chrome.runtime.getURL("blockers/"+scriptName);
(document.head || document.documentElement).appendChild(scrpt);
return [scrpt,siteName]
}