消除js Remove JS Button

在当前页添加一个删除指定的html标签的按钮,点击后会自动删除JS。

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

  1. // ==UserScript==
  2. // @name 消除js Remove JS Button
  3. // @namespace 消除js Remove JS Button
  4. // @license yagizaMJ
  5. // @version 1.1.1
  6. // @description 在当前页添加一个删除指定的html标签的按钮,点击后会自动删除JS。
  7. // @AuThor yagizaMJ
  8. // @match *://*/*
  9. // @grant none
  10. // ==/UserScript==
  11. (function() {
  12. 'use strict';
  13. function removeTags(tagNames) {
  14. tagNames.forEach(function(tagName) {
  15. // 获取所有指定标签
  16. var elements = document.querySelectorAll(tagName);
  17. // 遍历所有的指定标签并移除它们
  18. elements.forEach(function(element) {
  19. element.parentNode.removeChild(element);
  20. });
  21. });
  22. }
  23. // 创建按钮元素
  24. var removeButton = document.createElement('button');
  25. removeButton.textContent = 'Remove JS';
  26. removeButton.style.position = 'fixed';
  27. removeButton.style.top = '250px';
  28. removeButton.style.right = '20px';
  29. removeButton.style.zIndex = '9999';
  30. // 将按钮添加到页面上
  31. document.body.appendChild(removeButton);
  32. // 添加按钮点击事件
  33. removeButton.addEventListener('click', function() {
  34. // 调用函数删除 <a> 和 <h1> 标签
  35. removeTags(['link', 'script']);
  36. // 移除按钮自身
  37. removeButton.parentNode.removeChild(removeButton);
  38. });
  39. // 隐藏按钮的右键菜单
  40. removeButton.addEventListener('contextmenu', function(event) {
  41. event.preventDefault();
  42. removeButton.style.display = 'none';
  43. });
  44. // 当文档双击时,恢复按钮
  45. document.addEventListener('dblclick', function() {
  46. removeButton.style.display = 'block';
  47. });
  48. })();