// ==UserScript== // @namespace greasyfork // @name 百度网盘网页旧版去广告(清爽版) // @version 1.0 // @match https://pan.baidu.com/* // @grant GM.addStyle // @grant GM.info // @grant unsafeWindow // @run-at document-body // @description 自动屏蔽百度网盘中几乎所有广告,页面瞬间清爽 // ==/UserScript== (function() { 'use strict'; GM.addStyle(` @import url("https://cdn.bootcdn.net/ajax/libs/bootstrap-icons/1.11.0/font/bootstrap-icons.min.css"); body{max-width:100vw;overflow-x:hidden} #layoutMain{font-size:14px !important} div.file-name{font-family:"Microsoft YaHei UI", monospace !important} .wp-side-options, span.newIcon, span[node-type=find-apps], [node-type=header-union], dd.desc-box>div, img.btn-img-tips, span.user-name, [node-type=header-apps], dd:has(> .dir-card-small, > .dir-share-small, > .dir-apps-small), #ft, iframe, .bd-aside-ad, .module-share-footer, .ads-container, .banner, .recommend, .promotion, .tips-container, .guide-layer, .popup, .feed-card, .activity-entry, .vip-promotion, .third-party, .notice-badge, .task-center, .level-indicator, .growth-guide, .cloud-storage-guide, .album-promotion, .file-activity, .upgrade-guide, .speedup-promotion, .ad-container, #ad-banner, .recommend-list, .activity-banner, .vip-ad, .third-app-entry, .guide-panel, .dir-share-small, .dir-apps-small, .share-right-side-content {display:none !important; visibility:hidden !important;} #init-new{background: none !important} .file-card, .dir-card { box-shadow: none !important; border: 1px solid #eee !important; } .toolbar { border-bottom: 1px solid #eee !important; } .sidebar { width: 180px !important; } `); if ("pan.baidu.com" === location.hostname) { if ("/disk/home" === location.pathname) { const arr = GM.info.version.split(".", 3).map(t => Number.parseInt(t)); if (5 < arr[0] || 3 < arr[1] || 6221 <= arr[2]) { GM.addStyle(` #layoutMain{font-size:14px} div.file-name{font-family:"Microsoft YaHei UI", monospace} .wp-side-options,span.newIcon,span[node-type=find-apps], [node-type=header-union],dd.desc-box>div,img.btn-img-tips, span.user-name,[node-type=header-apps], dd:has(> .dir-card-small, > .dir-share-small, > .dir-apps-small) {display:none !important} `); unsafeWindow.XMLHttpRequest = new Proxy(XMLHttpRequest, { construct: target => { let url; return new Proxy(new target, { set: (target, prop, value) => Reflect.set(target, prop, value), get: (target, prop) => { let value = target[prop]; if ("function" === typeof value) { value = function() { if (prop === "open") { url = arguments[1]; } return Reflect.apply(target[prop], target, arguments); }; } else if ("responseText" === prop && url && url.includes("/adx")) { const d = JSON.parse(value); if (d.hasOwnProperty("list")) { d.list = null; d.error_code = 31402; value = JSON.stringify(d); } } return value; } }); } }); } } else if ("/login" === location.pathname) { localStorage.clear(); } else if ("/disk/main" === location.pathname && location.hash.startsWith("#/index")) { location.replace("/disk/home?stayAtHome=true"); } else if ("/share/init" === location.pathname) { GM.addStyle("#init-new{background: none !important}#ft,iframe{display: none !important}"); } else if (location.pathname.startsWith("/s/")) { GM.addStyle(".bd-aside-ad,.module-share-footer{display: none !important}"); } const observer = new MutationObserver((mutations) => { mutations.forEach(mutation => { mutation.addedNodes.forEach(node => { if (node.nodeType === 1) { const shouldHide = node.hasAttribute('node-type') && ['header-union', 'header-apps', 'find-apps'].includes(node.getAttribute('node-type')) || node.classList.contains('wp-side-options') || node.classList.contains('newIcon') || node.classList.contains('ads-container') || node.classList.contains('banner') || node.classList.contains('vip-promotion'); if (shouldHide) { node.style.display = 'none !important'; node.style.visibility = 'hidden !important'; } } }); }); }); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['class', 'node-type'] }); } })();