Просмотр исходного кода

added option "userScriptEnabled" (cf #279)

Former-commit-id: bb70d14d87029c1969e62d25c4ec7316ab69f249
Gildas 6 лет назад
Родитель
Сommit
e9d2e3d73d

+ 2 - 1
extension/core/bg/config.js

@@ -78,7 +78,8 @@ singlefile.extension.core.bg.config = (() => {
 		groupDuplicateImages: true,
 		saveRawPage: false,
 		saveToClipboard: false,
-		resolveFragmentIdentifierURLs: false
+		resolveFragmentIdentifierURLs: false,
+		userScriptEnabled: false
 	};
 
 	let pendingUpgradePromise = upgrade();

+ 4 - 4
extension/core/content/content-bootstrap.js

@@ -79,15 +79,15 @@ this.singlefile.extension.core.content.bootstrap = this.singlefile.extension.cor
 				await new Promise(resolve => autoSaveTimeout = setTimeout(resolve, options.autoSaveDelay * 1000));
 				await autoSavePage();
 			} else {
-				const docData = helper.preProcessDoc(document, window, options);
 				let frames = [];
 				autoSaveTimeout = null;
 				if (!options.removeFrames && singlefile.lib.frameTree.content.frames && window.frames && window.frames.length) {
 					frames = await singlefile.lib.frameTree.content.frames.getAsync(options);
 				}
-				if (singlefile.waitForUserScript) {
+				if (options.userScriptEnabled && singlefile.waitForUserScript) {
 					await singlefile.waitForUserScript();
 				}
+				const docData = helper.preProcessDoc(document, window, options);
 				savePage(docData, frames);
 				helper.postProcessDoc(document, docData.markedElements);
 				pageAutoSaved = true;
@@ -113,14 +113,14 @@ this.singlefile.extension.core.content.bootstrap = this.singlefile.extension.cor
 	function onUnload() {
 		const helper = singlefile.lib.helper;
 		if (!pageAutoSaved || options.autoSaveUnload) {
-			const docData = helper.preProcessDoc(document, window, options);
 			let frames = [];
 			if (!options.removeFrames && singlefile.lib.frameTree.content.frames && window.frames && window.frames.length) {
 				frames = singlefile.lib.frameTree.content.frames.getSync(options);
 			}
-			if (singlefile.waitForUserScript) {
+			if (options.userScriptEnabled && singlefile.waitForUserScript) {
 				singlefile.waitForUserScript();
 			}
+			const docData = helper.preProcessDoc(document, window, options);
 			savePage(docData, frames);
 		}
 	}

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

@@ -185,7 +185,7 @@ this.singlefile.extension.core.content.main = this.singlefile.extension.core.con
 			options.doc = document;
 		}
 		if (!processor.cancelled) {
-			if (singlefile.waitForUserScript) {
+			if (options.userScriptEnabled && singlefile.waitForUserScript) {
 				await singlefile.waitForUserScript();
 			}
 			await processor.run();