Quellcode durchsuchen

cleanup page before serializing it

Gildas vor 7 Jahren
Ursprung
Commit
50c46684dc

+ 4 - 2
lib/single-file/doc-helper.js

@@ -30,7 +30,9 @@ this.docHelper = this.docHelper || (() => {
 		getCanvasData,
 		getEmptyStyleRulesText,
 		getDoctype,
-		WIN_ID_ATTRIBUTE_NAME
+		WIN_ID_ATTRIBUTE_NAME,
+		PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME,
+		REMOVED_CONTENT_ATTRIBUTE_NAME
 	};
 
 	function preProcessDoc(doc, win, options) {
@@ -61,7 +63,7 @@ this.docHelper = this.docHelper || (() => {
 	}
 
 	function postProcessDoc(doc, options) {
-		doc.head.querySelectorAll("disabled-noscript").forEach(element => {
+		doc.querySelectorAll("disabled-noscript").forEach(element => {
 			const noscriptElement = doc.createElement("noscript");
 			Array.from(element.childNodes).forEach(node => noscriptElement.appendChild(node));
 			element.parentElement.replaceChild(noscriptElement, element);

+ 6 - 0
lib/single-file/single-file-browser.js

@@ -152,6 +152,12 @@ this.SingleFile = this.SingleFile || (() => {
 		static winIdAttributeName() {
 			return docHelper.WIN_ID_ATTRIBUTE_NAME;
 		}
+		static preservedSpaceAttributeName() {
+			return docHelper.PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME;
+		}
+		static removedContentAttributeName() {
+			return docHelper.REMOVED_CONTENT_ATTRIBUTE_NAME;
+		}
 	}
 
 	return { getClass: () => SingleFileCore.getClass(Download, DOM, URL) };

+ 3 - 5
lib/single-file/single-file-core.js

@@ -24,8 +24,6 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 
 	const SELECTED_CONTENT_ATTRIBUTE_NAME = "data-single-file-selected-content";
 	const SELECTED_CONTENT_ROOT_ATTRIBUTE_NAME = "data-single-file-selected-content-root";
-	const REMOVED_CONTENT_ATTRIBUTE_NAME = "data-single-file-removed-content";
-	const PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME = "data-single-file-preserved-space-element";
 
 	let Download, DOM, URL;
 
@@ -288,6 +286,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 		}
 
 		getPageData() {
+			DOM.postProcessDoc(this.doc, this.options);
 			if (this.options.selected) {
 				const rootElement = this.doc.querySelector("[" + SELECTED_CONTENT_ROOT_ATTRIBUTE_NAME + "]");
 				if (rootElement) {
@@ -442,7 +441,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 		}
 
 		removeHiddenElements() {
-			const hiddenElements = this.doc.querySelectorAll("[" + REMOVED_CONTENT_ATTRIBUTE_NAME + "]");
+			const hiddenElements = this.doc.querySelectorAll("[" + DOM.removedContentAttributeName() + "]");
 			if (this.options.displayStats) {
 				this.stats.discarded.hiddenElements = hiddenElements.length;
 			}
@@ -464,11 +463,10 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 				if (this.options.displayStats) {
 					size = new Blob([this.doc.documentElement.outerHTML]).size;
 				}
-				DOM.htmlminiProcess(this.doc, { preservedSpaceAttributeName: PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME });
+				DOM.htmlminiProcess(this.doc, { preservedSpaceAttributeName: DOM.preservedSpaceAttributeName() });
 				if (this.options.displayStats) {
 					this.stats.discarded.htmlBytes += size - (new Blob([this.doc.documentElement.outerHTML]).size);
 				}
-				this.doc.querySelectorAll("[" + PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME + "]").forEach(element => element.removeAttribute(PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME));
 			}
 		}