-
Notifications
You must be signed in to change notification settings - Fork 7
/
content.js
61 lines (48 loc) · 1.4 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
const maxPing = 5;
const waitBetweenPings = 100; //in milliseconds
chrome.storage.local.get(['hideFeed'], (res) => {
if (res.hideFeed == undefined) {
chrome.storage.local.set({ 'hideFeed': true });
removeFeed();
}
});
function removeFeed() {
if (window.location.href.includes("linkedin.com/feed/")) {
if (document.getElementsByTagName("main")) {
if (document.getElementsByTagName("main")[0]) {
document.getElementsByTagName("main")[0].remove();
}
}
}
}
/**
* For some odd reason, the news seem to load much slower than the feed. Therefore, multiple attempts
* on removing the news is necessary.
*/
async function attemptToRemoveElement(elementName) {
if (window.location.href.includes("linkedin.com/feed/")) {
let ping = 0;
let removed = false;
async function wait(ms) {
return new Promise(resolve => {
setTimeout(() => {
if (document.getElementById(elementName)) {
document.getElementById(elementName).remove();
removed = true;
}
ping = ping + 1;
resolve();
}, ms);
});
}
while (!removed && ping < maxPing) {
await wait(waitBetweenPings);
}
}
}
setInterval(() => {
chrome.storage.local.get(['hideFeed', 'hideNews'], (res) => {
if (res.hideFeed) removeFeed();
if (res.hideNews) attemptToRemoveElement("feed-news-module");
});
}, 500);