/
clean.js
75 lines (69 loc) · 2.34 KB
/
clean.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
// jshint esversion: 8
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
chrome.storage.sync.get(["okList"], function(result) {
var links = result.okList;
// make sure links is not undefined
if(links) {
// modify links to only obtain ID
links = links.filter(Boolean); // get rid of empty strings
links.forEach(function(account, i, links) {
links[i] = account.substring(0, account.length-1);
links[i] = links[i].substring(links[i].lastIndexOf("/") + 1, links[i].length);
});
} else {
sendResponse({status: 200});
return true;
}
// sort of a brute-force solution to make sure the DOM and deletion async goes before cleaning up
setTimeout(function(){
removeOccludableUpdate(links);
}, 2000);
});
sendResponse({status: 200});
return true;
});
function removeOccludableUpdate(links) {
const toRemove = ["occludable-update","has-occluded-height", "occludable-update-hint", "occludable"];
const re = new RegExp(toRemove.join("|"), "i");
const re2 = new RegExp(links.join("|"), "i");
var cr = document.getElementsByClassName("scaffold-layout__main");
for(const child of cr) {
const c = child.children;
for(const post of c) {
const r = post.children;
for(const del of r) {
// check it contains the classes but DOESNT contain okListed users' posts
if(re.test(del.innerHTML) && !re2.test(del.innerHTML)) {
del.setAttribute("class", "");
del.remove();
}
}
}
}
expandPosts();
}
function expandPosts() {
try {
var coreRail = document.getElementsByClassName("scaffold-layout__main")[0];
var crbuttons = coreRail.getElementsByTagName('button');
// console.log(crbuttons);
for(const btn of crbuttons) {
if(btn.innerHTML.match("see more")) {
btn.parentNode.setAttribute("style", 'max-height: none; display: block;');
btn.remove();
}
}
}
catch (e) {
// move on
}
// var coreRail = document.getElementsByClassName("core-rail")[0];
// var crbuttons = coreRail.getElementsByTagName('button');
// // console.log(crbuttons);
// for(const btn of crbuttons) {
// if(btn.innerHTML.match("see more")) {
// btn.parentNode.setAttribute("style", 'max-height: none; display: block;');
// btn.remove();
// }
// }
}