Greasy Fork

Greasy Fork is available in English.

知产网页公告拦截

拦截常用知识产权网站烦人的各种开屏公告和弹窗。

当前为 2025-04-25 提交的版本,查看 最新版本

// ==UserScript==
// @name        知产网页公告拦截
// @namespace   http://tampermonkey.net/
// @version     1.5
// @description 拦截常用知识产权网站烦人的各种开屏公告和弹窗。
// @grant       none
// @match                *://register.ccopyright.com.cn/*
// @match                *://cpquery.cponline.cnipa.gov.cn/*
// @match                *://wssq.sbj.cnipa.gov.cn/*
// @match                *://interactive.cponline.cnipa.gov.cn/*
// @run-at               document-start
// ==/UserScript==

(function() {
    'use strict';

    // 按域名配置选择器 (支持带www的主域名)
    const siteRules = {
        // 版权保护中心配置
        'register.ccopyright.com.cn': [
            '#ie_mask',      // 指定浏览器的提示
            '.ie_alert',             // 指定浏览器的提示
        ],
        // 多国配置
        'cpquery.cponline.cnipa.gov.cn': [
            '.login-u', // 使用说明提示
            '.fixed-full',            // 使用说明提示
        ],
        // 商标申请网配置
        'wssq.sbj.cnipa.gov.cn': [
            '.pop',        // 开屏公告
            '.bgPop',  // 开屏公告
            '.messager-window', // 申请页重要提示
            '.window-mask', // 申请页重要提示
            '.window-shadow', // 申请页重要提示
        ],
        // 专利办理系统配置
        'interactive.cponline.cnipa.gov.cn': [
            '.el-message', // 填写统一信用代码提示
            '.is-closable',            // 填写统一信用代码提示
            '.message-class',            // 填写统一信用代码提示
            '.el-message--error',            // 填写统一信用代码提示
        ]
    };


    // 获取当前域名
    const currentHost = window.location.hostname;

    // 获取当前站点的规则
    const currentSelectors = siteRules[currentHost];

    // 如果当前站点无配置则停止执行
    if (!currentSelectors) return;

    console.log(`[${currentHost}] 规则已加载:`, currentSelectors);

    // 注入CSS隐藏元素
    const style = document.createElement('style');
    style.textContent = currentSelectors.map(sel => `${sel} { display: none !important; }`).join('\n');
    document.head.appendChild(style);

    // 元素检查函数
    function checkElement(element) {
        // 检查元素本身
        if (currentSelectors.some(sel => element.matches(sel))) {
            element.remove();
            console.log(`[${currentHost}] 移除元素:`, element);
            return;
        }

        // 检查子元素
        currentSelectors.forEach(selector => {
            element.querySelectorAll(selector).forEach(target => {
                target.remove();
                console.log(`[${currentHost}] 移除子元素:`, target);
            });
        });
    }

    // DOM修改监听器
    const observer = new MutationObserver(mutations => {
        mutations.forEach(mutation => {
            mutation.addedNodes.forEach(node => {
                if (node.nodeType === Node.ELEMENT_NODE) {
                    checkElement(node);
                }
            });
        });
    });

    // 启动DOM监听
    observer.observe(document, {
        childList: true,
        subtree: true
    });

    // 初始页面清理
    window.addEventListener('DOMContentLoaded', () => {
        currentSelectors.forEach(selector => {
            document.querySelectorAll(selector).forEach(element => {
                element.remove();
                console.log(`[${currentHost}] 初始清理:`, element);
            });
        });
    });

    // 增加额外的初始清理步骤
    setTimeout(() => {
        currentSelectors.forEach(selector => {
            document.querySelectorAll(selector).forEach(element => {
                element.remove();
                console.log(`[${currentHost}] 延迟清理:`, element);
            });
        });
    }, 1000); // 增加1秒延迟

    setTimeout(() => {
        currentSelectors.forEach(selector => {
            document.querySelectorAll(selector).forEach(element => {
                element.remove();
                console.log(`[${currentHost}] 更长延迟清理:`, element);
            });
        });
    }, 5000); // 增加5秒延迟
})();