Переглянути джерело

try to get some frame data when saving on unload

Gildas 7 роки тому
батько
коміт
036cb217ad

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

@@ -81,11 +81,11 @@ singlefile.core = (() => {
 		const options = await singlefile.config.get();
 		options.content = message.content;
 		options.url = message.url;
+		options.framesData = message.framesData;
 		options.canvasData = message.canvasData;
 		options.emptyStyleRulesText = message.emptyStyleRulesText;
 		options.insertSingleFileComment = true;
 		options.insertFaviconLink = true;
-		options.removeFrames = true;
 		options.backgroundTab = true;
 		options.autoSave = true;
 		options.onprogress = async event => {

+ 5 - 5
extension/core/content/content-autosave-unload.js

@@ -18,11 +18,11 @@
  *   along with SingleFile.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-/* global singlefile, browser, window, addEventListener, removeEventListener, document, location, docHelper */
+/* global singlefile, frameTree, browser, window, addEventListener, removeEventListener, document, location, docHelper */
 
 this.singlefile.autoSaveUnload = this.singlefile.autoSaveUnload || (async () => {
 
-	let listenerAdded, saveConfig;
+	let listenerAdded, options;
 	refreshAutoSaveUnload();
 	browser.runtime.onMessage.addListener(message => {
 		if (message.autoSaveUnloadEnabled) {
@@ -33,7 +33,7 @@ this.singlefile.autoSaveUnload = this.singlefile.autoSaveUnload || (async () =>
 
 	async function refreshAutoSaveUnload() {
 		const [autoSaveEnabled, config] = await Promise.all([browser.runtime.sendMessage({ isAutoSaveEnabled: true }), browser.runtime.sendMessage({ getConfig: true })]);
-		saveConfig = config;
+		options = config;
 		enableAutoSaveUnload(autoSaveEnabled && (config.autoSaveUnload || config.autoSaveLoadOrUnload));
 	}
 
@@ -51,8 +51,8 @@ this.singlefile.autoSaveUnload = this.singlefile.autoSaveUnload || (async () =>
 
 	function onUnload() {
 		if (!singlefile.pageAutoSaved) {
-			const docData = docHelper.preProcessDoc(document, window, saveConfig);
-			browser.runtime.sendMessage({ processContent: true, content: docHelper.serialize(document), canvasData: docData.canvasData, emptyStyleRulesText: docData.emptyStyleRulesText, url: location.href });
+			const docData = docHelper.preProcessDoc(document, window, options);
+			browser.runtime.sendMessage({ processContent: true, content: docHelper.serialize(document), canvasData: docData.canvasData, emptyStyleRulesText: docData.emptyStyleRulesText, framesData: this.frameTree && !options.removeFrames && frameTree.getSync(options), url: location.href });
 		}
 	}
 

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

@@ -78,7 +78,7 @@ this.singlefile.top = this.singlefile.top || (() => {
 		options.insertFaviconLink = true;
 		options.jsEnabled = true;
 		if (!options.removeFrames && this.frameTree) {
-			options.framesData = await frameTree.get(options);
+			options.framesData = await frameTree.getAsync(options);
 		}
 		options.doc = document;
 		options.win = window;

+ 9 - 6
extension/ui/pages/help.html

@@ -220,10 +220,12 @@
 				<p>Auto-save</p>
 				<ul>
 					<li>
-						<span class="option">auto-save on page load or on page unload as fallback</span>
+						<span class="option">auto-save on page load or on page </span>
 						<p>Check this option to auto-save pages after being loaded. If you browse to another page before the page is fully loaded
 							then the page will be saved just before being unloaded. With this option active, you are guaranteed pages will always
-							be saved. Pages saved before being unloaded will not contain frame contents (if you unchecked "remove frames").</p>
+							be saved but some frame contents may be missing (if you unchecked "remove frames") when pages are saved before being
+							unloaded.
+						</p>
 					</li>
 					<p class="notice">It is recommended to
 						<u>check</u> this option</p>
@@ -236,14 +238,15 @@
 					<li>
 						<span class="option">auto-save on page unload</span>
 						<p>Check this option to auto-save pages before being unloaded instead of saving pages after being loaded. With this option
-							active, you are guaranteed pages will always be saved but they will never contain frame contents (if you unchecked
-							"remove frames").</p>
+							active, you are guaranteed pages will always be saved but some frame contents may be missing (if you unchecked "remove
+							frames").
+						</p>
 					</li>
 
 					<li>
 						<span class="option">auto-save wait delay after load (sec.)</span>
-						<p>Specify the amount of time in seconds to wait before saving a page when the "auto-save on page load or on page unload
-							as fallback" or "auto-save on page load" is checked.
+						<p>Specify the amount of time in seconds to wait before saving a page when the "auto-save on page load or on page unload"
+							or "auto-save on page load" is checked.
 						</p>
 					</li>
 				</ul>

+ 1 - 1
extension/ui/pages/options.html

@@ -100,7 +100,7 @@
 	<details>
 		<summary>Auto-save</summary>
 		<div class="option">
-			<label for="autoSaveLoadInput">auto-save on page load or on page unload as fallback</label>
+			<label for="autoSaveLoadInput">auto-save on page load or on page unload</label>
 			<input type="checkbox" id="autoSaveLoadOrUnloadInput">
 		</div>
 		<div class="option">

+ 8 - 1
lib/single-file/frame-tree.js

@@ -46,7 +46,7 @@ this.frameTree = this.frameTree || (() => {
 		}
 	}, false);
 	return {
-		get: async options => {
+		getAsync: async options => {
 			const sessionId = options.sessionId;
 			options = JSON.parse(JSON.stringify(options));
 			return new Promise(resolve => {
@@ -54,6 +54,13 @@ this.frameTree = this.frameTree || (() => {
 				initRequest({ windowId, sessionId, options });
 			});
 		},
+		getSync: options => {
+			const sessionId = options.sessionId;
+			options = JSON.parse(JSON.stringify(options));
+			sessions.set(sessionId, { frames: [] });
+			initRequest({ windowId, sessionId, options });
+			return sessions.get(sessionId);
+		},
 		initResponse
 	};