1
0
Эх сурвалжийг харах

removed sessionId from constants

Gildas 7 жил өмнө
parent
commit
07bf5d0955

+ 4 - 4
lib/frame-tree/frame-tree.js

@@ -131,7 +131,7 @@ this.frameTree = this.frameTree || (() => {
 		const framesData = [];
 		frameElements.forEach((frameElement, frameIndex) => {
 			const windowId = parentWindowId + WINDOW_ID_SEPARATOR + frameIndex;
-			frameElement.setAttribute(docHelper.windowIdAttributeName(options.sessionId), windowId);
+			frameElement.setAttribute(docHelper.WIN_ID_ATTRIBUTE_NAME, windowId);
 			framesData.push({ windowId });
 			try {
 				sendMessage(frameElement.contentWindow, { method: INIT_REQUEST_MESSAGE, windowId, sessionId, options });
@@ -141,7 +141,7 @@ this.frameTree = this.frameTree || (() => {
 			setTimeout(async () => {
 				let frameDoc;
 				if (frameElement.src && frameElement.src.match(PREFIX_VALID_FRAME_URL)) {
-					frameDoc = await getFrameDoc(frameElement.src, parentWindowId, options);
+					frameDoc = await getFrameDoc(frameElement.src, parentWindowId);
 				}
 				if (frameDoc) {
 					sendInitResponse({ framesData: [getFrameData(frameDoc, null, windowId, options)] });
@@ -196,7 +196,7 @@ this.frameTree = this.frameTree || (() => {
 		}
 	}
 
-	async function getFrameDoc(frameUrl, parentWindowId, options) {
+	async function getFrameDoc(frameUrl, parentWindowId) {
 		let frameContent;
 		try {
 			frameContent = await ((typeof superFetch !== "undefined" && superFetch.fetch) || fetch)(frameUrl);
@@ -240,7 +240,7 @@ this.frameTree = this.frameTree || (() => {
 				const frameElements = doc.documentElement.querySelectorAll(FRAMES_CSS_SELECTOR);
 				frameElements.forEach((frameElement, frameIndex) => {
 					const windowId = parentWindowId + WINDOW_ID_SEPARATOR + frameIndex;
-					frameElement.setAttribute(docHelper.windowIdAttributeName(options.sessionId), windowId);
+					frameElement.setAttribute(docHelper.WIN_ID_ATTRIBUTE_NAME, windowId);
 				});
 				return doc;
 			}

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

@@ -189,7 +189,7 @@ this.htmlMinifier = this.htmlMinifier || (() => {
 	function collapseWhitespace(node, options) {
 		if (node.nodeType == Node_TEXT_NODE) {
 			let element = node.parentElement;
-			const spacePreserved = element.getAttribute(options.preservedSpaceAttributeName) == "";
+			const spacePreserved = element.getAttribute(options.PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME) == "";
 			const textContent = node.textContent;
 			let noWhitespace = !spacePreserved && noWhitespaceCollapse(element);
 			while (noWhitespace) {

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

@@ -439,7 +439,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 				this.doc.body.querySelectorAll(":not(svg) title, meta, link[href][rel*=\"icon\"]").forEach(element => element instanceof this.options.win.HTMLElement && this.doc.head.appendChild(element));
 			}
 			if (this.options.imageData) {
-				const dataAttributeName = docUtil.imagesAttributeName(this.options.sessionId);
+				const dataAttributeName = docUtil.IMAGE_ATTRIBUTE_NAME;
 				this.doc.querySelectorAll("img").forEach(imgElement => {
 					const imgData = this.options.imageData[Number(imgElement.getAttribute(dataAttributeName))];
 					if (this.options.removeHiddenElements && imgData.size && !imgData.size.pxWidth && !imgData.size.pxHeight) {
@@ -469,13 +469,13 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 
 		insertShadowRootContents() {
 			if (this.options.shadowRootContents) {
-				this.doc.querySelectorAll("[" + docUtil.shadowRootAttributeName(this.options.sessionId) + "]").forEach((element, elementIndex) => {
+				this.doc.querySelectorAll("[" + docUtil.SHADOW_ROOT_ATTRIBUTE_NAME + "]").forEach((element, elementIndex) => {
 					const elementInfo = this.options.shadowRootContents[elementIndex];
 					if (elementInfo) {
 						const frameElement = this.doc.createElement("iframe");
 						frameElement.setAttribute("style", "all:initial!important;border:0!important;width:100%!important;height:" + elementInfo.height + "px!important");
 						const windowId = "shadow-" + this.options.framesData.length;
-						frameElement.setAttribute(docUtil.windowIdAttributeName(this.options.sessionId), windowId);
+						frameElement.setAttribute(docUtil.WIN_ID_ATTRIBUTE_NAME, windowId);
 						this.options.framesData.push({ windowId, content: elementInfo.content, baseURI: this.baseURI });
 						element.appendChild(frameElement);
 					}
@@ -617,22 +617,22 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 
 		setInputValues() {
 			this.doc.querySelectorAll("input").forEach(input => {
-				const value = input.getAttribute(docUtil.inputValueAttributeName(this.options.sessionId));
+				const value = input.getAttribute(docUtil.INPUT_VALUE_ATTRIBUTE_NAME);
 				input.setAttribute("value", value || "");
 			});
 			this.doc.querySelectorAll("input[type=radio], input[type=checkbox]").forEach(input => {
-				const value = input.getAttribute(docUtil.inputValueAttributeName(this.options.sessionId));
+				const value = input.getAttribute(docUtil.INPUT_VALUE_ATTRIBUTE_NAME);
 				if (value == "true") {
 					input.setAttribute("checked", "");
 				}
 			});
 			this.doc.querySelectorAll("textarea").forEach(textarea => {
-				const value = textarea.getAttribute(docUtil.inputValueAttributeName(this.options.sessionId));
+				const value = textarea.getAttribute(docUtil.INPUT_VALUE_ATTRIBUTE_NAME);
 				textarea.textContent = value || "";
 			});
 			this.doc.querySelectorAll("select").forEach(select => {
 				select.querySelectorAll("option").forEach(option => {
-					const selected = option.getAttribute(docUtil.inputValueAttributeName(this.options.sessionId)) != null;
+					const selected = option.getAttribute(docUtil.INPUT_VALUE_ATTRIBUTE_NAME) != null;
 					if (selected) {
 						option.setAttribute("selected", "");
 					}
@@ -696,7 +696,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 		}
 
 		removeHiddenElements() {
-			const hiddenElements = this.doc.querySelectorAll("[" + docUtil.removedContentAttributeName(this.options.sessionId) + "]");
+			const hiddenElements = this.doc.querySelectorAll("[" + docUtil.REMOVED_CONTENT_ATTRIBUTE_NAME + "]");
 			this.stats.set("discarded", "hidden elements", hiddenElements.length);
 			this.stats.set("processed", "hidden elements", hiddenElements.length);
 			hiddenElements.forEach(element => element.remove());
@@ -767,7 +767,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 				const frameElements = Array.from(this.doc.querySelectorAll("iframe, frame, object[type=\"text/html\"][data]"));
 				await Promise.all(frameElements.map(async frameElement => {
 					ProcessorHelper.setFrameEmptySrc(frameElement);
-					const frameWindowId = frameElement.getAttribute(docUtil.windowIdAttributeName(this.options.sessionId));
+					const frameWindowId = frameElement.getAttribute(docUtil.WIN_ID_ATTRIBUTE_NAME);
 					if (frameWindowId) {
 						const frameData = this.options.framesData.find(frame => frame.windowId == frameWindowId);
 						if (frameData) {
@@ -912,7 +912,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 			if (this.options.framesData) {
 				const frameElements = Array.from(this.doc.querySelectorAll("iframe, frame, object[type=\"text/html\"][data]"));
 				await Promise.all(frameElements.map(async frameElement => {
-					const frameWindowId = frameElement.getAttribute(docUtil.windowIdAttributeName(this.options.sessionId));
+					const frameWindowId = frameElement.getAttribute(docUtil.WIN_ID_ATTRIBUTE_NAME);
 					if (frameWindowId) {
 						const frameData = this.options.framesData.find(frame => frame.windowId == frameWindowId);
 						if (frameData) {
@@ -920,7 +920,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 								this.stats.add("processed", "frames", 1);
 								await frameData.processor.run();
 								const pageData = await frameData.processor.getPageData();
-								frameElement.removeAttribute(docUtil.windowIdAttributeName(this.options.sessionId));
+								frameElement.removeAttribute(docUtil.WIN_ID_ATTRIBUTE_NAME);
 								if (pageData.content.match(NOSCRIPT_TAG_FOUND) || pageData.content.match(SCRIPT_TAG_FOUND)) {
 									frameElement.setAttribute("sandbox", "allow-scripts allow-same-origin");
 								} else {
@@ -1019,7 +1019,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 			if (this.options.displayStats) {
 				size = docUtil.getContentSize(this.doc.documentElement.outerHTML);
 			}
-			docUtil.minifyHTML(this.doc, { preservedSpaceAttributeName: docUtil.preservedSpaceAttributeName(this.options.sessionId) });
+			docUtil.minifyHTML(this.doc, { PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME: docUtil.PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME });
 			if (this.options.displayStats) {
 				this.stats.add("discarded", "HTML bytes", size - docUtil.getContentSize(this.doc.documentElement.outerHTML));
 			}
@@ -1641,7 +1641,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 		}
 
 		static replaceImageSource(imgElement, variableName, options) {
-			const dataAttributeName = docUtil.imagesAttributeName(options.sessionId);
+			const dataAttributeName = docUtil.IMAGE_ATTRIBUTE_NAME;
 			if (imgElement.getAttribute(dataAttributeName) != null) {
 				const imgData = options.imageData[Number(imgElement.getAttribute(dataAttributeName))];
 				if (imgData.replaceable) {

+ 22 - 47
lib/single-file/util/doc-helper.js

@@ -41,13 +41,13 @@ this.docHelper = this.docHelper || (() => {
 		preProcessDoc,
 		postProcessDoc,
 		serialize,
-		windowIdAttributeName,
-		preservedSpaceAttributeName,
-		removedContentAttributeName,
-		imagesAttributeName,
-		inputValueAttributeName,
-		shadowRootAttributeName,
-		removeQuotes
+		removeQuotes,
+		WIN_ID_ATTRIBUTE_NAME,
+		PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME,
+		REMOVED_CONTENT_ATTRIBUTE_NAME,
+		IMAGE_ATTRIBUTE_NAME,
+		INPUT_VALUE_ATTRIBUTE_NAME,
+		SHADOW_ROOT_ATTRIBUTE_NAME
 	};
 
 	function preProcessDoc(doc, win, options) {
@@ -66,7 +66,7 @@ this.docHelper = this.docHelper || (() => {
 			if (doc.body && (options.removeHiddenElements || options.removeUnusedFonts || options.compressHTML)) {
 				let elementsInfo = getElementsInfo(win, doc.body);
 				if (options.removeHiddenElements) {
-					const markerRemovedContent = removedContentAttributeName(options.sessionId);
+					const markerRemovedContent = REMOVED_CONTENT_ATTRIBUTE_NAME;
 					let ignoredTags = JSON.parse(JSON.stringify(IGNORED_REMOVED_TAG_NAMES));
 					if (!options.removeScripts) {
 						ignoredTags = ignoredTags.concat("SCRIPT");
@@ -93,15 +93,14 @@ this.docHelper = this.docHelper || (() => {
 				if (options.compressHTML) {
 					elementsInfo.forEach((elementInfo, element) => {
 						if (elementInfo.whiteSpace.startsWith("pre")) {
-							element.setAttribute(preservedSpaceAttributeName(options.sessionId), "");
+							element.setAttribute(PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME, "");
 						}
 					});
 				}
 				elementsInfo.forEach((elementInfo, element) => {
 					let elementIndex = 0;
 					if (elementInfo.shadowRoot) {
-						const attributeName = shadowRootAttributeName(options.sessionId);
-						element.setAttribute(attributeName, elementIndex);
+						element.setAttribute(SHADOW_ROOT_ATTRIBUTE_NAME, elementIndex);
 						elementIndex++;
 						if (!shadowRootContents) {
 							shadowRootContents = [];
@@ -111,7 +110,7 @@ this.docHelper = this.docHelper || (() => {
 				});
 			}
 		}
-		retrieveInputValues(doc, options);
+		retrieveInputValues(doc);
 		return {
 			canvasData,
 			fontsData: getFontsData(doc),
@@ -206,38 +205,14 @@ this.docHelper = this.docHelper || (() => {
 		});
 		doc.head.querySelectorAll("*:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)").forEach(element => element.removeAttribute("hidden"));
 		if (options.removeHiddenElements) {
-			doc.querySelectorAll("[" + removedContentAttributeName(options.sessionId) + "]").forEach(element => element.removeAttribute(removedContentAttributeName(options.sessionId)));
+			doc.querySelectorAll("[" + REMOVED_CONTENT_ATTRIBUTE_NAME + "]").forEach(element => element.removeAttribute(REMOVED_CONTENT_ATTRIBUTE_NAME));
 		}
 		if (options.compressHTML) {
-			doc.querySelectorAll("[" + preservedSpaceAttributeName(options.sessionId) + "]").forEach(element => element.removeAttribute(preservedSpaceAttributeName(options.sessionId)));
+			doc.querySelectorAll("[" + PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME + "]").forEach(element => element.removeAttribute(PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME));
 		}
-		doc.querySelectorAll("[" + imagesAttributeName(options.sessionId) + "]").forEach(element => element.removeAttribute(imagesAttributeName(options.sessionId)));
-		doc.querySelectorAll("[" + inputValueAttributeName(options.sessionId) + "]").forEach(element => element.removeAttribute(inputValueAttributeName(options.sessionId)));
-		doc.querySelectorAll("[" + shadowRootAttributeName(options.sessionId) + "]").forEach(element => element.removeAttribute(shadowRootAttributeName(options.sessionId)));
-	}
-
-	function imagesAttributeName(sessionId) {
-		return IMAGE_ATTRIBUTE_NAME + (sessionId || "");
-	}
-
-	function preservedSpaceAttributeName(sessionId) {
-		return PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME + (sessionId || "");
-	}
-
-	function shadowRootAttributeName(sessionId) {
-		return SHADOW_ROOT_ATTRIBUTE_NAME + (sessionId || "");
-	}
-
-	function removedContentAttributeName(sessionId) {
-		return REMOVED_CONTENT_ATTRIBUTE_NAME + (sessionId || "");
-	}
-
-	function windowIdAttributeName(sessionId) {
-		return WIN_ID_ATTRIBUTE_NAME + (sessionId || "");
-	}
-
-	function inputValueAttributeName(sessionId) {
-		return INPUT_VALUE_ATTRIBUTE_NAME + (sessionId || "");
+		doc.querySelectorAll("[" + IMAGE_ATTRIBUTE_NAME + "]").forEach(element => element.removeAttribute(IMAGE_ATTRIBUTE_NAME));
+		doc.querySelectorAll("[" + INPUT_VALUE_ATTRIBUTE_NAME + "]").forEach(element => element.removeAttribute(INPUT_VALUE_ATTRIBUTE_NAME));
+		doc.querySelectorAll("[" + SHADOW_ROOT_ATTRIBUTE_NAME + "]").forEach(element => element.removeAttribute(SHADOW_ROOT_ATTRIBUTE_NAME));
 	}
 
 	function getCanvasData(doc, win) {
@@ -281,7 +256,7 @@ this.docHelper = this.docHelper || (() => {
 		if (doc) {
 			const data = [];
 			doc.querySelectorAll("img").forEach((imageElement, imageElementIndex) => {
-				imageElement.setAttribute(imagesAttributeName(options.sessionId), imageElementIndex);
+				imageElement.setAttribute(IMAGE_ATTRIBUTE_NAME, imageElementIndex);
 				const imageData = {
 					currentSrc: (options.loadDeferredImages && imageElement.getAttribute(LAZY_SRC_ATTRIBUTE_NAME)) || imageElement.currentSrc
 				};
@@ -377,14 +352,14 @@ this.docHelper = this.docHelper || (() => {
 		}
 	}
 
-	function retrieveInputValues(doc, options) {
-		doc.querySelectorAll("input").forEach(input => input.setAttribute(inputValueAttributeName(options.sessionId), input.value));
-		doc.querySelectorAll("input[type=radio], input[type=checkbox]").forEach(input => input.setAttribute(inputValueAttributeName(options.sessionId), input.checked));
-		doc.querySelectorAll("textarea").forEach(textarea => textarea.setAttribute(inputValueAttributeName(options.sessionId), textarea.value));
+	function retrieveInputValues(doc) {
+		doc.querySelectorAll("input").forEach(input => input.setAttribute(INPUT_VALUE_ATTRIBUTE_NAME, input.value));
+		doc.querySelectorAll("input[type=radio], input[type=checkbox]").forEach(input => input.setAttribute(INPUT_VALUE_ATTRIBUTE_NAME, input.checked));
+		doc.querySelectorAll("textarea").forEach(textarea => textarea.setAttribute(INPUT_VALUE_ATTRIBUTE_NAME, textarea.value));
 		doc.querySelectorAll("select").forEach(select => {
 			select.querySelectorAll("option").forEach(option => {
 				if (option.selected) {
-					option.setAttribute(inputValueAttributeName(options.sessionId), "");
+					option.setAttribute(INPUT_VALUE_ATTRIBUTE_NAME, "");
 				}
 			});
 		});

+ 5 - 18
lib/single-file/util/doc-util.js

@@ -123,24 +123,11 @@ this.docUtil = this.docUtil || (() => {
 				removeQuotes(string) {
 					return modules.docHelper.removeQuotes(string);
 				},
-				windowIdAttributeName(sessionId) {
-					return modules.docHelper.windowIdAttributeName(sessionId);
-				},
-				preservedSpaceAttributeName(sessionId) {
-					return modules.docHelper.preservedSpaceAttributeName(sessionId);
-				},
-				removedContentAttributeName(sessionId) {
-					return modules.docHelper.removedContentAttributeName(sessionId);
-				},
-				imagesAttributeName(sessionId) {
-					return modules.docHelper.imagesAttributeName(sessionId);
-				},
-				inputValueAttributeName(sessionId) {
-					return modules.docHelper.inputValueAttributeName(sessionId);
-				},
-				shadowRootAttributeName(sessionId) {
-					return modules.docHelper.shadowRootAttributeName(sessionId);
-				}
+				WIN_ID_ATTRIBUTE_NAME: modules.docHelper.WIN_ID_ATTRIBUTE_NAME,
+				REMOVED_CONTENT_ATTRIBUTE_NAME: modules.docHelper.REMOVED_CONTENT_ATTRIBUTE_NAME,
+				IMAGE_ATTRIBUTE_NAME: modules.docHelper.IMAGE_ATTRIBUTE_NAME,
+				INPUT_VALUE_ATTRIBUTE_NAME: modules.docHelper.INPUT_VALUE_ATTRIBUTE_NAME,
+				SHADOW_ROOT_ATTRIBUTE_NAME: modules.docHelper.SHADOW_ROOT_ATTRIBUTE_NAME
 			};
 
 			async function getContent(resourceURL, options) {