forked from yakkomajuri/linkedin-adblocker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.js
More file actions
47 lines (39 loc) · 1.6 KB
/
extension.js
File metadata and controls
47 lines (39 loc) · 1.6 KB
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
/*
This event triggers when the browser has committed to loading a webpage.
As opposed to e.g. webNavigation.onCompleted, this will start to run early
so that we can begin to remove ads as soon as possible.
*/
chrome.webNavigation.onCommitted.addListener(function (tab) {
// Prevents script from running when other frames load
if (tab.frameId == 0) {
chrome.tabs.query({ active: true, lastFocusedWindow: true }, tabs => {
// Get the URL of the webpage
let url = tabs[0].url;
// Remove unnecessary protocol definitions and www subdomain from the URL
let parsedUrl = url.replace("https://", "")
.replace("http://", "")
.replace("www.", "")
// Remove path and queries e.g. linkedin.com/feed or linkedin.com?query=value
// We only want the base domain
let domain = parsedUrl.slice(0, parsedUrl.indexOf('/') == -1 ? parsedUrl.length : parsedUrl.indexOf('/'))
.slice(0, parsedUrl.indexOf('?') == -1 ? parsedUrl.length : parsedUrl.indexOf('?'));
try {
if (domain.length < 1 || domain === null || domain === undefined) {
return;
} else if (domain == "linkedin.com") {
runLinkedinScript();
return;
}
} catch (err) {
throw err;
}
});
}
});
function runLinkedinScript() {
// Inject script from file into the webpage
chrome.tabs.executeScript({
file: 'linkedin.js'
});
return true;
}