Disable Wechat Images Lazyload

Disable Wechat Images Lazyload, Show Origin Images Directly

2025-05-19 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

    // ==UserScript==
    // @name               Disable Wechat Images Lazyload
    // @name:zh-CN         微信公众号去除图片延迟加载
    // @description        Disable Wechat Images Lazyload, Show Origin Images Directly
    // @description:zh-CN  去除图片延迟加载,直接显示原图片
    // @namespace          https://www.runningcheese.com
    // @version            0.3
    // @author             RunningCheese
    // @match              https://mp.weixin.qq.com/s/*
    // @match              https://mp.weixin.qq.com/s?__biz=*
    // @run-at             document-start
    // @require            https://code.jquery.com/jquery-3.3.1.min.js
    // @icon               https://t1.gstatic.cn/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https://mp.weixin.qq.com
    // @license            MIT
    // ==/UserScript==
     
     
    var $ = window.jQuery;
    
    // 处理图片懒加载
    function processLazyImages() {
        $('img').each(function(){
            var dataSrc = $(this).attr('data-src');
            if (dataSrc){
                $(this).attr('src', dataSrc);
                $(this).removeAttr('data-src');
                $(this).removeAttr('data-type');
                $(this).removeAttr('data-w');
                $(this).removeAttr('data-ratio');
                $(this).removeAttr('data-fail');
            }
        });
    }
    
    // 移除URL中的懒加载参数
    function removeWxLazyParam() {
        const links = document.querySelectorAll('a');
        links.forEach(link => {
            if (link.href && link.href.includes('wx_lazy=1')) {
                link.href = link.href.replace('wx_lazy=1', '');
            }
        });
    }
    
    // 监听DOM变化,处理动态加载的内容
    function observeDOMChanges() {
        const observer = new MutationObserver(function(mutations) {
            processLazyImages();
            removeWxLazyParam();
        });
        
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    }
    
    // 页面加载完成后执行
    $(document).ready(function() {
        // 立即执行一次
        processLazyImages();
        removeWxLazyParam();
        
        // 再延迟执行一次,确保处理完所有图片
        setTimeout(function(){
            processLazyImages();
            removeWxLazyParam();
            
            // 开始监听DOM变化
            observeDOMChanges();
        }, 1000);
    });
    
    // 替换HTML内容中的懒加载属性
    document.addEventListener('DOMContentLoaded', function() {
        const htmlContent = document.body.innerHTML;
        document.body.innerHTML = htmlContent.replace(/wx_lazy=1/g, '').replace(/data-src/g, 'src');
    });