Selaa lähdekoodia

don't override existing url and date of the page

Gildas 5 vuotta sitten
vanhempi
sitoutus
bdc4df63b2
2 muutettua tiedostoa jossa 12 lisäystä ja 3 poistoa
  1. 1 1
      lib/single-file/modules/html-minifier.js
  2. 11 2
      lib/single-file/single-file-core.js

+ 1 - 1
lib/single-file/modules/html-minifier.js

@@ -211,7 +211,7 @@ this.singlefile.lib.modules.htmlMinifier = this.singlefile.lib.modules.htmlMinif
 	}
 
 	function removeComments(node) {
-		if (node.nodeType == Node_COMMENT_NODE) {
+		if (node.nodeType == Node_COMMENT_NODE && node.parentElement.tagName != "HTML") {
 			return !node.textContent.toLowerCase().trim().startsWith("[if");
 		}
 	}

+ 11 - 2
lib/single-file/single-file-core.js

@@ -463,10 +463,19 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 			util.postProcessDoc(this.doc);
 			const url = util.parseURL(this.baseURI);
 			if (this.options.insertSingleFileComment) {
+				const firstComment = this.doc.documentElement.firstChild;
+				let infobarURL = this.options.saveUrl, infobarSaveDate = this.options.saveDate;
+				if (firstComment.nodeType == 8 && (firstComment.textContent.includes(util.COMMENT_HEADER_LEGACY) || firstComment.textContent.includes(util.COMMENT_HEADER))) {
+					const info = this.doc.documentElement.firstChild.textContent.split("\n");
+					const [, , url, saveDate] = info;
+					infobarURL = url.split("url: ")[1];
+					infobarSaveDate = saveDate.split("saved date: ")[1];
+					firstComment.remove();
+				}
 				const infobarContent = (this.options.infobarContent || "").replace(/\\n/g, "\n").replace(/\\t/g, "\t");
 				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 +
+					" \n url: " + infobarURL +
+					" \n saved date: " + infobarSaveDate +
 					(infobarContent ? " \n info: " + infobarContent : "") + "\n");
 				this.doc.documentElement.insertBefore(commentNode, this.doc.documentElement.firstChild);
 			}