Browse Source

added hidden option "useLegacyCommentHeader" (cf #388)

Former-commit-id: ffe93d30a0cac49dd18e9493b4f7dc3f34283c94
Gildas 5 năm trước cách đây
mục cha
commit
0ee94fe6a0

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

@@ -186,7 +186,9 @@ this.singlefile.extension.core.content.bootstrap = this.singlefile.extension.cor
 	}
 
 	async function openEditor(document) {
-		if (document.documentElement.firstChild.nodeType == Node.COMMENT_NODE && document.documentElement.firstChild.textContent.includes("Page saved with SingleFile")) {
+		const helper = singlefile.lib.helper;
+		if (document.documentElement.firstChild.nodeType == Node.COMMENT_NODE &&
+			(document.documentElement.firstChild.textContent.includes(helper.COMMENT_HEADER) || document.documentElement.firstChild.textContent.includes(helper.COMMENT_HEADER_LEGACY))) {
 			serializeShadowRoots(document);
 			const content = singlefile.lib.modules.serializer.process(document);
 			for (let blockIndex = 0; blockIndex * MAX_CONTENT_SIZE < content.length; blockIndex++) {

+ 1 - 1
lib/single-file/single-file-core.js

@@ -459,7 +459,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 			const url = util.parseURL(this.baseURI);
 			if (this.options.insertSingleFileComment) {
 				const infobarContent = (this.options.infobarContent || "").replace(/\\n/g, "\n").replace(/\\t/g, "\t");
-				const commentNode = this.doc.createComment("\n Page saved with SingleFile" +
+				const commentNode = this.doc.createComment("\n " + (this.options.useLegacyCommentHeader ? util.COMMENT_HEADER_LEGACY : util.COMMENT_HEADER) +
 					" \n url: " + this.options.saveUrl +
 					" \n saved date: " + this.options.saveDate +
 					(infobarContent ? " \n info: " + infobarContent : "") + "\n");

+ 5 - 1
lib/single-file/single-file-helper.js

@@ -56,6 +56,8 @@ this.singlefile.lib.helper = this.singlefile.lib.helper || (() => {
 		bolder: "700",
 		lighter: "100"
 	};
+	const COMMENT_HEADER = "Page saved with SingleFile";
+	const COMMENT_HEADER_LEGACY = "Archive processed by SingleFile";
 
 	addEventListener("single-file-user-script-init", () => singlefile.lib.helper.waitForUserScript = async eventPrefixName => {
 		const event = new CustomEvent(eventPrefixName + "-request", { cancelable: true });
@@ -90,7 +92,9 @@ this.singlefile.lib.helper = this.singlefile.lib.helper || (() => {
 		LAZY_SRC_ATTRIBUTE_NAME,
 		STYLESHEET_ATTRIBUTE_NAME,
 		SELECTED_CONTENT_ATTRIBUTE_NAME,
-		ASYNC_SCRIPT_ATTRIBUTE_NAME
+		ASYNC_SCRIPT_ATTRIBUTE_NAME,
+		COMMENT_HEADER,
+		COMMENT_HEADER_LEGACY
 	};
 
 	function initDoc(doc) {

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

@@ -202,7 +202,9 @@ this.singlefile.lib.util = this.singlefile.lib.util || (() => {
 				SHADOW_ROOT_ATTRIBUTE_NAME: helper.SHADOW_ROOT_ATTRIBUTE_NAME,
 				PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME: helper.PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME,
 				STYLESHEET_ATTRIBUTE_NAME: helper.STYLESHEET_ATTRIBUTE_NAME,
-				SELECTED_CONTENT_ATTRIBUTE_NAME: helper.SELECTED_CONTENT_ATTRIBUTE_NAME
+				SELECTED_CONTENT_ATTRIBUTE_NAME: helper.SELECTED_CONTENT_ATTRIBUTE_NAME,
+				COMMENT_HEADER: helper.COMMENT_HEADER,
+				COMMENT_HEADER_LEGACY: helper.COMMENT_HEADER_LEGACY
 			};
 
 			async function getContent(resourceURL, options) {