Greasy Fork

Greasy Fork is available in English.

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

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

当前为 2023-07-22 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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 http://greasyfork.icu/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();
})();