Greasy Fork

Greasy Fork is available in English.

YouTubeAdSolutions

Combines bass boost, 1000% volume, intelligent ad-block speedup, and Shorts support.

当前为 2026-01-04 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         YouTubeAdSolutions
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Combines bass boost, 1000% volume, intelligent ad-block speedup, and Shorts support.
// @author       Pascal
// @match        https://www.youtube.com/*
// @icon         https://www.youtube.com/s/desktop/ee47b5e0/img/logos/favicon_144x144.png
// @grant        none
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // --- SETTINGS ---
    const SETTINGS = {
        startDelayMs: 2000,
        fastSpeed: 15,
        turboSpeedShort: 2.0,
        checkInterval: 100,
        logoColor: "#00FFCC"
    };

    let audioCtx, source, gainNode, bassFilter;
    let isAudioInited = false;
    let isAdActive = false;
    let adStartedAt = 0;

    const watchSliderClassname = 'custom-watch-volume-slider';
    const shortsSliderClassname = 'custom-shorts-volume-slider';

    // --- AUDIO ENGINE ---
    function initAudio() {
        const video = document.querySelector('video');
        if (!video || isAudioInited) return;
        try {
            audioCtx = new (window.AudioContext || window.webkitAudioContext)();
            source = audioCtx.createMediaElementSource(video);
            gainNode = audioCtx.createGain();
            bassFilter = audioCtx.createBiquadFilter();
            bassFilter.type = "lowshelf";
            bassFilter.frequency.value = 150;

            source.connect(bassFilter);
            bassFilter.connect(gainNode);
            gainNode.connect(audioCtx.destination);
            isAudioInited = true;
        } catch (e) { console.error("Audio Init Error", e); }
    }

    // --- ADS & LOGO ---
    function handleAds() {
        const video = document.querySelector('video');
        const ad = document.querySelector('.ad-showing, .ad-interrupting');

        if (video && ad) {
            if (!isAdActive) {
                isAdActive = true;
                adStartedAt = Date.now();
            }
            video.muted = true;
            const timeElapsed = Date.now() - adStartedAt;
            const timeLeft = video.duration - video.currentTime;

            if (video.duration < 10) {
                video.playbackRate = SETTINGS.turboSpeedShort;
            } else {
                if (timeElapsed < SETTINGS.startDelayMs) {
                    video.playbackRate = 1.0;
                } else if (timeLeft > 5.0) {
                    video.playbackRate = SETTINGS.fastSpeed;
                } else {
                    video.playbackRate = 1.0;
                }
            }
            const skipBtn = document.querySelector('.ytp-ad-skip-button, .ytp-ad-skip-button-modern, .ytp-skip-ad-button');
            if (skipBtn) skipBtn.click();
        } else if (video && isAdActive) {
            isAdActive = false;
            video.playbackRate = 1.0;
            video.muted = false;
        }

        const logo = document.querySelector('ytd-logo svg, a#logo svg');
        if (logo) logo.style.fill = SETTINGS.logoColor;

        const overlay = document.querySelector('ytd-enforcement-message-view-model');
        if (overlay) { overlay.remove(); document.body.style.overflow = "auto"; }
    }

    // --- SLIDER SETUP (NORMAL WATCH) ---
    function setupWatchSliders() {
        const videoPlayer = document.querySelector('#movie_player.html5-video-player');
        const ytLeftControls = document.querySelector('.ytp-left-controls');
        if (!videoPlayer || !ytLeftControls || document.querySelector('.' + watchSliderClassname)) return;

        const customVideoVolume = localStorage.getItem('custom-player-volume') ?? 0.4;
        videoPlayer.setVolume((customVideoVolume ** 2) * 100);

        // 1. RED SLIDER (Volume)
        const $origSlider = document.createElement('input');
        $origSlider.className = watchSliderClassname;
        $origSlider.type = 'range';
        $origSlider.min = '0.09'; $origSlider.max = '1'; $origSlider.step = '0.005';
        $origSlider.value = customVideoVolume;
        $origSlider.style.width = '10vw';
        $origSlider.style.height = '43px';
        $origSlider.style.accentColor = 'red';
        $origSlider.style.marginLeft = '15px';
        $origSlider.style.cursor = 'pointer';

        $origSlider.oninput = () => videoPlayer.setVolume(($origSlider.value ** 2) * 100);
        $origSlider.onchange = () => localStorage.setItem('custom-player-volume', $origSlider.value);

        // 2. YELLOW SLIDER (Booster)
        const $boostSlider = document.createElement('input');
        $boostSlider.type = 'range';
        $boostSlider.min = '1'; $boostSlider.max = '10'; $boostSlider.step = '0.1'; $boostSlider.value = '1';
        $boostSlider.style.width = '15vw';
        $boostSlider.style.accentColor = 'yellow';
        $boostSlider.style.marginLeft = '20px';
        $boostSlider.title = "Amplifier (1000%)";
        $boostSlider.oninput = () => { initAudio(); if (gainNode) gainNode.gain.value = $boostSlider.value; };

        // 3. ORANGE SLIDER (Bass)
        const $bassSlider = document.createElement('input');
        $bassSlider.type = 'range';
        $bassSlider.min = '0'; $bassSlider.max = '30'; $bassSlider.step = '1'; $bassSlider.value = '0';
        $bassSlider.style.width = '12vw';
        $bassSlider.style.accentColor = 'orange';
        $bassSlider.style.marginLeft = '20px';
        $bassSlider.title = "Bass Boost";
        $bassSlider.oninput = () => { initAudio(); if (bassFilter) bassFilter.gain.value = $bassSlider.value; };

        ytLeftControls.appendChild($origSlider);
        ytLeftControls.appendChild($boostSlider);
        ytLeftControls.appendChild($bassSlider);
    }

    // --- SLIDER SETUP (SHORTS) ---
    function setupShortsSlider() {
        const videoPlayer = document.querySelector('#shorts-player.html5-video-player');
        if (!videoPlayer || document.querySelector('.' + shortsSliderClassname)) return;

        const customVideoVolume = localStorage.getItem('custom-player-volume') ?? 0.4;
        videoPlayer.setVolume((customVideoVolume ** 2) * 100);

        const $shortsSlider = document.createElement('input');
        $shortsSlider.className = shortsSliderClassname;
        $shortsSlider.type = 'range';
        $shortsSlider.min = '0.09'; $shortsSlider.max = '1'; $shortsSlider.step = '0.005';
        $shortsSlider.value = customVideoVolume;

        $shortsSlider.style.width = '40vh';
        $shortsSlider.style.position = 'fixed';
        $shortsSlider.style.right = '-100px';
        $shortsSlider.style.bottom = '40vh';
        $shortsSlider.style.transform = 'rotateZ(-90deg)';
        $shortsSlider.style.accentColor = 'red';
        $shortsSlider.style.zIndex = '9999';

        $shortsSlider.oninput = () => { videoPlayer.setVolume(($shortsSlider.value ** 2) * 100); };
        $shortsSlider.onchange = () => { localStorage.setItem('custom-player-volume', $shortsSlider.value); };

        document.body.appendChild($shortsSlider);
    }

    // --- INITIALIZATION ---
    setInterval(handleAds, SETTINGS.checkInterval);

    const mainObserver = new MutationObserver(() => {
        const isWatch = window.location.pathname.startsWith('/watch');
        const isShorts = window.location.pathname.startsWith('/shorts');
        const $sSlider = document.querySelector('.' + shortsSliderClassname);

        if (isWatch) setupWatchSliders();
        if (isShorts) {
            setupShortsSlider();
            if ($sSlider) $sSlider.style.visibility = 'visible';
        } else if ($sSlider) {
            $sSlider.style.visibility = 'hidden';
        }
    });

    const checkBody = setInterval(() => {
        if (document.body) {
            clearInterval(checkBody);
            mainObserver.observe(document.body, { childList: true, subtree: true });

            const style = document.createElement('style');
            style.textContent = `ytd-ad-slot-renderer, #masthead-ad, .ytp-ad-overlay-container, #player-ads { display: none !important; }`;
            document.head.appendChild(style);
        }
    }, 100);
})();