您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
2023/10/26
// ==UserScript== // @name Youtube视频广告去除 // @namespace https://github.com/jin-lin0/tampermonkey-demo // @version 0.2 // @description 2023/10/26 // @author logyes // @license MPL-2.0 // @match *://*.youtube.com/* // @icon https://www.google.com/s2/favicons?sz=64&domain=greasyfork.org // @grant GM_addStyle // ==/UserScript== (function () { "use strict"; GM_addStyle("#player-ads{display:none !important}"); GM_addStyle("ytd-ad-slot-renderer{display:none !important}"); GM_addStyle( "ytd-rich-item-renderer:has(ytd-ad-slot-renderer){display:none !important}" ); let observer = null; const hasQueryParamV = () => { return /[\?&]v=/.test(location.href); }; const skipAd = () => { let video = document.querySelector(`.ad-showing video`); let skipButton = document.querySelector(`.ytp-ad-skip-button`); if (skipButton) { skipButton.click(); } if (video) { video.currentTime = video.duration; } return; }; const startObserve = () => { const target = document.querySelector(`.video-ads.ytp-ad-module`); if (!target) { observer = null; return; } observer = new MutationObserver(skipAd); observer.observe(target, { childList: true, subtree: true, }); return observer; }; setInterval(() => { if (hasQueryParamV()) { if (!observer) { startObserve(); } } else { if (observer) { observer.disconnect(); observer = null; } } }, 200); })();