Iwara ID 黑名单 (v3.5 视频与图片通用版)

在 iwara.tv 上根据作者 Profile ID 屏蔽所有类型作品(视频、图片)和评论

// ==UserScript==
// @name         Iwara ID 黑名单 (v3.5 视频与图片通用版)
// @namespace    http://tampermonkey.net/
// @version      3.5
// @license      MIT
// @description  在 iwara.tv 上根据作者 Profile ID 屏蔽所有类型作品(视频、图片)和评论
// @author       Gemini
// @match        https://*.iwara.tv/*
// @grant        GM_getValue
// @grant        GM_setValue
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    const BLACKLIST_KEY = 'iwara_id_blacklist';

    const getBlacklist = () => {
        const defaultValue = '["blacklane"]';
        return new Set(JSON.parse(GM_getValue(BLACKLIST_KEY, defaultValue)));
    };

    const saveBlacklist = (blacklistSet) => {
        GM_setValue(BLACKLIST_KEY, JSON.stringify(Array.from(blacklistSet)));
    };


    /**
     * 根据 Profile ID 动态隐藏所有类型的作品 (视频和图片)
     */
    const hideBlacklistedWorks = () => {
        const blacklist = getBlacklist();
        if (blacklist.size === 0) return;

        // --- 核心改动:使用逗号分隔,同时选择 videoTeaser 和 imageTeaser,以屏蔽视频和图片两种类型的作品 ---
        const works = document.querySelectorAll('.videoTeaser:not([data-id-checked]), .imageTeaser:not([data-id-checked])');

        for (const work of works) {
            work.dataset.idChecked = 'true';

            const authorLink = work.querySelector('a.username');
            if (authorLink) {
                const profileId = authorLink.href.split('/profile/')[1];
                if (profileId && blacklist.has(profileId)) {
                    const workContainer = work.closest('[class*="col-"]');
                    if (workContainer) {
                        console.log(`[Iwara ID 黑名单] 已隐藏 ID: ${profileId} 的作品 (类型: ${work.className.split(' ')[0]})`);
                        workContainer.style.display = 'none';
                    }
                }
            }
        }
    };

    /**
     * 根据 Profile ID 动态隐藏评论
     */
    const hideBlacklistedComments = () => {
        const blacklist = getBlacklist();
        if (blacklist.size === 0) return;

        const comments = document.querySelectorAll('.comment:not([data-id-checked])');
        for (const comment of comments) {
            comment.dataset.idChecked = 'true';

            const authorLink = comment.querySelector('a.username');
            if (authorLink) {
                const profileId = authorLink.href.split('/profile/')[1];
                if (profileId && blacklist.has(profileId)) {
                    const commentContainer = comment.closest('.col-12');
                    if (commentContainer) {
                         console.log(`[Iwara ID 黑名单] 已隐藏 ID: ${profileId} 的评论`);
                         commentContainer.style.display = 'none';
                    }
                }
            }
        }
    };


    /**
     * 在作者主页添加“拉黑ID”按钮
     */
    const addBlockButton = () => {
        if (!window.location.pathname.startsWith('/profile/')) return;
        if (document.querySelector('#author-id-block-btn')) return;

        const container = document.querySelector('.page-profile__header__middle .d-flex.align-items-center');
        if (!container) return;

        const currentProfileId = window.location.pathname.split('/profile/')[1];
        if (!currentProfileId) return;

        const blockButton = document.createElement('div');
        blockButton.id = 'author-id-block-btn';
        Object.assign(blockButton.style, {
            marginLeft: '16px', padding: '4px 10px', border: '1px solid #ccc',
            borderRadius: '5px', cursor: 'pointer', fontSize: '14px',
            fontWeight: 'bold', userSelect: 'none', transition: 'all 0.2s ease'
        });

        const updateButtonState = (isBlocked) => {
            blockButton.textContent = isBlocked ? '✓ 已拉黑此ID (移除)' : '🚫 拉黑此ID';
            blockButton.style.borderColor = isBlocked ? '#e91e63' : '#ccc';
            blockButton.style.color = isBlocked ? '#e91e63' : '#555';
            blockButton.style.backgroundColor = isBlocked ? '#fce4ec' : '#f0f0f0';
        };

        let blacklist = getBlacklist();
        updateButtonState(blacklist.has(currentProfileId));

        blockButton.addEventListener('click', (e) => {
            e.stopPropagation();
            let currentBlacklist = getBlacklist();
            if (currentBlacklist.has(currentProfileId)) {
                currentBlacklist.delete(currentProfileId);
            } else {
                currentBlacklist.add(currentProfileId);
            }
            saveBlacklist(currentBlacklist);
            updateButtonState(currentBlacklist.has(currentProfileId));
        });

        container.appendChild(blockButton);
    };

    // --- 动态内容监控核心 ---
    const observer = new MutationObserver(() => {
        hideBlacklistedWorks();
        hideBlacklistedComments();
        addBlockButton();
    });

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