Greasy Fork

Greasy Fork is available in English.

禁止 Web 延迟加载图片(一次性加载)

在 Web 页面中直接显示图片,禁止延迟加载,一次性加载所有图片

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         禁止 Web 延迟加载图片(一次性加载)
// @name:en      Disable web lazy loading images (one-time loading)
// @description  在 Web 页面中直接显示图片,禁止延迟加载,一次性加载所有图片
// @description:en Display images directly on the web page, disable lazy loading, load all images at once.
// @version      0.8.5
// @author       DUN
// @match        *://*/*
// @grant        none
// @run-at       document-start
// @namespace    http://greasyfork.icu/users/662094
// ==/UserScript==

(function() {
    'use strict';

    function isExcluded(url) {
        const excludedKeywords = [
            // 在这里添加你要排除的关键词
        ];
        return excludedKeywords.some(keyword => url.includes(keyword));
    }

    function updateImageSource(imgElement) {
        const srcAttribute = imgElement.getAttribute("data-src") || imgElement.getAttribute("data-original") || imgElement.src;
        if (srcAttribute && !isExcluded(srcAttribute)) {
            if (srcAttribute.startsWith('data:image')) {
                imgElement.src = srcAttribute;
            } else {
                imgElement.src = new URL(srcAttribute, window.location.href).href;
            }
        }

        const srcsetAttribute = imgElement.getAttribute("data-srcset");
        if (srcsetAttribute) {
            imgElement.srcset = srcsetAttribute;
        }

        imgElement.removeAttribute('data-src');
        imgElement.removeAttribute('data-srcset');
        imgElement.removeAttribute('srcset');
        imgElement.removeAttribute('sizes');
        imgElement.classList.remove('lazyload', 'lazy');
    }

    function processAddedNodes(addedNodes) {
        addedNodes.forEach(node => {
            if (node.tagName === 'IMG') {
                updateImageSource(node);
            } else if (node.querySelectorAll) {
                node.querySelectorAll('img').forEach(updateImageSource);
            }
        });
    }

    const observer = new MutationObserver(mutations => {
        mutations.forEach(mutation => {
            if (mutation.type === 'childList' && mutation.addedNodes.length) {
                processAddedNodes(mutation.addedNodes);
            } else if (mutation.type === 'attributes' && (mutation.attributeName === 'data-src' || mutation.attributeName === 'data-original')) {
                updateImageSource(mutation.target);
            }
        });
    });

    observer.observe(document.documentElement, {
        childList: true,
        subtree: true,
        attributes: true,
        attributeFilter: ['data-src', 'data-original']
    });

    window.addEventListener('DOMContentLoaded', () => {
        document.querySelectorAll('img').forEach(updateImageSource);
    });
})();