禁止 Web 延迟加载图片(优化版 - 支持滑动加载)

在 Web 页面中直接显示图片,禁止延迟加载,支持滑动加载图片

目前為 2023-07-22 提交的版本,檢視 最新版本

// ==UserScript==
// @name         禁止 Web 延迟加载图片(优化版 - 支持滑动加载)
// @name:en     Disable Web Lazy Loading Images (Enhanced Version - Supports Scroll Loading)
// @description  在 Web 页面中直接显示图片,禁止延迟加载,支持滑动加载图片
// @description:en Display images directly on the web page, prohibit lazy loading, and support scroll-loaded images.
// @version      0.5
// @author       DUN
// @match        *://*/*
// @run-at       document-start
// @namespace https://gf.qytechs.cn/users/662094
// ==/UserScript==

(function() {
    // 禁止图片延迟加载
    function disableLazyLoad() {
        var images = document.querySelectorAll('img[data-src]');
        images.forEach(function(img) {
            img.setAttribute('src', img.getAttribute('data-src'));
            img.removeAttribute('data-src');
        });
    }

    // 使用 IntersectionObserver 监视图片加载
    var observer = new IntersectionObserver(function(entries, observer) {
        entries.forEach(function(entry) {
            if (entry.isIntersecting) {
                var img = entry.target;
                if (img.hasAttribute('data-src')) {
                    img.setAttribute('src', img.getAttribute('data-src'));
                    img.removeAttribute('data-src');
                    observer.unobserve(img); // 只加载一次后停止观察
                }
            }
        });
    });

    // 获取所有需要处理的图片元素
    var images = document.querySelectorAll('img[data-src]');
    images.forEach(function(img) {
        observer.observe(img);
    });

    // 初始禁止延迟加载
    disableLazyLoad();
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址