YouTube Preview Unmute

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

目前為 2025-02-15 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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.0
// @match               *://*.youtube.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 = JSON.parse(JSON.parse(localStorage.getItem('yt-player-volume')).data);
            if (ytVolumeSetting.muted !== true) {
                event.detail?.unMute();
            }
        } catch (error) {
            throw ("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);
})();