YouTube Automix Cleaner

Remove Automix/autoplay junk from YouTube video URLs and reload cleanly

Tính đến 11-06-2025. Xem phiên bản mới nhất.

// ==UserScript==
// @name         YouTube Automix Cleaner
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Remove Automix/autoplay junk from YouTube video URLs and reload cleanly
// @author       bloxy
// @match        *://www.youtube.com/watch*
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

    // Prevent infinite reload loop
    const CLEAN_FLAG = 'yt_cleaned';

    function isAutomixPlaylist(url) {
        const list = url.searchParams.get('list');
        return list && list.startsWith('RD');
    }

    function cleanURL() {
        const url = new URL(window.location.href);

        if (isAutomixPlaylist(url) && !url.searchParams.has(CLEAN_FLAG)) {
            // Clean up automix junk
            url.searchParams.delete('list');
            url.searchParams.delete('index');
            url.searchParams.delete('start_radio');
            url.searchParams.set(CLEAN_FLAG, '1'); // Mark cleaned

            // Reload with cleaned URL
            window.location.replace(url.toString());
        }
    }

    // Initial clean
    cleanURL();

    // Re-check on YouTube's dynamic navigation
    window.addEventListener('yt-navigate-finish', cleanURL);

    // Patch pushState and replaceState too
    ['pushState', 'replaceState'].forEach(fn => {
        const orig = history[fn];
        history[fn] = function () {
            orig.apply(this, arguments);
            setTimeout(cleanURL, 100);
        };
    });
})();