您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Greasy Fork is available in English.
使用前请登出bangumi.tv的账号,登录并使用bgm.tv的账号
当前为
// ==UserScript== // @name Bangumi 屏蔽色情条目 // @version 0.5 // @description 使用前请登出bangumi.tv的账号,登录并使用bgm.tv的账号 // @author sedoruee // @match *://bgm.tv/* // @match *://bangumi.tv/* // @match *://chii.in/* // @grant none // @namespace http://greasyfork.icu/users/1383632 // ==/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)) { const match = href.match(regex); const targetDomain = match[2]; const targetPath = match[3]; const targetType = match[4]; // 获取当前页面的路径部分和类型 const currentPathRegex = /^\/((subject|game|book|anime)(\/(\d+|(tag.*)?))?)/; const currentPathMatch = window.location.pathname.match(currentPathRegex); const currentType = currentPathMatch ? currentPathMatch[2] : null; const currentPath = currentPathMatch ? currentPathMatch[1] : null; // 检查当前页面和目标链接是否都是 /subject, /game, /book, /anime (不带数字) 且域名相同 const shouldKeepDomain = currentPathMatch && targetType && currentType === targetType && !currentPath.includes("/") && //当前路径没有/ !targetPath.includes("/") && //目标路径没有/ targetDomain === host; if (shouldKeepDomain) { continue; // 保持当前域名 } 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 }); })();