您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Block YouTube ads and enhance your viewing experience
当前为
// ==UserScript== // @name Advanced YouTube Ad Blocker // @namespace http://tampermonkey.net/ // @version 1.1 // @description Block YouTube ads and enhance your viewing experience // @author Patrick // @match https://*.youtube.com/* // @grant none // @run-at document-start // ==/UserScript== (function() { 'use strict'; // Function to remove ads from the DOM function removeAds() { // Remove overlay ads const overlayAds = document.querySelectorAll('.ytp-ad-overlay'); overlayAds.forEach(ad => ad.remove()); // Remove pre-roll and mid-roll ads const videoAds = document.querySelectorAll('.videoAdUi'); videoAds.forEach(ad => ad.remove()); // Remove banner ads const bannerAds = document.querySelectorAll('.ytp-ad-text'); bannerAds.forEach(ad => ad.remove()); } // Function to skip ads automatically function skipAds() { const skipButton = document.querySelector('.ytp-ad-skip-button'); if (skipButton) { skipButton.click(); } } // Function to mute and speed up playback during ads function enhancePlayback() { const videoPlayer = document.querySelector('video'); if (videoPlayer) { videoPlayer.muted = true; videoPlayer.playbackRate = 2; } } // Function to inject custom CSS to hide elements function injectCSS() { const style = document.createElement('style'); style.innerHTML = ` .ytp-ad-overlay, .videoAdUi, .ytp-ad-text { display: none !important; } `; document.head.appendChild(style); } // Function to handle ad removal and playback enhancement function handleAdRemoval() { removeAds(); skipAds(); enhancePlayback(); } // Inject custom CSS on page load injectCSS(); // Set interval to periodically remove ads and enhance playback setInterval(handleAdRemoval, 500); // Override fetch to intercept ad-related requests const originalFetch = window.fetch; window.fetch = function(url, ...args) { if (url.includes('/youtubei/v1/player')) { return originalFetch(url, ...args).then(response => { return response.clone().json().then(data => { data.adPlacements = []; return new Response(JSON.stringify(data), { status: response.status, statusText: response.statusText, headers: response.headers }); }); }); } return originalFetch(url, ...args); }; // Override ytInitialPlayerResponse to remove ad placements const originalYtInitialPlayerResponse = window.ytInitialPlayerResponse; window.ytInitialPlayerResponse = { ...originalYtInitialPlayerResponse, adPlacements: [] }; // Override Object.defineProperty to ensure ad placements are removed const originalDefineProperty = Object.defineProperty; Object.defineProperty = function(obj, prop, descriptor) { if (prop === 'ytInitialPlayerResponse') { descriptor.get = function() { return { ...originalYtInitialPlayerResponse, adPlacements: [] }; }; } return originalDefineProperty(obj, prop, descriptor); }; })();