Hardwax Random Button

Adds a button that lets you choose a random Hardwax record

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Hardwax Random Button
// @namespace    http://miseryconfusion.com/
// @version      2025-01-02
// @description  Adds a button that lets you choose a random Hardwax record
// @author       @miseryconfusion
// @match        https://hardwax.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=hardwax.com
// @grant        none
// @license      MIT 
// ==/UserScript==

(function() {
    'use strict';

    function install() {
        const downloadNode = document.querySelector('a[href="/downloads/"]');

        const createLink = () => {
            const link = document.createElement('a');
            link.href = '#';
            link.classList.add('sm');
            link.addEventListener('click', function(e) {
                const number = Math.ceil(Math.random() * 100000);
                window.location = `https://hardwax.com/${number}`;
                e.preventDefault();
                return false;
            });

            const span = document.createElement('span');
            span.classList.add('so');
            span.textContent = '🔄 Random';
            link.appendChild(span)

            return link;
        }

        if (downloadNode) {
            const downloadListItem = downloadNode.parentNode;
            const newListItem = document.createElement('li');
            newListItem.classList.add('sj');
            newListItem.classList.add('sk');

            const link = createLink();

            newListItem.appendChild(link);
            downloadListItem.after(newListItem);
        } else {
            const node404 = document.querySelector('h2.fo');
            if (node404 && node404.textContent === '404 - Not Found') {
                node404.after(createLink());
            }
        }
    }

    if (document.readyState == "complete" || document.readyState == "loaded" || document.readyState == "interactive") {
        install();
    } else {
        install();
    }

})();