Greasy Fork

Greasy Fork is available in English.

图片样式屏蔽器

隐藏所有图片元素,可以用来看网页小说和视频,脚本菜单启用/禁用脚本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         图片样式屏蔽器
// @version      1.4
// @description  隐藏所有图片元素,可以用来看网页小说和视频,脚本菜单启用/禁用脚本
// @author       ChatGPT
// @match        *://*/*
// @grant        GM_registerMenuCommand
// @grant        GM_unregisterMenuCommand
// @grant        GM_setValue
// @grant        GM_getValue
// @run-at       document-start
// @namespace http://greasyfork.icu/users/452911
// ==/UserScript==

(function() {
    'use strict';

    const currentHostname = window.location.hostname;

    // 在初始化时检查是否应用样式屏蔽器
    checkAndApplyImageStyleBlocker();

    // 动态创建或更新菜单项
    function updateMenu() {
        const useImageStyleBlocker = GM_getValue(`use_image_style_blocker_${currentHostname}`, false);
        if (useImageStyleBlocker) {
            GM_registerMenuCommand("禁用图片样式屏蔽器", () => {
                GM_setValue(`use_image_style_blocker_${currentHostname}`, false);
                window.location.reload(); // 禁用后立即刷新页面以移除效果
            });
        } else {
            GM_registerMenuCommand("启用图片样式屏蔽器", () => {
                GM_setValue(`use_image_style_blocker_${currentHostname}`, true);
                applyImageStyleBlocker();
                updateMenu(); // 更新菜单项
            });
        }
    }

    function checkAndApplyImageStyleBlocker() {
        const useImageStyleBlocker = GM_getValue(`use_image_style_blocker_${currentHostname}`, false);
        updateMenu(); // 初始时更新菜单项
        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);
    }
})();