Disable Shafa Lazy Loading

Disable the lazy loading for images

  1. // ==UserScript==
  2. // @name Disable Shafa Lazy Loading
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Disable the lazy loading for images
  6. // @author max5555
  7. // @match https://shafa.ua/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function disableLazyLoading() {
  16. // Find all images with data-src attribute and the relevant classes
  17. const images = document.querySelectorAll('img.js-lazy-img[data-src]');
  18.  
  19. images.forEach(img => {
  20. // Set the src attribute to the value of data-src
  21. img.src = img.getAttribute('data-src');
  22.  
  23. // Remove the lazy loading related classes
  24. img.classList.remove('js-lazy-img', 'lazy-loaded');
  25.  
  26. // If there's a loading attribute set to "lazy", change it to "eager"
  27. if (img.getAttribute('loading') === 'lazy') {
  28. img.setAttribute('loading', 'eager');
  29. }
  30. });
  31. }
  32.  
  33. disableLazyLoading();
  34.  
  35. // As many sites load content dynamically (e.g., infinite scroll, AJAX),
  36. // consider setting up a MutationObserver to handle new elements being added to the DOM.
  37. const observer = new MutationObserver(mutationsList => {
  38. for(const mutation of mutationsList) {
  39. if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
  40. disableLazyLoading();
  41. }
  42. }
  43. });
  44.  
  45. observer.observe(document.body, { childList: true, subtree: true });
  46.  
  47. })();