🏠 Home 

图片样式屏蔽器

隐藏所有图片元素,可以用来看网页小说和视频,脚本菜单启用/禁用脚本,也可以通过A键加B键触发

  1. // ==UserScript==
  2. // @name 图片样式屏蔽器
  3. // @version 1.5
  4. // @description 隐藏所有图片元素,可以用来看网页小说和视频,脚本菜单启用/禁用脚本,也可以通过A键加B键触发
  5. // @author ChatGPT
  6. // @match *://*/*
  7. // @grant GM_registerMenuCommand
  8. // @grant GM_unregisterMenuCommand
  9. // @grant GM_setValue
  10. // @grant GM_getValue
  11. // @run-at document-start
  12. // @namespace https://greasyfork.org/users/452911
  13. // ==/UserScript==
  14. (function() {
  15. 'use strict';
  16. const currentHostname = window.location.hostname;
  17. const styleId = 'image-style-blocker';
  18. let isStyleBlocked = GM_getValue(`use_image_style_blocker_${currentHostname}`, false);
  19. // 检查并应用图片样式屏蔽器
  20. checkAndApplyImageStyleBlocker();
  21. let aKeyPressed = false;
  22. let bKeyPressed = false;
  23. // 监听快捷键事件
  24. document.addEventListener('keydown', function(e) {
  25. if (e.key === 'a') {
  26. aKeyPressed = true;
  27. }
  28. if (e.key === 'b') {
  29. bKeyPressed = true;
  30. }
  31. if (aKeyPressed && bKeyPressed) {
  32. e.preventDefault(); // 阻止默认行为
  33. toggleImageStyleBlocker();
  34. aKeyPressed = false; // 重置状态
  35. bKeyPressed = false; // 重置状态
  36. }
  37. });
  38. document.addEventListener('keyup', function(e) {
  39. if (e.key === 'a') {
  40. aKeyPressed = false;
  41. }
  42. if (e.key === 'b') {
  43. bKeyPressed = false;
  44. }
  45. });
  46. // 动态创建或更新菜单项
  47. function updateMenu() {
  48. GM_unregisterMenuCommand("启用图片样式屏蔽器");
  49. GM_unregisterMenuCommand("禁用图片样式屏蔽器");
  50. if (isStyleBlocked) {
  51. GM_registerMenuCommand("禁用图片样式屏蔽器", () => {
  52. GM_setValue(`use_image_style_blocker_${currentHostname}`, false);
  53. isStyleBlocked = false;
  54. removeImageStyleBlocker();
  55. updateMenu(); // 更新菜单项
  56. });
  57. } else {
  58. GM_registerMenuCommand("启用图片样式屏蔽器", () => {
  59. GM_setValue(`use_image_style_blocker_${currentHostname}`, true);
  60. isStyleBlocked = true;
  61. applyImageStyleBlocker();
  62. updateMenu(); // 更新菜单项
  63. });
  64. }
  65. }
  66. function checkAndApplyImageStyleBlocker() {
  67. isStyleBlocked = GM_getValue(`use_image_style_blocker_${currentHostname}`, false);
  68. updateMenu(); // 更新菜单项
  69. if (isStyleBlocked) {
  70. applyImageStyleBlocker();
  71. } else {
  72. removeImageStyleBlocker();
  73. }
  74. }
  75. function applyImageStyleBlocker() {
  76. let style = document.createElement('style');
  77. style.id = styleId;
  78. style.innerHTML = `img,[style*='height:'][style*='width:'] {display: none !important;visibility: hidden; opacity: 0; z-index: -999; width: 0; height: 0; pointer-events: none; position: absolute; left: -9999px; top: -9999px;}`;
  79. document.head.appendChild(style);
  80. }
  81. function removeImageStyleBlocker() {
  82. let style = document.getElementById(styleId);
  83. if (style) {
  84. style.remove();
  85. }
  86. }
  87. function toggleImageStyleBlocker() {
  88. isStyleBlocked = !isStyleBlocked;
  89. GM_setValue(`use_image_style_blocker_${currentHostname}`, isStyleBlocked);
  90. if (isStyleBlocked) {
  91. applyImageStyleBlocker();
  92. } else {
  93. removeImageStyleBlocker();
  94. }
  95. updateMenu(); // 更新菜单项
  96. }
  97. })();