Raw Source
nascent / Epidemic Sound Auto Download Redirect

// ==UserScript==
// @name         Epidemic Sound Auto Download Redirect
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Replaces Epidemic Sound's download button with a redirect & auto-submits on StepToDown.
// @author       You
// @updateURL https://openuserjs.org/meta/nascent/Epidemic_Sound_Auto_Download_Redirect_(with_Tooltip).meta.js
// @downloadURL https://openuserjs.org/install/nascent/Epidemic_Sound_Auto_Download_Redirect_(with_Tooltip).user.js
// @copyright 2025, nascent (https://openuserjs.org/users/nascent)
// @license MIT
// @match        https://www.epidemicsound.com/track/*
// @match        https://steptodown.com/epidemic-sound-downloader/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to modify the download button on Epidemic Sound
    function modifyDownloadButton() {
        const downloadButton = document.querySelector('button[aria-label="Download"]');
        if (downloadButton) {
            const trackUrl = window.location.href;
            const downloadUrl = `https://steptodown.com/epidemic-sound-downloader/?url=${encodeURIComponent(trackUrl)}`;

            // Keep tooltip attributes intact
            downloadButton.setAttribute("data-hide-tooltip", "false");
            downloadButton.setAttribute("aria-label", "Download via StepToDown");

            // Remove previous event listeners (clone approach)
            const newButton = downloadButton.cloneNode(true);

            newButton.addEventListener("click", (event) => {
                event.preventDefault();
                window.location.href = downloadUrl; // Redirect instantly
            });

            // Replace the old button with the modified one
            downloadButton.replaceWith(newButton);
        }
    }

    // Function to auto-fill the input on StepToDown and submit the form
    function autoFillStepToDownForm() {
        const urlParams = new URLSearchParams(window.location.search);
        const epidemicUrl = urlParams.get('url');

        if (epidemicUrl) {
            const inputBox = document.querySelector('form input[name="url"]');
            const submitButton = document.querySelector('form button');

            if (inputBox && submitButton) {
                inputBox.value = epidemicUrl; // Auto-fill the input
                setTimeout(() => {
                    submitButton.click(); // Auto-submit
                }, 500); // Slight delay to ensure form loads properly
            }
        }
    }

    // Run based on the current site
    if (window.location.hostname.includes("epidemicsound.com")) {
        // Modify Epidemic Sound Download Button
        const observer = new MutationObserver(() => {
            if (document.querySelector('button[aria-label="Download"]')) {
                modifyDownloadButton();
                observer.disconnect(); // Stop observing once modified
            }
        });
        observer.observe(document.body, { childList: true, subtree: true });
    } else if (window.location.hostname.includes("steptodown.com")) {
        // Auto-fill and submit on StepToDown
        window.addEventListener("load", autoFillStepToDownForm);
    }

})();