Disable Shafa Lazy Loading

Disable the lazy loading for images

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

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

})();