Greasy Fork

无图模式

点击脚本菜单关闭/开启页面图片

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

// ==UserScript==
// @name         无图模式
// @namespace    http://tampermonkey.net/
// @license MIT
// @version      0.2
// @icon         https://qwn3213.com/icon/tupian.png
// @description  点击脚本菜单关闭/开启页面图片
// @author       Q伟N
// @match        *://*/*
// @require      http://code.jquery.com/jquery-latest.js
// @grant        GM_registerMenuCommand
// @grant        GM_unregisterMenuCommand
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(function() {
    'use strict';
    var host = window.location.hostname;
    var imgShow = GM_getValue(host);
    if (imgShow === false) {
        $('img').each(function() {
            $(this).hide();
            if (!$(this).next().is('.hidden-image-notice')) { // 如果还没有添加过文案
                $(this).after('<div class="hidden-image-notice">!!!已隐藏图片!!!</div>'); // 在图片后面添加文案
            }
        });
    } else {
        imgShow = true;
    }

    function menu_change() {
        imgShow = !imgShow;
        if (imgShow) {
            $('img').show();
            $('.hidden-image-notice').remove(); // 移除所有的 "已隐藏图片" 文案
        } else {
            $('img').each(function() {
                $(this).hide();
                if (!$(this).next().is('.hidden-image-notice')) {
                    $(this).after('<div class="hidden-image-notice">!!!已隐藏图片!!!</div>');
                }
            });
        }
        GM_setValue(host, imgShow);
        GM_unregisterMenuCommand(menuId);
        menuId = GM_registerMenuCommand((imgShow ? '✅': '❌') + '图', menu_change, 'h');
    }

    var menuId = GM_registerMenuCommand((imgShow ? '✅': '❌') + '图', menu_change, 'h');
})();