|
|
@@ -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) {
|