remove image lazy load

remove lazyload on img div

  1. // ==UserScript==
  2. // @name remove image lazy load
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description remove lazyload on img div
  6. // @author Charles
  7. // @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
  8. // @match *://**/*
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // @grant GM_registerMenuCommand
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. "use strict";
  16. let white_lists = GM_getValue("whitelists", []);
  17. let host_name = document.location.hostname;
  18. GM_registerMenuCommand("add site to enable remove lazy load", function () {
  19. console.log(host_name);
  20. // if host name is in white list, return
  21. if (white_lists.includes(host_name)) {
  22. return;
  23. }
  24. GM_setValue("whitelists", white_lists.concat(host_name));
  25. });
  26. GM_registerMenuCommand(
  27. "remove site to disable remove lazy load",
  28. function () {
  29. console.log(host_name);
  30. // if host name is not in white list, return
  31. if (!white_lists.includes(host_name)) {
  32. return;
  33. }
  34. GM_setValue(
  35. "whitelists",
  36. white_lists.filter((e) => e !== host_name)
  37. );
  38. }
  39. );
  40. // if host name is in white list , then enable remove lazy load
  41. if (white_lists.includes(host_name)) {
  42. // remove loading attribute
  43. let images = document.getElementsByTagName("img");
  44. for (let image of images) {
  45. image.removeAttribute("loading");
  46. // set data-src to src
  47. if (image.getAttribute("data-src") !== null)
  48. image.setAttribute("src", image.getAttribute("data-src"));
  49. else if (image.getAttribute("data-original") !== null)
  50. image.setAttribute("src", image.getAttribute("data-original"));
  51. }
  52. }
  53. })();