消除js Remove JS Button

Add a button to remove specified HTML tags from the current page and remove itself after clicking

当前为 2024-06-20 提交的版本,查看 最新版本

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         消除js Remove JS Button
// @namespace    消除js Remove JS Button
// @license      yagizaMJ
// @version      1.1
// @description  Add a button to remove specified HTML tags from the current page and remove itself after clicking
// @AuThor       yagizaMJ
// @match        *://*/*
// @grant        none
// ==/UserScript==
 
(function() {
    'use strict';
 
    function removeTags(tagNames) {
        tagNames.forEach(function(tagName) {
            // 获取所有指定标签
            var elements = document.querySelectorAll(tagName);
 
            // 遍历所有的指定标签并移除它们
            elements.forEach(function(element) {
                element.parentNode.removeChild(element);
            });
        });
    }
 
    // 创建按钮元素
    var removeButton = document.createElement('button');
    removeButton.textContent = 'Remove JS';
    removeButton.style.position = 'fixed';
    removeButton.style.top = '250px';
    removeButton.style.right = '20px';
    removeButton.style.zIndex = '9999';
 
    // 将按钮添加到页面上
    document.body.appendChild(removeButton);
 
    // 添加按钮点击事件
    removeButton.addEventListener('click', function() {
        // 调用函数删除 <a> 和 <h1> 标签
        removeTags(['link', 'script']);
 
        // 移除按钮自身
        removeButton.parentNode.removeChild(removeButton);
    });
 
    // 隐藏按钮的右键菜单
    removeButton.addEventListener('contextmenu', function(event) {
        event.preventDefault();
        removeButton.style.display = 'none';
    });
 
    // 当文档双击时,恢复按钮
    document.addEventListener('dblclick', function() {
        removeButton.style.display = 'block';
    });
})();