-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinkedin.js
79 lines (66 loc) · 2.53 KB
/
linkedin.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const targetNode = document.getElementById("voyager-feed");
const callback = (mutationList, observer) => {
for (const mutation of mutationList) {
//console.log(`mutation: ${mutation.type}`);
if (mutation.type === "childList") {
if (mutation.target.tagName == "DIV"){
if (mutation.target.classList.contains("ember-view")) {
//console.log(`${mutation.target.tagName}, ${mutation.target.innerText}`);
hideSpanWithText(mutation.target, "Suggested", "suggested");
hideSpanWithText(mutation.target, "Promoted", "promoted");
}
}
// if (mutation.target.tagName === "SPAN") {
// if (mutation.target.innerText === "Promoted" ) {
// console.log(`${mutation.target.tagName}, ${mutation.target.innerText}`);
// let xoxo = mutation.target.closest("div.feed-shared-update-v2");
// //mutation.target.classList.add("promoted");
// if (xoxo != null) {
// xoxo.classList.add("promoted")
// }
// else {
// console.log("Promoted is null");
// }
// }
// if (mutation.target.innerText === "Suggested" ) {
// //console.log(`${mutation.target.tagName}, ${mutation.target.innerText}`);
// let xoxo = mutation.target.closest("div.feed-shared-update-v2");
// if (xoxo != null) {
// xoxo.classList.add("suggested")
// }
// else {
// console.log("Suggested is null");
// }
// }
// }
} else if (mutation.type === "subtree") {
console.log(`The ${mutation.attributeName} attribute was modified.`);
}
}
};
const config = { childList: true, subtree: true };
const observer = new MutationObserver(callback);
observer.observe(targetNode, config);
window.addEventListener("load", (event) => {
hideSpanWithText(document, "Suggested", "suggested");
hideSpanWithText(document, "Promoted", "promoted");
});
function hideSpanWithText(startElement, text, className) {
const xpath = `//span[contains(text(), '${text}')]`;
const spans = document.evaluate(xpath, startElement, null, XPathResult.ANY_TYPE, null);
let allSpans = [];
let thisSpan = spans.iterateNext();
allSpans.push(thisSpan);
while (thisSpan) {
thisSpan = spans.iterateNext();
if (thisSpan != null) {
allSpans.push(thisSpan);
}
}
for (var i = 0; i < allSpans.length; i++) {
let currentSpan = allSpans[i];
if (currentSpan != null){
currentSpan.closest("div.feed-shared-update-v2").classList.add(className);
}
}
}