Răsfoiți Sursa

don't inject additional content scripts for autosave

Gildas 7 ani în urmă
părinte
comite
ac88122f77

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

@@ -203,7 +203,6 @@ singlefile.core = (() => {
 	}
 
 	async function autoSaveStart(tab, options) {
-		await executeScripts(tab.id, getContentScriptFiles(options), false);
 		await browser.tabs.sendMessage(tab.id, { autoSavePage: true, options });
 	}
 

+ 26 - 3
extension/core/content/content-autosave.js

@@ -22,22 +22,45 @@
 
 this.singlefile.autosave = this.singlefile.autosave || (async () => {
 
-	let listenerAdded, options;
+	let listenerAdded, options, autoSaveTimeout;
 	refresh();
 	browser.runtime.onMessage.addListener(message => {
+		if (message.autoSavePage) {
+			autoSavePage();
+		}
 		if (message.autoSaveUnloadEnabled) {
 			refresh();
 		}
 	});
 	return {};
 
+	async function autoSavePage() {
+		const [autoSaveEnabled, options] = await Promise.all([browser.runtime.sendMessage({ isAutoSaveEnabled: true }), browser.runtime.sendMessage({ getConfig: true })]);
+		if (autoSaveEnabled) {
+			if (options.autoSaveDelay && !autoSaveTimeout) {
+				autoSaveTimeout = setTimeout(() => {
+					autoSavePage();
+				}, options.autoSaveDelay * 1000);
+			} else {
+				const docData = docHelper.preProcessDoc(document, window, options);
+				let framesData = [];
+				if (!options.removeFrames && this.frameTree) {
+					framesData = await frameTree.getAsync(options);
+				}
+				browser.runtime.sendMessage({ processContent: true, content: docHelper.serialize(document, false), canvasData: docData.canvasData, stylesheetContents: docData.stylesheetContents, framesData, url: location.href });
+				docHelper.postProcessDoc(document, window);
+				singlefile.pageAutoSaved = true;
+			}
+		}
+	}
+
 	async function refresh() {
 		const [autoSaveEnabled, config] = await Promise.all([browser.runtime.sendMessage({ isAutoSaveEnabled: true }), browser.runtime.sendMessage({ getConfig: true })]);
 		options = config;
-		enable(autoSaveEnabled && (config.autoSaveUnload || config.autoSaveLoadOrUnload));
+		enableAutoSaveUnload(autoSaveEnabled && (config.autoSaveUnload || config.autoSaveLoadOrUnload));
 	}
 
-	function enable(enabled) {
+	function enableAutoSaveUnload(enabled) {
 		if (enabled) {
 			if (!listenerAdded) {
 				addEventListener("unload", onUnload);

+ 1 - 25
extension/core/content/content.js

@@ -18,20 +18,16 @@
  *   along with SingleFile.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-/* global browser, SingleFile, singlefile, frameTree, document, Blob, MouseEvent, getSelection, prompt, addEventListener, Node, window, docHelper, location */
+/* global browser, SingleFile, singlefile, frameTree, document, Blob, MouseEvent, getSelection, prompt, addEventListener, Node, window */
 
 this.singlefile.top = this.singlefile.top || (() => {
 
 	let processing = false;
-	let autoSaveTimeout;
 
 	browser.runtime.onMessage.addListener(message => {
 		if (message.savePage) {
 			savePage(message);
 		}
-		if (message.autoSavePage) {
-			autoSavePage();
-		}
 	});
 
 	addEventListener("message", event => {
@@ -44,26 +40,6 @@ this.singlefile.top = this.singlefile.top || (() => {
 	});
 	return true;
 
-	async function autoSavePage() {
-		const [autoSaveEnabled, options] = await Promise.all([browser.runtime.sendMessage({ isAutoSaveEnabled: true }), browser.runtime.sendMessage({ getConfig: true })]);
-		if (autoSaveEnabled) {
-			if (options.autoSaveDelay && !autoSaveTimeout) {
-				autoSaveTimeout = setTimeout(() => {
-					autoSavePage();
-				}, options.autoSaveDelay * 1000);
-			} else {
-				const docData = docHelper.preProcessDoc(document, window, options);
-				let framesData = [];
-				if (!options.removeFrames && this.frameTree) {
-					framesData = await frameTree.getAsync(options);
-				}
-				browser.runtime.sendMessage({ processContent: true, content: docHelper.serialize(document, false), canvasData: docData.canvasData, stylesheetContents: docData.stylesheetContents, framesData, url: location.href });
-				docHelper.postProcessDoc(document, window);
-				singlefile.pageAutoSaved = true;
-			}
-		}
-	}
-
 	async function savePage(message) {
 		const options = message.options;
 		if (!processing && !options.frameId) {