// ==UserScript== // @name 图片样式屏蔽器 // @version 1.3 // @description 隐藏所有图片元素,可以用来看网页小说和视频,脚本菜单启用脚本 // @author ChatGPT // @match *://*/* // @grant GM_registerMenuCommand // @grant GM_setValue // @grant GM_getValue // @run-at document-start // @namespace https://greasyfork.org/users/452911 // @downloadURL none // ==/UserScript== (function() { 'use strict'; const currentHostname = window.location.hostname; // 添加设置菜单 GM_registerMenuCommand("启用图片样式屏蔽器", () => { GM_setValue(`use_image_style_blocker_${currentHostname}`, true); applyImageStyleBlocker(); }); GM_registerMenuCommand("禁用图片样式屏蔽器", () => { // 每次点击时重新获取当前状态,以确保状态是最新的 const useImageStyleBlocker = GM_getValue(`use_image_style_blocker_${currentHostname}`, false); if (useImageStyleBlocker) { GM_setValue(`use_image_style_blocker_${currentHostname}`, false); window.location.reload(); // 禁用后立即刷新页面以移除效果 } }); // 在初始化时检查是否应用样式屏蔽器 checkAndApplyImageStyleBlocker(); function checkAndApplyImageStyleBlocker() { const useImageStyleBlocker = GM_getValue(`use_image_style_blocker_${currentHostname}`, false); if (useImageStyleBlocker) { applyImageStyleBlocker(); } } function applyImageStyleBlocker() { let style = document.createElement('style'); 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;}`; document.head.appendChild(style); } })();