Skip to content

Commit 7e89d77

Browse files
committed
deprecate 08 reddit stuff
1 parent 19be4ab commit 7e89d77

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

reddit.com/index.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,41 @@ sheet.innerText = styles;
1313
document.head.appendChild(sheet);
1414

1515

16-
const sections = location.pathname.split(/(?!^)\//);
17-
18-
1916
// Select the node that will be observed for mutations
2017
const targetNode = document.querySelector('.ListingLayout-outerContainer');
2118

2219
// Options for the observer (which mutations to observe)
2320
const config = { attributes: true, childList: true, subtree: true };
2421

25-
const observer = new MutationObserver((mutations, observer) => {
22+
let runs = 0;
23+
const observer = new MutationObserver((mutations, _) => {
2624
for (const mut of mutations) {
25+
if(mut.target.tagName != 'DIV') {
26+
continue;
27+
}
28+
2729
if (mut.type === 'childList') {
28-
run_it();
30+
run_it(mut.target);
31+
console.log("ran it", ++runs, 'times', mut);
2932
}
3033
}
3134
});
3235

3336
observer.observe(targetNode, config);
3437

3538

36-
function run_it() {
39+
/**
40+
*
41+
*/
42+
function run_it(node = document) {
43+
if(node.marked) {
44+
console.log('avoided extraneous call')
45+
return;
46+
}
47+
48+
const sections = location.pathname.split(/(?!^)\//);
3749
const loc = sections[0];
38-
if(loc == '/user') [...document.querySelectorAll(".Comment a")].forEach(element => {
50+
if(['/user', '/r'].includes(loc)) [...node.querySelectorAll("a")].forEach(element => {
3951
const href=element.getAttribute("href");;
4052
if(!href) return;
4153
if(element.title) {
@@ -52,14 +64,7 @@ if(loc == '/user') [...document.querySelectorAll(".Comment a")].forEach(element
5264
if (href == element.textContent) element.textContent = "{Image}";
5365
} else if(href.indexOf("/")==0) {
5466

55-
} else if(/http:\/\/(?:www\.)?reddit\.com/.test(href)) {
56-
if(/user\/([^\/]+)$/.test(element.textContent)) element.textContent = "{User} " + RegExp.$1;
57-
else if (/\/r\/([^\/]+)\/?(?:comments\/[^\/]+\/(.+))?/.test(href)) {
58-
if(element.textContent == href) element.textContent = "";
59-
var subreddit = RegExp.$1;
60-
if(RegExp.$2)
61-
element.innerHTML = element.textContent + " <small>{" + RegExp.$2.replace(/_/g, " ").replace(/\/.*?$/, "") + " / "+subreddit+"}</small>";
62-
}
67+
} else if(/https?:\/\/(?:www\.)?reddit\.com/.test(href)) {
6368
element.className += " favicon";
6469
element.style.color = "crimson";
6570
element.style.backgroundImage = "url(\"http://www.reddit.com/static/favicon.ico\")";
@@ -84,11 +89,12 @@ if(loc == '/user') [...document.querySelectorAll(".Comment a")].forEach(element
8489
element.style.color = "black";
8590
element.style.backgroundImage = "url(\"http://en.wikipedia.org/favicon.ico\")";
8691
element.className += " favicon";
87-
} else {
92+
} else if(!element.href.startsWith( location.protocol +'//' + location.host)) {
8893
element.className += " favicon";
8994
element.style.color = "darkGreen";
9095
element.style.backgroundImage = "url(\"https://upload.wikimedia.org/wikipedia/commons/0/0f/External-link-ltr-icon_Dark.png\")";
9196
element.style.paddingRight = "11px";
9297
}
9398
});
99+
node.marked = true;
94100
}

0 commit comments

Comments
 (0)