Disable Shafa Lazy Loading

Disable the lazy loading for images

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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 });

})();