-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRedditAlwayshelloRandom.user.js
More file actions
47 lines (42 loc) · 1.41 KB
/
Copy pathRedditAlwayshelloRandom.user.js
File metadata and controls
47 lines (42 loc) · 1.41 KB
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
// ==UserScript==
// @name Reddit Alwayshello Random
// @namespace http://tampermonkey.net/
// @version 0.7
// @description Leverages the alwayshello API used by redditrand.com to redirect to a random subreddit.
// @author CheatFreak & PXA
// @match *://*.reddit.com/*
// @grant GM.xmlHttpRequest
// @run-at document-start
// @connect api.alwayshello.com
// ==/UserScript==
(function() {
'use strict';
function goRandom(nsfw) {
GM.xmlHttpRequest({
method: 'GET',
url: `https://api.alwayshello.com/reddit-runner/rand?nsfw=${nsfw}`,
onload: response => {
const result = JSON.parse(response.responseText);
window.location.href = `${window.location.origin}${result.url}`;
}
});
}
function replaceLinks() {
const links = document.querySelectorAll('a');
links.forEach(link => {
if (link.href.includes('/r/random')) {
link.href = 'javascript:void(0)';
link.addEventListener('click', () => goRandom(0));
} else if (link.href.includes('/r/randnsfw')) {
link.href = 'javascript:void(0)';
link.addEventListener('click', () => goRandom(1));
}
});
}
document.addEventListener('DOMContentLoaded', replaceLinks);
if (window.location.pathname.startsWith('/r/random')) {
goRandom(0);
} else if (window.location.pathname.startsWith('/r/randnsfw')) {
goRandom(1);
}
})();