소스 검색

support filename options loaded from the page
(see https://github.com/gildas-lormeau/SingleFile/issues/1280)

Gildas 2 년 전
부모
커밋
4471b78795

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
lib/single-file-bootstrap.js


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
lib/single-file-extension-background.js


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
lib/single-file-extension-editor-helper.js


+ 21 - 3
lib/single-file-extension-editor.js

@@ -37,6 +37,7 @@
 		const BUTTON_CLOSE_URL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAgMAAAAOFJJnAAABhGlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AcxV9TtaIVETuIOASsThZERRylikWwUNoKrTqYXPohNGlIUlwcBdeCgx+LVQcXZ10dXAVB8APEydFJ0UVK/F9SaBHjwXE/3t173L0DhFqJqWbbOKBqlpGMRcVMdkUMvKIbfQCG0SExU4+nFtLwHF/38PH1LsKzvM/9OXqUnMkAn0g8y3TDIl4nnt60dM77xCFWlBTic+Ixgy5I/Mh12eU3zgWHBZ4ZMtLJOeIQsVhoYbmFWdFQiaeIw4qqUb6QcVnhvMVZLVVY4578hcGctpziOs0hxLCIOBIQIaOCDZRgIUKrRoqJJO1HPfyDjj9BLplcG2DkmEcZKiTHD/4Hv7s185MTblIwCrS/2PbHCBDYBepV2/4+tu36CeB/Bq60pr9cA2Y+Sa82tfAR0LsNXFw3NXkPuNwBBp50yZAcyU9TyOeB9zP6pizQfwt0rbq9NfZx+gCkqaulG+DgEBgtUPaax7s7W3v790yjvx825XKP2aKCdAAAAAlwSFlzAAAuIwAALiMBeKU/dgAAAAd0SU1FB+QLEQA6Na1u6IUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAACVBMVEUAAAAAAACKioqjwG1pAAAAAXRSTlMAQObYZgAAAAFiS0dEAmYLfGQAAABlSURBVBhXTc/BEUQhCAPQ58ES6McSPED/rfwDI7vOMCoJIeGd6CvFgZXiwk47Ia5VUKdrVXcb39kfqxqmTg+I2xJ2tqhVTaGaQjTl7/GgIc/4CL4Vs3RsjLFndcxPnAn4iww8A3yQjRZjti1t6AAAAABJRU5ErkJggg==";
 		const SHADOWROOT_ATTRIBUTE_NAME = "shadowrootmode";
 		const SCRIPT_TEMPLATE_SHADOW_ROOT = "data-template-shadow-root";
+		const SCRIPT_OPTIONS = "data-single-file-options";
 		const NOTE_TAGNAME = "single-file-note";
 		const NOTE_CLASS = "note";
 		const NOTE_MASK_CLASS = "note-mask";
@@ -1075,11 +1076,20 @@ pre code {
 				if (initScriptContent) {
 					content = content.replace(/<script data-template-shadow-root src.*?<\/script>/g, initScriptContent);
 				}
+				let filename;
+				const pageOptions = loadOptionsFromPage(document);
+				if (pageOptions) {
+					pageOptions.backgroundSave = message.backgroundSave;
+					pageOptions.saveDate = new Date(pageOptions.saveDate);
+					pageOptions.visitDate = new Date(pageOptions.visitDate);
+					filename = await singlefile.helper.formatFilename(content, document, pageOptions);
+				}
 				if (pageCompressContent) {
 					const viewport = document.head.querySelector("meta[name=viewport]");
 					window.parent.postMessage(JSON.stringify({
 						method: "setContent",
 						content,
+						filename,
 						title: document.title,
 						doctype: singlefile.helper.getDoctypeString(document),
 						url: pageUrl,
@@ -1089,9 +1099,9 @@ pre code {
 					}), "*");
 				} else {
 					if (message.foregroundSave) {
-						if (message.filename && message.filename.length) {
+						if (filename || (message.filename && message.filename.length)) {
 							const link = document.createElement("a");
-							link.download = message.filename;
+							link.download = filename || message.filename;
 							link.href = URL.createObjectURL(new Blob([content], { type: "text/html" }));
 							link.dispatchEvent(new MouseEvent("click"));
 						}
@@ -1099,7 +1109,8 @@ pre code {
 					} else {
 						window.parent.postMessage(JSON.stringify({
 							method: "setContent",
-							content
+							content,
+							filename
 						}), "*");
 					}
 				}
@@ -1253,6 +1264,13 @@ pre code {
 			}
 		}
 
+		function loadOptionsFromPage(doc) {
+			const optionsElement = doc.body.querySelector("script[type=\"application/json\"][" + SCRIPT_OPTIONS + "]");
+			if (optionsElement) {
+				return JSON.parse(optionsElement.textContent);
+			}
+		}
+
 		async function initPage() {
 			document.querySelectorAll("iframe").forEach(element => {
 				const pointerEvents = "pointer-events";

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
lib/single-file-frames.js


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
lib/single-file.js


+ 7 - 2
package-lock.json

@@ -10,7 +10,7 @@
 			"license": "AGPL-3.0-or-later",
 			"dependencies": {
 				"single-file-cli": "1.1.28",
-				"single-file-core": "1.2.35"
+				"single-file-core": "1.2.36"
 			},
 			"bin": {
 				"single-file": "cli/single-file"
@@ -1667,11 +1667,16 @@
 				"single-file": "single-file"
 			}
 		},
-		"node_modules/single-file-core": {
+		"node_modules/single-file-cli/node_modules/single-file-core": {
 			"version": "1.2.35",
 			"resolved": "https://registry.npmjs.org/single-file-core/-/single-file-core-1.2.35.tgz",
 			"integrity": "sha512-qcC16Y57lKO4A+HK50OssicTtYM9DrnZ9TabolDbiu7lbb7ZJ+3ld4jJa4utpU0T5pIebYDtAhc4X/pNvHlGJw=="
 		},
+		"node_modules/single-file-core": {
+			"version": "1.2.36",
+			"resolved": "https://registry.npmjs.org/single-file-core/-/single-file-core-1.2.36.tgz",
+			"integrity": "sha512-66x38gx1phJIK3Ch/eFoeV4N7xq/WlDJDu84RwcuhlEpqQ8apqAFCR+cp5Jc6yuyOlwBcRzkruvPxWIayw6ffw=="
+		},
 		"node_modules/smart-buffer": {
 			"version": "4.2.0",
 			"resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz",

+ 1 - 1
package.json

@@ -12,7 +12,7 @@
 		"single-file": "./cli/single-file"
 	},
 	"dependencies": {
-		"single-file-core": "1.2.35",
+		"single-file-core": "1.2.36",
 		"single-file-cli": "1.1.28"
 	},
 	"devDependencies": {

+ 3 - 2
src/ui/bg/ui-editor.js

@@ -292,7 +292,7 @@ addEventListener("message", event => {
 					pageData.doctype = message.doctype;
 					pageData.viewport = message.viewport;
 					pageData.url = message.url;
-					pageData.filename = tabData.filename;
+					pageData.filename = message.filename || tabData.filename;
 					if (message.foregroundSave) {
 						tabData.options.backgroundSave = false;
 						tabData.options.foregroundSave = true;
@@ -302,7 +302,7 @@ addEventListener("message", event => {
 		} else {
 			const pageData = {
 				content: message.content,
-				filename: tabData.filename
+				filename: message.filename || tabData.filename
 			};
 			tabData.options.compressContent = false;
 			download.downloadPage(pageData, tabData.options);
@@ -510,6 +510,7 @@ function savePage() {
 		method: "getContent",
 		compressHTML: tabData.options.compressHTML,
 		includeInfobar: tabData.options.includeInfobar,
+		backgroundSave: tabData.options.backgroundSave,
 		updatedResources,
 		filename: tabData.filename,
 		foregroundSave: FOREGROUND_SAVE

+ 21 - 3
src/ui/content/content-ui-editor-web.js

@@ -34,6 +34,7 @@
 	const BUTTON_CLOSE_URL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAgMAAAAOFJJnAAABhGlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AcxV9TtaIVETuIOASsThZERRylikWwUNoKrTqYXPohNGlIUlwcBdeCgx+LVQcXZ10dXAVB8APEydFJ0UVK/F9SaBHjwXE/3t173L0DhFqJqWbbOKBqlpGMRcVMdkUMvKIbfQCG0SExU4+nFtLwHF/38PH1LsKzvM/9OXqUnMkAn0g8y3TDIl4nnt60dM77xCFWlBTic+Ixgy5I/Mh12eU3zgWHBZ4ZMtLJOeIQsVhoYbmFWdFQiaeIw4qqUb6QcVnhvMVZLVVY4578hcGctpziOs0hxLCIOBIQIaOCDZRgIUKrRoqJJO1HPfyDjj9BLplcG2DkmEcZKiTHD/4Hv7s185MTblIwCrS/2PbHCBDYBepV2/4+tu36CeB/Bq60pr9cA2Y+Sa82tfAR0LsNXFw3NXkPuNwBBp50yZAcyU9TyOeB9zP6pizQfwt0rbq9NfZx+gCkqaulG+DgEBgtUPaax7s7W3v790yjvx825XKP2aKCdAAAAAlwSFlzAAAuIwAALiMBeKU/dgAAAAd0SU1FB+QLEQA6Na1u6IUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAACVBMVEUAAAAAAACKioqjwG1pAAAAAXRSTlMAQObYZgAAAAFiS0dEAmYLfGQAAABlSURBVBhXTc/BEUQhCAPQ58ES6McSPED/rfwDI7vOMCoJIeGd6CvFgZXiwk47Ia5VUKdrVXcb39kfqxqmTg+I2xJ2tqhVTaGaQjTl7/GgIc/4CL4Vs3RsjLFndcxPnAn4iww8A3yQjRZjti1t6AAAAABJRU5ErkJggg==";
 	const SHADOWROOT_ATTRIBUTE_NAME = "shadowrootmode";
 	const SCRIPT_TEMPLATE_SHADOW_ROOT = "data-template-shadow-root";
+	const SCRIPT_OPTIONS = "data-single-file-options";
 	const NOTE_TAGNAME = "single-file-note";
 	const NOTE_CLASS = "note";
 	const NOTE_MASK_CLASS = "note-mask";
@@ -1072,11 +1073,20 @@ pre code {
 			if (initScriptContent) {
 				content = content.replace(/<script data-template-shadow-root src.*?<\/script>/g, initScriptContent);
 			}
+			let filename;
+			const pageOptions = loadOptionsFromPage(document);
+			if (pageOptions) {
+				pageOptions.backgroundSave = message.backgroundSave;
+				pageOptions.saveDate = new Date(pageOptions.saveDate);
+				pageOptions.visitDate = new Date(pageOptions.visitDate);
+				filename = await singlefile.helper.formatFilename(content, document, pageOptions);
+			}
 			if (pageCompressContent) {
 				const viewport = document.head.querySelector("meta[name=viewport]");
 				window.parent.postMessage(JSON.stringify({
 					method: "setContent",
 					content,
+					filename,
 					title: document.title,
 					doctype: singlefile.helper.getDoctypeString(document),
 					url: pageUrl,
@@ -1086,9 +1096,9 @@ pre code {
 				}), "*");
 			} else {
 				if (message.foregroundSave) {
-					if (message.filename && message.filename.length) {
+					if (filename || (message.filename && message.filename.length)) {
 						const link = document.createElement("a");
-						link.download = message.filename;
+						link.download = filename || message.filename;
 						link.href = URL.createObjectURL(new Blob([content], { type: "text/html" }));
 						link.dispatchEvent(new MouseEvent("click"));
 					}
@@ -1096,7 +1106,8 @@ pre code {
 				} else {
 					window.parent.postMessage(JSON.stringify({
 						method: "setContent",
-						content
+						content,
+						filename
 					}), "*");
 				}
 			}
@@ -1250,6 +1261,13 @@ pre code {
 		}
 	}
 
+	function loadOptionsFromPage(doc) {
+		const optionsElement = doc.body.querySelector("script[type=\"application/json\"][" + SCRIPT_OPTIONS + "]");
+		if (optionsElement) {
+			return JSON.parse(optionsElement.textContent);
+		}
+	}
+
 	async function initPage() {
 		document.querySelectorAll("iframe").forEach(element => {
 			const pointerEvents = "pointer-events";

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.