Kaynağa Gözat

improved support of twitter (see #542)

Gildas 5 yıl önce
ebeveyn
işleme
74ff39488b

+ 1 - 1
extension/core/bg/business.js

@@ -236,7 +236,7 @@ singlefile.extension.core.bg.business = (() => {
 	function cancelTask(taskInfo) {
 		const tabId = taskInfo.tab.id;
 		taskInfo.cancelled = true;
-		singlefile.extension.core.bg.tabs.sendMessage(tabId, { method: "content.cancelSave", resetZoomLevel: taskInfo.options.loadDeferredImagesKeepZoomLevel });
+		singlefile.extension.core.bg.tabs.sendMessage(tabId, { method: "content.cancelSave", options: { loadDeferredImagesKeepZoomLevel: taskInfo.options.loadDeferredImagesKeepZoomLevel } });
 		if (taskInfo.cancel) {
 			taskInfo.cancel();
 		}

+ 2 - 6
extension/core/content/content-main.js

@@ -56,9 +56,7 @@ this.singlefile.extension.core.content.main = this.singlefile.extension.core.con
 					ui.onEndPage();
 					browser.runtime.sendMessage({ method: "ui.processCancelled" });
 				}
-				if (message.resetZoomLevel) {
-					singlefile.lib.processors.lazy.content.loader.resetZoomLevel();
-				}
+				singlefile.lib.processors.lazy.content.loader.resetZoomLevel(message.options);
 				return {};
 			}
 			if (message.method == "content.getSelectedLinks") {
@@ -145,9 +143,7 @@ this.singlefile.extension.core.content.main = this.singlefile.extension.core.con
 			if (!processor.cancelled) {
 				if (event.type == event.RESOURCES_INITIALIZED) {
 					maxIndex = event.detail.max;
-					if (options.loadDeferredImagesKeepZoomLevel) {
-						singlefile.lib.processors.lazy.content.loader.resetZoomLevel();
-					}
+					singlefile.lib.processors.lazy.content.loader.resetZoomLevel(options);
 				}
 				if (event.type == event.RESOURCES_INITIALIZED || event.type == event.RESOURCE_LOADED) {
 					if (event.type == event.RESOURCE_LOADED) {

+ 1 - 3
lib/single-file/index.js

@@ -68,9 +68,7 @@ this.singlefile = this.singlefile || {
 			options.insertCanonicalLink = true;
 			options.onprogress = event => {
 				if (event.type === event.RESOURCES_INITIALIZED) {
-					if (options.loadDeferredImagesKeepZoomLevel) {
-						this.processors.lazy.content.loader.resetZoomLevel();
-					}
+					this.processors.lazy.content.loader.resetZoomLevel(options);
 				}
 			};
 			const processor = new this.SingleFile(options);

+ 13 - 12
lib/single-file/processors/hooks/content/content-hooks-frames-web.js

@@ -29,7 +29,8 @@
 	const LOAD_DEFERRED_IMAGES_END_EVENT = "single-file-load-deferred-images-end";
 	const LOAD_DEFERRED_IMAGES_KEEP_ZOOM_LEVEL_START_EVENT = "single-file-load-deferred-images-keep-zoom-level-start";
 	const LOAD_DEFERRED_IMAGES_KEEP_ZOOM_LEVEL_END_EVENT = "single-file-load-deferred-images-keep-zoom-level-end";
-	const LOAD_DEFERRED_IMAGES_RESET_ZOOM_LEVEL_END_EVENT = "single-file-load-deferred-images-keep-zoom-level-reset";
+	const LOAD_DEFERRED_IMAGES_RESET_ZOOM_LEVEL_EVENT = "single-file-load-deferred-images-keep-zoom-level-reset";
+	const LOAD_DEFERRED_IMAGES_RESET_EVENT = "single-file-load-deferred-images-reset";
 	const BLOCK_COOKIES_START_EVENT = "single-file-block-cookies-start";
 	const BLOCK_COOKIES_END_EVENT = "single-file-block-cookies-end";
 	const BLOCK_STORAGE_START_EVENT = "single-file-block-storage-start";
@@ -183,8 +184,8 @@
 
 	addEventListener(LOAD_DEFERRED_IMAGES_END_EVENT, () => loadDeferredImagesEnd());
 	addEventListener(LOAD_DEFERRED_IMAGES_KEEP_ZOOM_LEVEL_END_EVENT, () => loadDeferredImagesEnd(true));
-	addEventListener(LOAD_DEFERRED_IMAGES_RESET_ZOOM_LEVEL_END_EVENT, () => {
-		const scrollingElement = document.scrollingElement || document.documentElement;
+	addEventListener(LOAD_DEFERRED_IMAGES_RESET_EVENT, resetScreenSize);
+	addEventListener(LOAD_DEFERRED_IMAGES_RESET_ZOOM_LEVEL_EVENT, () => {
 		const transform = document.documentElement.style.getPropertyValue("-sf-transform");
 		const transformPriority = document.documentElement.style.getPropertyPriority("-sf-transform");
 		const transformOrigin = document.documentElement.style.getPropertyValue("-sf-transform-origin");
@@ -197,23 +198,15 @@
 		document.documentElement.style.removeProperty("-sf-transform");
 		document.documentElement.style.removeProperty("-sf-transform-origin");
 		document.documentElement.style.removeProperty("-sf-min-height");
-		delete scrollingElement.clientHeight;
-		delete scrollingElement.clientWidth;
-		delete screen.height;
-		delete screen.width;
+		resetScreenSize();
 	});
 
 	function loadDeferredImagesEnd(keepZoomLevel) {
-		const scrollingElement = document.scrollingElement || document.documentElement;
 		document.querySelectorAll("[" + LAZY_LOAD_ATTRIBUTE + "]").forEach(element => {
 			element.loading = "lazy";
 			element.removeAttribute(LAZY_LOAD_ATTRIBUTE);
 		});
 		if (!keepZoomLevel) {
-			delete scrollingElement.clientHeight;
-			delete scrollingElement.clientWidth;
-			delete screen.height;
-			delete screen.width;
 			if (window._singleFile_getBoundingClientRect) {
 				Element.prototype.getBoundingClientRect = window._singleFile_getBoundingClientRect;
 				window.innerHeight = window._singleFile_innerHeight;
@@ -233,6 +226,14 @@
 		}
 	}
 
+	function resetScreenSize() {
+		const scrollingElement = document.scrollingElement || document.documentElement;
+		delete scrollingElement.clientHeight;
+		delete scrollingElement.clientWidth;
+		delete screen.height;
+		delete screen.width;
+	}
+
 	addEventListener(BLOCK_COOKIES_START_EVENT, () => {
 		try {
 			document.__defineGetter__("cookie", () => { throw new Error("document.cookie temporary blocked by SingleFile"); });

+ 8 - 3
lib/single-file/processors/hooks/content/content-hooks-frames.js

@@ -29,7 +29,8 @@ this.singlefile.lib.processors.hooks.content.frames = this.singlefile.lib.proces
 	const LOAD_DEFERRED_IMAGES_END_EVENT = "single-file-load-deferred-images-end";
 	const LOAD_DEFERRED_IMAGES_KEEP_ZOOM_LEVEL_START_EVENT = "single-file-load-deferred-images-keep-zoom-level-start";
 	const LOAD_DEFERRED_IMAGES_KEEP_ZOOM_LEVEL_END_EVENT = "single-file-load-deferred-images-keep-zoom-level-end";
-	const LOAD_DEFERRED_IMAGES_RESET_ZOOM_LEVEL_END_EVENT = "single-file-load-deferred-images-keep-zoom-level-reset";
+	const LOAD_DEFERRED_IMAGES_RESET_ZOOM_LEVEL_EVENT = "single-file-load-deferred-images-keep-zoom-level-reset";
+	const LOAD_DEFERRED_IMAGES_RESET_EVENT = "single-file-load-deferred-images-reset";
 	const BLOCK_COOKIES_START_EVENT = "single-file-block-cookies-start";
 	const BLOCK_COOKIES_END_EVENT = "single-file-block-cookies-end";
 	const BLOCK_STORAGE_START_EVENT = "single-file-block-storage-start";
@@ -97,8 +98,12 @@ this.singlefile.lib.processors.hooks.content.frames = this.singlefile.lib.proces
 				dispatchEvent(new CustomEvent(LOAD_DEFERRED_IMAGES_END_EVENT));
 			}
 		},
-		loadDeferredImagesResetZoomLevel: () => {
-			dispatchEvent(new CustomEvent(LOAD_DEFERRED_IMAGES_RESET_ZOOM_LEVEL_END_EVENT));
+		loadDeferredImagesResetZoomLevel: options => {
+			if (options.loadDeferredImagesKeepZoomLevel) {
+				dispatchEvent(new CustomEvent(LOAD_DEFERRED_IMAGES_RESET_ZOOM_LEVEL_EVENT));
+			} else {
+				dispatchEvent(new CustomEvent(LOAD_DEFERRED_IMAGES_RESET_EVENT));
+			}
 		},
 		LOAD_IMAGE_EVENT,
 		IMAGE_LOADED_EVENT

+ 2 - 2
lib/single-file/processors/lazy/content/content-lazy-loader.js

@@ -44,10 +44,10 @@ this.singlefile.lib.processors.lazy.content.loader = this.singlefile.lib.process
 				}
 			}
 		},
-		resetZoomLevel: () => {
+		resetZoomLevel: options => {
 			const frames = singlefile.lib.processors.hooks.content.frames;
 			if (frames) {
-				frames.loadDeferredImagesResetZoomLevel();
+				frames.loadDeferredImagesResetZoomLevel(options);
 			}
 		}
 	};