remove_all_images.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // ==UserScript==
  2. // @name Remove All Images
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Add a button to remove all images on the page
  6. // @author You
  7. // @match *://*/*
  8. // @grant none
  9. // ==/UserScript==
  10. (function() {
  11. 'use strict';
  12. // 创建按钮元素
  13. const button = document.createElement('button');
  14. button.textContent = "Remove Img";
  15. button.style.position = "fixed";
  16. button.style.top = "12.5%";
  17. button.style.right = "1%";
  18. button.style.transform = "translateY(-50%)";
  19. button.style.padding = "3px 8px";
  20. button.style.fontSize = "10px";
  21. button.style.backgroundColor = "#007baf";
  22. button.style.color = "#fff";
  23. button.style.border = "none";
  24. button.style.borderRadius = "5px";
  25. button.style.cursor = "pointer";
  26. button.style.zIndex = "10000";
  27. // 为按钮添加点击事件监听器
  28. button.addEventListener('click', function() {
  29. // 获取页面上的所有图片元素
  30. const images = document.querySelectorAll('img');
  31. // 遍历所有图片元素并移除它们
  32. images.forEach(image => {
  33. image.parentNode.removeChild(image);
  34. });
  35. });
  36. // 将按钮添加到页面的 body 元素中
  37. document.body.appendChild(button);
  38. })();