remove image lazy load

remove lazyload on img div

Versione datata 02/05/2024. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         remove image lazy load
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  remove lazyload on img div
// @author       Charles
// @icon         https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @match        *://**/*
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_registerMenuCommand
// ==/UserScript==

(function () {
  "use strict";
  let white_lists = GM_getValue("whitelists", []);
  let host_name = document.location.hostname;
  GM_registerMenuCommand("add site to enable remove lazy load", function () {
    console.log(host_name);
    // if host name is in white list, return
    if (white_lists.includes(host_name)) {
      return;
    }
    GM_setValue("whitelists", white_lists.concat(host_name));
  });
  GM_registerMenuCommand(
    "remove site to disable remove lazy load",
    function () {
      console.log(host_name);
      // if host name is not in white list, return
      if (!white_lists.includes(host_name)) {
        return;
      }
      GM_setValue(
        "whitelists",
        white_lists.filter((e) => e !== host_name)
      );
    }
  );
  // if host name is in white list , then enable remove lazy load
  if (white_lists.includes(host_name)) {
    // remove loading attribute
    let images = document.getElementsByTagName("img");
    for (let image of images) {
      image.removeAttribute("loading");
      // set data-src to src
      if (image.getAttribute("data-src") !== null)
        image.setAttribute("src", image.getAttribute("data-src"));
      else if (image.getAttribute("data-original") !== null)
        image.setAttribute("src", image.getAttribute("data-original"));
    }
  }
})();