// ==UserScript== // @name Bangumi 隐藏NSFW条目 // @version 2.7 // @description 隐藏NSFW条目 // @author 墨云 // @match https://bangumi.tv/*/browser/* // @match https://chii.in/*/browser/* // @match https://bgm.tv/*/browser/* // @grant none // @namespace https://greasyfork.org/users/1354622 // @downloadURL none // ==/UserScript== (function() { 'use strict'; // 检查条目是否包含 checked 属性的函数 async function isSubjectChecked(subjectId) { const response = await fetch(`/subject/${subjectId}/edit_detail`); const text = await response.text(); return text.includes('checked="checked"'); } // 隐藏已选中条目的函数 async function hideCheckedSubjects() { const listItems = document.querySelectorAll('li > a[href^="/subject/"]'); const promises = Array.from(listItems).map(async (item) => { const subjectId = item.getAttribute('href').split('/')[2]; const isChecked = await isSubjectChecked(subjectId); if (isChecked) { item.parentElement.style.display = 'none'; } }); await Promise.all(promises); } // 切换已选中条目可见性的函数 async function toggleNSFW() { const listItems = document.querySelectorAll('li > a[href^="/subject/"]'); const promises = Array.from(listItems).map(async (item) => { const subjectId = item.getAttribute('href').split('/')[2]; const isChecked = await isSubjectChecked(subjectId); if (isChecked) { item.parentElement.style.display = item.parentElement.style.display === 'none' ? '' : 'none'; } }); await Promise.all(promises); // 切换链接文本 toggleLink.textContent = toggleLink.textContent === '显示NSFW' ? '隐藏NSFW' : '显示NSFW'; } // 在页面中添加切换链接 const browserTools = document.getElementById('browserTools'); const showBtn = document.getElementById('showBtn'); const toggleLink = document.createElement('a'); toggleLink.id = 'toggleNSFWLink'; toggleLink.textContent = '显示NSFW'; toggleLink.className = 'chiiBtn'; toggleLink.style.cssText = showBtn.style.cssText; toggleLink.addEventListener('click', toggleNSFW); browserTools.appendChild(toggleLink); // 初始化:隐藏所有已选中的条目 hideCheckedSubjects(); // 观察页面变化并隐藏新出现的已选中条目 const observer = new MutationObserver(hideCheckedSubjects); observer.observe(document.body, { childList: true, subtree: true }); })();