Disable Shafa Lazy Loading

Disable the lazy loading for images

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Disable Shafa Lazy Loading
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Disable the lazy loading for images
// @author       max5555
// @match        https://shafa.ua/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function disableLazyLoading() {
        // Find all images with data-src attribute and the relevant classes
        const images = document.querySelectorAll('img.js-lazy-img[data-src]');

        images.forEach(img => {
            // Set the src attribute to the value of data-src
            img.src = img.getAttribute('data-src');

            // Remove the lazy loading related classes
            img.classList.remove('js-lazy-img', 'lazy-loaded');

            // If there's a loading attribute set to "lazy", change it to "eager"
            if (img.getAttribute('loading') === 'lazy') {
                img.setAttribute('loading', 'eager');
            }
        });
    }

    disableLazyLoading();

    // As many sites load content dynamically (e.g., infinite scroll, AJAX),
    // consider setting up a MutationObserver to handle new elements being added to the DOM.
    const observer = new MutationObserver(mutationsList => {
        for(const mutation of mutationsList) {
            if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
                disableLazyLoading();
            }
        }
    });

    observer.observe(document.body, { childList: true, subtree: true });

})();