Greasy Fork

拦截CUG网页VPN弹窗

拦截具有特定类名的<div>元素

// ==UserScript==
// @name         拦截CUG网页VPN弹窗
// @version      1.0
// @description  拦截具有特定类名的<div>元素
// @match        https://webvpn.cug.edu.cn/*
// @grant        none
// @namespace https://greasyfork.org/users/1112554
// ==/UserScript==

(function() {
    'use strict';
    var targetClassNames = [ 'dialog-mask','dialog'];
    var observer = new MutationObserver(function(mutationsList) {
        for (var mutation of mutationsList) {
            if (mutation.type === 'childList') {
                mutation.addedNodes.forEach(function(node) {
                    if (node.classList && targetClassNames.some(function(className) { return node.classList.contains(className); })) {
                            node.remove();
                    }
                });
            }
        }
    });
    observer.observe(document.documentElement, {
        childList: true,
        subtree: true
    });
})();