// ==UserScript== // @name Bangumi 隐藏NSFW条目 // @version 2.9 // @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/"]'); for (const item of listItems) { const subjectId = item.getAttribute('href').split('/')[2]; const isChecked = await isSubjectChecked(subjectId); if (isChecked) { item.parentElement.style.display = 'none'; } } } // 切换已选中条目可见性的函数 async function toggleNSFW() { const listItems = document.querySelectorAll('li > a[href^="/subject/"]'); for (const item of listItems) { const subjectId = item.getAttribute('href').split('/')[2]; const isChecked = await isSubjectChecked(subjectId); if (isChecked) { item.parentElement.style.display = item.parentElement.style.display === 'none' ? '' : 'none'; } } // 切换按钮文本 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.href = 'javascript:void(0);'; toggleLink.style.cssText = showBtn.style.cssText; toggleLink.classList.add('chiiBtn'); // 添加 class="chiiBtn" toggleLink.addEventListener('click', toggleNSFW); browserTools.appendChild(toggleLink); // 初始化:隐藏所有已选中的条目 hideCheckedSubjects(); // 观察页面变化并隐藏新出现的已选中条目 const observer = new MutationObserver((mutationsList) => { for (const mutation of mutationsList) { if (mutation.type === 'childList') { mutation.addedNodes.forEach((node) => { if (node.nodeType === 1 && node.matches('li > a[href^="/subject/"]')) { hideCheckedSubjects(); } }); } } }); observer.observe(document.body, { childList: true, subtree: true }); })();