Greasy Fork

无图模式

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

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

// ==UserScript==
// @name         无图模式
// @namespace    http://tampermonkey.net/
// @license MIT
// @version      0.7
// @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) {
        setTimeout(function() {
            hide_img();
            GM_registerMenuCommand('暂时显示', function () {$('img').show();$('.hidden-image-notice').remove();}, 't');
        }, 380);
    } else {
        imgShow = true;
    }

    function menu_change() {
        imgShow = !imgShow;
        if (imgShow) {
            $('img').show();
            $('.hidden-image-notice').remove();
        } else {
           hide_img();
        }
        GM_setValue(host, imgShow);
        GM_unregisterMenuCommand(menuId);
        menuId = GM_registerMenuCommand((imgShow ? '✅': '❌') + '图', menu_change, 'h');
    }


    function hide_img() {
        $('img').each(function() {
            var $this = $(this);
            var imgSrc = $this.attr('src');
            var displayedWidth = $this.width();
            var displayedHeight = $this.height();
            console.log(imgSrc);
            console.log("displayedWidth:"+displayedWidth+",displayedHeight:"+displayedHeight);
            if(displayedWidth>100 || displayedHeight>100){
                $this.hide();
                if (!$this.next().is('.hidden-image-notice')) {
                    $this.after('<div class="hidden-image-notice"><a href="' + imgSrc + '" target="_blank">『图』</a></div>');
                }
            }
        });
    }
    var menuId = GM_registerMenuCommand((imgShow ? '✅': '❌') + '图', menu_change, 'h');
})();