// ==UserScript== // @name Bangumi 屏蔽色情条目 // @version 0.4 // @description 使用前请登出bangumi.tv的账号,登录并使用bgm.tv的账号 // @author sedoruee // @match *://bgm.tv/* // @match *://bangumi.tv/* // @match *://chii.in/* // @grant none // @namespace https://greasyfork.org/users/1383632 // @downloadURL none // ==/UserScript== (function() { 'use strict'; const host = window.location.host; const isBgm = host === 'bgm.tv' || host === 'chii.in'; function replaceLinks(targetHost) { const links = document.querySelectorAll('a[href]'); for (const link of links) { // 排除 div.page_inner 元素 if (link.closest('div.page_inner')) continue; const href = link.href; const regex = /^(https?:\/\/)(bgm\.tv|chii\.in|bangumi\.tv)(\/(subject|game|book|anime)(\/(\d+|(tag.*)?))?)/; if (regex.test(href)) { if (isBgm) { link.href = href.replace(regex, `$1bangumi.tv$3`); } else { link.href = href.replace(regex, `$1bgm.tv$3`); } } } } if (isBgm) { replaceLinks('bangumi.tv'); } else { replaceLinks('bgm.tv'); } // 监听 DOM 变化,处理动态加载的内容 const observer = new MutationObserver(() => { if (isBgm) { replaceLinks('bangumi.tv'); } else { replaceLinks('bgm.tv'); } }); observer.observe(document.body, { childList: true, subtree: true }); })();