YouTube Preview Unmute

This script automatically unmutes the video previews on the YouTube homepage when you hover over them.

// ==UserScript==
// @name                YouTube Preview Unmute
// @icon                https://www.youtube.com/img/favicon_48.png
// @author              ElectroKnight22
// @namespace           electroknight22_youtube_preview_unmute_namespace
// @version             1.0.2
// @match               *://*.youtube.com/*
// @match               *://www.youtube-nocookie.com/*
// @license             MIT
// @description         This script automatically unmutes the video previews on the YouTube homepage when you hover over them.
// ==/UserScript==

/*jshint esversion: 11 */

(function () {
    "use strict";

    let pageType = '';

    function unmuteVideo(event) {
        if (pageType !== 'browse') return;
        try {
            const ytVolumeSetting = localStorage.getItem('yt-player-volume');
            let muted = false;
            try {
                muted = JSON.parse(JSON.parse(ytVolumeSetting)?.data)?.muted == true;
            } catch {
                console.warn('Volume setting not found in localStorage.');
            }

            if (!muted && event.target.id === 'inline-player') {
                event.target?.player_?.unMute();
            }
        } catch (error) {
            console.error ("Failed to unmute video due to this error. Error: " + error);
        }
    }

    window.addEventListener('yt-page-data-fetched', (event) => {
        pageType = event.detail?.pageData?.page;
    }, true);
    window.addEventListener('yt-player-updated', (event) => {
        unmuteVideo(event);
    }, true);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址