// ==UserScript== // @name 百度网盘视频播放器-去除赞助广告 // @namespace https://scriptcat.org // @version 1.0 // @description 去除百度网盘视频播放器的爱发电赞助广告框 // @author YourName // @match http*://yun.baidu.com/s/* // @match https://pan.baidu.com/s/* // @match https://pan.baidu.com/wap/home* // @match https://pan.baidu.com/play/video* // @match https://pan.baidu.com/pfile/video* // @match https://pan.baidu.com/pfile/mboxvideo* // @match https://pan.baidu.com/mbox/streampage* // @run-at document-start // @grant none // ==/UserScript== (function() { 'use strict'; // 方法1:直接修改 artPlugins 中的相关函数 function removeSponsorAds() { // 等待 artPlugins 加载 if (typeof window.artPlugins !== 'function') { setTimeout(removeSponsorAds, 100); return; } // 保存原始函数 const originalInit = window.artPlugins; // 重写 artPlugins 函数 window.artPlugins = function(t) { const instance = originalInit(t); // 修改用户插件,移除赞助相关功能 if (instance && instance.plugins) { // 找到用户插件并修改 const plugins = instance.plugins; if (Array.isArray(plugins)) { plugins.forEach((plugin, index) => { if (typeof plugin === 'function') { // 重写插件函数,移除赞助相关代码 const originalPlugin = plugin; plugins[index] = function() { const pluginInstance = originalPlugin.apply(this, arguments); // 如果这是用户插件,移除赞助功能 if (pluginInstance && pluginInstance.name === 'user') { // 重写 show 方法,使其不显示赞助框 if (pluginInstance.show) { const originalShow = pluginInstance.show; pluginInstance.show = function() { console.log('赞助功能已禁用'); // 不执行任何操作,直接返回 }; } } return pluginInstance; }; } }); } } return instance; }; // 复制原始函数的属性 Object.assign(window.artPlugins, originalInit); console.log('百度网盘视频播放器赞助广告已移除'); } // 方法2:拦截赞助框的显示 function interceptSponsorLayer() { const originalAddLayer = Element.prototype.appendChild; Element.prototype.appendChild = function(node) { // 检查是否包含赞助相关内容 if (node.nodeType === 1 && (node.innerHTML && ( node.innerHTML.includes('爱发电') || node.innerHTML.includes('赞助') || node.innerHTML.includes('sponsor') || node.innerHTML.includes('afdian') ))) { console.log('拦截到赞助广告层,已阻止显示'); return node; // 返回节点但不实际添加 } return originalAddLayer.call(this, node); }; } // 方法3:移除赞助相关的DOM元素 function removeSponsorElements() { const observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if (mutation.addedNodes) { mutation.addedNodes.forEach(function(node) { if (node.nodeType === 1) { // 检查是否赞助相关元素 if (node.innerHTML && ( node.innerHTML.includes('爱发电') || node.innerHTML.includes('赞助') || node.innerHTML.includes('sponsor') || node.innerHTML.includes('afdian') || node.innerHTML.includes('order-input') || node.innerHTML.includes('submit-order') )) { node.style.display = 'none'; node.remove(); console.log('已移除赞助相关元素'); } // 检查子元素 const sponsorElements = node.querySelectorAll ? node.querySelectorAll('*') : []; sponsorElements.forEach(function(el) { if (el.innerHTML && ( el.innerHTML.includes('爱发电') || el.innerHTML.includes('赞助') || el.innerHTML.includes('sponsor') || el.innerHTML.includes('afdian') )) { el.style.display = 'none'; el.remove(); } }); } }); } }); }); observer.observe(document.body, { childList: true, subtree: true }); } // 方法4:直接修改 artPlugins 的用户插件代码 function patchUserPlugin() { // 监听 artPlugins 初始化 const originalArtPluginsInit = window.artPlugins?.init; if (originalArtPluginsInit) { window.artPlugins.init = function(options) { return originalArtPluginsInit.call(this, options).then(function(player) { if (player && player.plugins) { // 找到用户插件并禁用赞助功能 const userPlugin = player.plugins.user; if (userPlugin && userPlugin.show) { userPlugin.show = function() { console.log('赞助功能已被屏蔽'); // 不执行任何操作 }; } } return player; }); }; } } // 启动所有去广告方法 window.addEventListener('load', function() { removeSponsorAds(); interceptSponsorLayer(); removeSponsorElements(); patchUserPlugin(); }); // 立即执行部分方法 removeSponsorAds(); interceptSponsorLayer(); })();