Skip to content

Commit 19be4ab

Browse files
committed
revive reddit script
1 parent 813bf74 commit 19be4ab

File tree

3 files changed

+98
-1
lines changed

3 files changed

+98
-1
lines changed

guidestar.org/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
setTimeout(() => {
12
let bar = document.getElementById('signUpModal');
23

34
if (bar) {
@@ -11,4 +12,5 @@ if (bar) bar.remove();
1112

1213
bar = document.getElementById('signUpFooter');
1314

14-
if (bar) bar.remove();
15+
if (bar) bar.remove();
16+
}, 500);

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ switch(location.host) {
2323
case 'google.com':
2424
case 'guidestar.org':
2525
case 'npmjs.com':
26+
case 'reddit.com':
2627
case 'youtube.com':
2728
target = domain;
2829
}

reddit.com/index.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* revival of
3+
* @see https://web.archive.org/web/20131105145427/http://userscripts.org/scripts/review/86301
4+
*/
5+
const styles = `
6+
.arrow.down {min-width:15px;min-height:14px;}
7+
.titText {font-size:smaller;color:darkSlateGray;font-weight:bold}
8+
.favicon {padding-right:17px;font-weight:bold;background-repeat:no-repeat;background-position:right center}
9+
`
10+
const sheet = document.createElement("style")
11+
sheet.type = "text/css";
12+
sheet.innerText = styles;
13+
document.head.appendChild(sheet);
14+
15+
16+
const sections = location.pathname.split(/(?!^)\//);
17+
18+
19+
// Select the node that will be observed for mutations
20+
const targetNode = document.querySelector('.ListingLayout-outerContainer');
21+
22+
// Options for the observer (which mutations to observe)
23+
const config = { attributes: true, childList: true, subtree: true };
24+
25+
const observer = new MutationObserver((mutations, observer) => {
26+
for (const mut of mutations) {
27+
if (mut.type === 'childList') {
28+
run_it();
29+
}
30+
}
31+
});
32+
33+
observer.observe(targetNode, config);
34+
35+
36+
function run_it() {
37+
const loc = sections[0];
38+
if(loc == '/user') [...document.querySelectorAll(".Comment a")].forEach(element => {
39+
const href=element.getAttribute("href");;
40+
if(!href) return;
41+
if(element.title) {
42+
if(href!="/s") { // prevent revealing spoilers
43+
var tit = document.createElement("span");
44+
tit.textContent = "(" + element.title + ")";
45+
tit.className = "titText";
46+
element.parentNode.insertBefore(tit, element);
47+
}
48+
}
49+
if(/\.(?:(jpe?|pn)g|gif|bmp)/.test(href)) {
50+
element.style.color = "blue";
51+
element.style.fontWeight = "bold";
52+
if (href == element.textContent) element.textContent = "{Image}";
53+
} else if(href.indexOf("/")==0) {
54+
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+
}
63+
element.className += " favicon";
64+
element.style.color = "crimson";
65+
element.style.backgroundImage = "url(\"http://www.reddit.com/static/favicon.ico\")";
66+
} else if(/http:\/\/(?:www\.)?youtube\.com/.test(href)) {
67+
element.className += " favicon";
68+
element.style.color = "red";
69+
element.style.backgroundImage = "url(\"http://s.ytimg.com/yt/favicon.ico\")";
70+
if (href == element.textContent) element.textContent = "{Video}";
71+
} else if(/http:\/\/(?:www\.)?facebook\.com/.test(href)) {
72+
if(href.match(/[&?]id=(\d+)/))
73+
element.innerHTML = "Profile: {"+RegExp.$1+"}";
74+
else if(element.pathname.match(/^\/([^?&#]+)/))
75+
element.innerHTML = "Profile: " + RegExp.$1;
76+
element.className += " favicon";
77+
element.style.color = "darkBlue";
78+
element.style.backgroundImage = "url(http://slippyd.com/assets/70/logo.facebook.favicon.s16.png)";
79+
} else if(/http:\/\/(?:www\.)?en\.wikipedia\.org\//.test(href)) {
80+
if(/\/wiki\/([^\/]+)/.test(element.pathname)) {
81+
if(element.textContent == href) element.innerHTML = "";
82+
element.innerHTML += " <small>{" + unescape(RegExp.$1).replace(/_/g, " ") + "}</small>";
83+
}
84+
element.style.color = "black";
85+
element.style.backgroundImage = "url(\"http://en.wikipedia.org/favicon.ico\")";
86+
element.className += " favicon";
87+
} else {
88+
element.className += " favicon";
89+
element.style.color = "darkGreen";
90+
element.style.backgroundImage = "url(\"https://upload.wikimedia.org/wikipedia/commons/0/0f/External-link-ltr-icon_Dark.png\")";
91+
element.style.paddingRight = "11px";
92+
}
93+
});
94+
}

0 commit comments

Comments
 (0)