🏠 Home 

禁止 Web 延迟加载图片(一次性加载)

在 Web 页面中直接显示图片,禁止延迟加载,一次性加载所有图片


安装此脚本?
  1. // ==UserScript==
  2. // @name 禁止 Web 延迟加载图片(一次性加载)
  3. // @name:en Disable web lazy loading images (one-time loading)
  4. // @description 在 Web 页面中直接显示图片,禁止延迟加载,一次性加载所有图片
  5. // @description:en Display images directly on the web page, disable lazy loading, load all images at once.
  6. // @version 0.8.5
  7. // @author DUN
  8. // @match *://*/*
  9. // @grant none
  10. // @run-at document-start
  11. // @namespace https://greasyfork.org/users/662094
  12. // ==/UserScript==
  13. (function() {
  14. 'use strict';
  15. function isExcluded(url) {
  16. const excludedKeywords = [
  17. // 在这里添加你要排除的关键词
  18. ];
  19. return excludedKeywords.some(keyword => url.includes(keyword));
  20. }
  21. function updateImageSource(imgElement) {
  22. const srcAttribute = imgElement.getAttribute("data-src") || imgElement.getAttribute("data-original") || imgElement.src;
  23. if (srcAttribute && !isExcluded(srcAttribute)) {
  24. if (srcAttribute.startsWith('data:image')) {
  25. imgElement.src = srcAttribute;
  26. } else {
  27. imgElement.src = new URL(srcAttribute, window.location.href).href;
  28. }
  29. }
  30. const srcsetAttribute = imgElement.getAttribute("data-srcset");
  31. if (srcsetAttribute) {
  32. imgElement.srcset = srcsetAttribute;
  33. }
  34. imgElement.removeAttribute('data-src');
  35. imgElement.removeAttribute('data-srcset');
  36. imgElement.removeAttribute('srcset');
  37. imgElement.removeAttribute('sizes');
  38. imgElement.classList.remove('lazyload', 'lazy');
  39. }
  40. function processAddedNodes(addedNodes) {
  41. addedNodes.forEach(node => {
  42. if (node.tagName === 'IMG') {
  43. updateImageSource(node);
  44. } else if (node.querySelectorAll) {
  45. node.querySelectorAll('img').forEach(updateImageSource);
  46. }
  47. });
  48. }
  49. const observer = new MutationObserver(mutations => {
  50. mutations.forEach(mutation => {
  51. if (mutation.type === 'childList' && mutation.addedNodes.length) {
  52. processAddedNodes(mutation.addedNodes);
  53. } else if (mutation.type === 'attributes' && (mutation.attributeName === 'data-src' || mutation.attributeName === 'data-original')) {
  54. updateImageSource(mutation.target);
  55. }
  56. });
  57. });
  58. observer.observe(document.documentElement, {
  59. childList: true,
  60. subtree: true,
  61. attributes: true,
  62. attributeFilter: ['data-src', 'data-original']
  63. });
  64. window.addEventListener('DOMContentLoaded', () => {
  65. document.querySelectorAll('img').forEach(updateImageSource);
  66. });
  67. })();