-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinject.js
38 lines (34 loc) · 1.27 KB
/
inject.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
// script to remove the "what's happening" section on Twitter
(function() {
// https://stackoverflow.com/questions/18432072/x-function-is-not-defined-inside-a-chrome-extension-content-script
function xPath(xpathToExecute) {
const result = [];
const nodesSnapshot = document.evaluate(xpathToExecute, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
for (let i = 0; i < nodesSnapshot.snapshotLength; i++) {
result.push(nodesSnapshot.snapshotItem(i));
}
return result;
}
function removeWhatsHappening() {
const maxAttempts = 5;
const interval = 500;
let attempts = 0;
let t = setInterval(() => {
if (attempts > maxAttempts) {
console.error('Could not remove element in', maxAttempts, 'attempts');
clearInterval(t);
}
try {
const target = xPath(`//span[text()='What’s happening']`)[0].parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement;
const parent = target.parentElement;
parent.removeChild(target);
clearInterval(t);
} catch (e) {}
attempts++;
}, interval);
}
// very hacky, but just run this every second.
setInterval(() => {
removeWhatsHappening();
}, 1000);
})();