Block Element by Name

根据F12查找到的element名称,对其进行自动屏蔽的通用脚本,*****请注意第15~17行*****,自行修改需要屏蔽的网站和内容(现在的blockeName和blockedPageUrls是用来屏蔽嘶哩嘶哩的悬浮窗广告的)

目前为 2023-04-28 提交的版本。查看 最新版本

// ==UserScript==
// @name         Block Element by Name
// @namespace    http://tampermonkey.net/
// @version      1.14
// @description  根据F12查找到的element名称,对其进行自动屏蔽的通用脚本,*****请注意第15~17行*****,自行修改需要屏蔽的网站和内容(现在的blockeName和blockedPageUrls是用来屏蔽嘶哩嘶哩的悬浮窗广告的)
// @author       chatGPT生成的=。=
// @match        http://*/*
// @match        https://*/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Configure the blocked element name and page URLs here | 在下面输入你不想看到的element名称和包含它们的页面,在浏览器中按F12可以很容易找到。
    var blockName = ['coupletleft','coupletright','HMRichBox']; // Change to the name of the element to be blocked
    var blockedPageUrls = ['https://www.silisili.tv/', 'http://www.example.org/'];

    // Check if the current page URL matches one of the blockedPageUrls
    function isBlockedPageUrl() {
        for (var i = 0; i < blockedPageUrls.length; i++) {
            if (window.location.href.indexOf(blockedPageUrls[i]) !== -1) {
                return true;
            }
        }
        return false;
    }

    // Block elements with the specified name
    function blockElementsByName(name) {
        var elements = document.getElementsByTagName('*');
        for(var i=0; i<elements.length; i++) {
            if(elements[i].getAttribute('name') === name) {
                elements[i].style.display = 'none';
            }
        }
    }

    // Main script logic
    if (isBlockedPageUrl()) {
        blockElementsByName(blockName);
    }

})();