소스 검색

force loading of lazy loaded elements

Former-commit-id: fa46b64d235d5830c3f37c45c53b83e42db7a073
Gildas 5 년 전
부모
커밋
8e1fa2668b
1개의 변경된 파일9개의 추가작업 그리고 0개의 파일을 삭제
  1. 9 0
      lib/single-file/processors/hooks/content/content-hooks-frames-web.js

+ 9 - 0
lib/single-file/processors/hooks/content/content-hooks-frames-web.js

@@ -31,6 +31,7 @@
 	const BLOCK_COOKIES_END_EVENT = "single-file-block-cookies-end";
 	const BLOCK_STORAGE_START_EVENT = "single-file-block-storage-start";
 	const BLOCK_STORAGE_END_EVENT = "single-file-block-storage-end";
+	const LAZY_LOAD_ATTRIBUTE = "single-file-lazy-load";
 	const LOAD_IMAGE_EVENT = "single-file-load-image";
 	const IMAGE_LOADED_EVENT = "single-file-image-loaded";
 	const NEW_FONT_FACE_EVENT = "single-file-new-font-face";
@@ -69,6 +70,10 @@
 		scrollingElement.__defineGetter__("clientWidth", () => scrollWidth);
 		screen.__defineGetter__("height", () => scrollHeight);
 		screen.__defineGetter__("width", () => scrollWidth);
+		document.querySelectorAll("[loading=lazy]").forEach(element => {
+			element.loading = "eager";
+			element.setAttribute(LAZY_LOAD_ATTRIBUTE, "");
+		});
 		if (!window._singleFile_getBoundingClientRect) {
 			window._singleFile_getBoundingClientRect = Element.prototype.getBoundingClientRect;
 			Element.prototype.getBoundingClientRect = function () {
@@ -154,6 +159,10 @@
 
 	addEventListener.call(window, LOAD_DEFERRED_IMAGES_END_EVENT, () => {
 		const scrollingElement = document.scrollingElement || document.documentElement;
+		document.querySelectorAll("[" + LAZY_LOAD_ATTRIBUTE + "]").forEach(element => {
+			element.loading = "lazy";
+			element.removeAttribute(LAZY_LOAD_ATTRIBUTE);
+		});
 		delete scrollingElement.clientHeight;
 		delete scrollingElement.clientWidth;
 		delete screen.height;