Gildas 7 лет назад
Родитель
Сommit
99881372a2

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

@@ -25,7 +25,7 @@ this.singlefile.frame = this.singlefile.frame || (() => {
 	if (window != top) {
 		browser.runtime.onMessage.addListener(async message => {
 			if (message.processStartFrame) {
-				message.options.content = docHelper.getDoctype(document) + document.documentElement.outerHTML;
+				message.options.content = docHelper.serialize(document);
 				message.processStartFrame = null;
 				message.options.frameId = null;
 				message.processStart = true;

+ 10 - 10
lib/single-file/doc-helper.js

@@ -29,7 +29,7 @@ this.docHelper = this.docHelper || (() => {
 		postProcessDoc,
 		getCanvasData,
 		getEmptyStyleRulesText,
-		getDoctype,
+		serialize,
 		WIN_ID_ATTRIBUTE_NAME,
 		PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME,
 		REMOVED_CONTENT_ATTRIBUTE_NAME
@@ -104,24 +104,24 @@ this.docHelper = this.docHelper || (() => {
 		}
 	}
 
-	function getDoctype(doc) {
+	function serialize(doc) {
 		const docType = doc.doctype;
-		let docTypeStr;
+		let docTypeString = "";
 		if (docType) {
-			docTypeStr = "<!DOCTYPE " + docType.nodeName;
+			docTypeString = "<!DOCTYPE " + docType.nodeName;
 			if (docType.publicId) {
-				docTypeStr += " PUBLIC \"" + docType.publicId + "\"";
+				docTypeString += " PUBLIC \"" + docType.publicId + "\"";
 				if (docType.systemId) {
-					docTypeStr += " \"" + docType.systemId + "\"";
+					docTypeString += " \"" + docType.systemId + "\"";
 				}
 			} else if (docType.systemId) {
-				docTypeStr += " SYSTEM \"" + docType.systemId + "\"";
+				docTypeString += " SYSTEM \"" + docType.systemId + "\"";
 			} if (docType.internalSubset) {
-				docTypeStr += " [" + docType.internalSubset + "]";
+				docTypeString += " [" + docType.internalSubset + "]";
 			}
-			return docTypeStr + ">\n";
+			docTypeString += "> ";
 		}
-		return "";
+		return docTypeString + doc.documentElement.outerHTML;
 	}
 
 })();

+ 2 - 2
lib/single-file/frame-tree/content/frame-tree.js

@@ -78,7 +78,7 @@ this.FrameTree = this.FrameTree || (() => {
 				method: "FrameTree.getDataResponse",
 				windowId: message.windowId,
 				tabId: message.tabId,
-				content: docHelper.getDoctype(document) + document.documentElement.outerHTML,
+				content: docHelper.serialize(document),
 				emptyStyleRulesText: docHelper.getEmptyStyleRulesText(document),
 				canvasData: docHelper.getCanvasData(document),
 				baseURI: document.baseURI,
@@ -184,7 +184,7 @@ this.FrameTree = this.FrameTree || (() => {
 				setFramesWinId(MESSAGE_PREFIX, frameDoc.querySelectorAll("iframe, frame, object[type=\"text/html\"][data]"), options, index, frameWinId, frameWindow);
 				topWindow.addEventListener("message", onMessage, false);
 				docHelper.preProcessDoc(frameDoc, frameWindow, options);
-				content = docHelper.getDoctype(frameDoc) + frameDoc.documentElement.outerHTML;
+				content = docHelper.serialize(frameDoc);
 				emptyStyleRulesText = docHelper.getEmptyStyleRulesText(frameDoc);
 				canvasData = docHelper.getCanvasData(frameDoc);
 				docHelper.postProcessDoc(frameDoc, options);

+ 15 - 19
lib/single-file/serializer.js

@@ -54,28 +54,24 @@ this.serializer = this.serializer || (() => {
 
 	return {
 		process(doc, compressHTML) {
-			return getDoctype(doc) + (compressHTML ? serialize(doc.documentElement) : doc.documentElement.outerHTML);
+			const docType = doc.doctype;
+			let docTypeString = "";
+			if (docType) {
+				docTypeString = "<!DOCTYPE " + docType.nodeName;
+				if (docType.publicId) {
+					docTypeString += " PUBLIC \"" + docType.publicId + "\"";
+					if (docType.systemId)
+						docTypeString += " \"" + docType.systemId + "\"";
+				} else if (docType.systemId)
+					docTypeString += " SYSTEM \"" + docType.systemId + "\"";
+				if (docType.internalSubset)
+					docTypeString += " [" + docType.internalSubset + "]";
+				docTypeString += "> ";
+			}
+			return docTypeString + (compressHTML ? serialize(doc.documentElement) : doc.documentElement.outerHTML);
 		}
 	};
 
-	function getDoctype(doc) {
-		const docType = doc.doctype;
-		let docTypeString;
-		if (docType) {
-			docTypeString = "<!DOCTYPE " + docType.nodeName;
-			if (docType.publicId) {
-				docTypeString += " PUBLIC \"" + docType.publicId + "\"";
-				if (docType.systemId)
-					docTypeString += " \"" + docType.systemId + "\"";
-			} else if (docType.systemId)
-				docTypeString += " SYSTEM \"" + docType.systemId + "\"";
-			if (docType.internalSubset)
-				docTypeString += " [" + docType.internalSubset + "]";
-			return docTypeString + "> ";
-		}
-		return "";
-	}
-
 	function serialize(node) {
 		if (node.nodeType == Node.TEXT_NODE) {
 			return serializeTextNode(node);