Reddit Alwayshello Random

Leverages the alwayshello API used by redditrand.com to redirect to a random subreddit.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Reddit Alwayshello Random
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Leverages the alwayshello API used by redditrand.com to redirect to a random subreddit.
// @author       PXA
// @match        *://*.reddit.com/*
// @grant        GM.xmlHttpRequest
// @run-at       document-idle
// @connect      api.alwayshello.com
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    async function goRandom(link) {
        const nsfw = link.target.text.toLowerCase().includes("nsfw") ? 1 : 0;
        const r = await GM.xmlHttpRequest({ url: `https://api.alwayshello.com/reddit-runner/rand?nsfw=${nsfw}` }).catch(e => console.error(e));
        window.location.href = `${window.location.origin}${JSON.parse(r.responseText).url}`;
    }

    const anchors = document.querySelectorAll('a.subbarlink');
    for (let i = 0; i < anchors.length; i++) {
        if (['/r/random/', '/r/randnsfw/'].includes(anchors[i].attributes.href.value)) {
            anchors[i].onclick = goRandom;
            anchors[i].href = "#";
        }
    }

})();