Greasy Fork

Greasy Fork is available in English.

Bangumi排行榜隐藏已收藏条目

排行榜隐藏已收藏条目

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Bangumi排行榜隐藏已收藏条目
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  排行榜隐藏已收藏条目
// @author       KunimiSaya
// @match        https://bgm.tv/*/browser*
// @match        https://bangumi.tv/*/browser*
// @match        https://chii.in/*/browser*
// @match        https://bgm.tv/index/*
// @match        https://chii.in/index/*
// @match        https://bangumi.tv/index/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    let isEnabled = true; // Flag to track whether hiding is enabled or disabled

    // Function to hide collected items
    function hideCollectedItems() {
        if (!isEnabled) return; // Do nothing if the script is disabled

        let items = document.querySelectorAll('.item');

        items.forEach(function(item) {
            if (item.querySelector('.collectModify')) {
                item.style.display = 'none';
            }
        });
    }

    // Function to show collected items (when the feature is disabled)
    function showCollectedItems() {
        let items = document.querySelectorAll('.item');

        items.forEach(function(item) {
            if (item.querySelector('.collectModify')) {
                item.style.display = ''; // Reset display style
            }
        });
    }

    // Function to toggle hiding
    function toggleHiding() {
        isEnabled = !isEnabled;

        if (isEnabled) {
            hideCollectedItems();
        } else {
            showCollectedItems();
        }
    }

    // Initial hiding of collected items
    hideCollectedItems();

    // Observe the page for any new nodes being added
    let observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            if (mutation.addedNodes.length) {
                hideCollectedItems();
            }
        });
    });

    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

    // Add the toggle button
    const browserTools = document.querySelector('#browserTools');
    if (browserTools) {
        const toggleButton = document.createElement('a');
        toggleButton.className = 'chiiBtn';
        toggleButton.href = 'javascript:void(0);';
        toggleButton.innerText = '显示/隐藏已收藏作品';
        toggleButton.onclick = toggleHiding;

        // Insert the toggle button before the sorting options
        browserTools.insertBefore(toggleButton, browserTools.firstChild);
    }
})();