YouTube Automix Cleaner

Remove Automix/autoplay junk from YouTube video URLs, keep real playlists intact.

Version au 11/06/2025. Voir la dernière version.

// ==UserScript==
// @name         YouTube Automix Cleaner
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Remove Automix/autoplay junk from YouTube video URLs, keep real playlists intact.
// @author       bloxy
// @match        *://www.youtube.com/watch*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

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

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

        if (isAutomixPlaylist(url)) {
            const paramsToRemove = ['list', 'index', 'start_radio'];
            for (const param of paramsToRemove) {
                if (url.searchParams.has(param)) {
                    url.searchParams.delete(param);
                    changed = true;
                }
            }

            if (changed) {
                window.history.replaceState({}, '', url.toString());
            }
        }
    }

    // Run once on initial load
    cleanURL();

    // Hook into YouTube's navigation
    const observeNavigation = () => {
        const observer = new MutationObserver(() => {
            cleanURL();
        });

        observer.observe(document.body, { childList: true, subtree: true });
    };

    window.addEventListener('yt-navigate-finish', cleanURL);
    observeNavigation();

    // Also patch both pushState and replaceState
    const patchHistory = (fnName) => {
        const original = history[fnName];
        history[fnName] = function() {
            original.apply(this, arguments);
            setTimeout(cleanURL, 100);
        };
    };

    patchHistory('pushState');
    patchHistory('replaceState');
})();