Enhanced youtube

Automatically skips YouTube ads, mutes them, disables autoplay, removes end screens, expands descriptions, and hides Up Next.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Enhanced youtube
// @namespace    Index
// @version      1.0
// @description  Automatically skips YouTube ads, mutes them, disables autoplay, removes end screens, expands descriptions, and hides Up Next.
// @author       Joel
// @match        *://www.youtube.com/*
// @license      MIT
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    function skipAd() {
        const skipButton = document.querySelector('.ytp-ad-skip-button');
        if (skipButton) {
            skipButton.click();
            console.log('Skipped an ad.');
        }
    }

    function muteAd() {
        const isAdPlaying = document.querySelector('.ad-showing');
        const video = document.querySelector('video');
        if (isAdPlaying && video && !video.muted) {
            video.muted = true;
            console.log('Muted video during ad.');
        } else if (!isAdPlaying && video && video.muted) {
            video.muted = false;
            console.log('Unmuted video after ad.');
        }
    }

    function removeEndScreens() {
        const elements = document.querySelectorAll('.ytp-ce-element');
        elements.forEach(el => el.remove());
    }

    function disableAutoplayToggle() {
        const autoplayButton = document.querySelector('.ytp-autonav-toggle-button[aria-checked="true"]');
        if (autoplayButton) {
            autoplayButton.click();
            console.log('Autoplay disabled.');
        }
    }

    function expandDescription() {
        const moreButton = document.querySelector('#expand .more-button');
        if (moreButton) {
            moreButton.click();
            console.log('Expanded description.');
        }
    }

    function hideUpNextSection() {
        const upNext = document.getElementById('related');
        if (upNext) {
            upNext.style.display = 'none';
            console.log('Hiding Up Next section.');
        }
    }

    function applyEnhancements() {
        skipAd();
        muteAd();
        removeEndScreens();
        disableAutoplayToggle();
        expandDescription();
        hideUpNextSection();
    }

    setInterval(applyEnhancements, 1000);
})();