|
@@ -86,19 +86,19 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
sequential: [
|
|
sequential: [
|
|
|
{ action: "preProcessPage" },
|
|
{ action: "preProcessPage" },
|
|
|
{ action: "replaceStyleContents" },
|
|
{ action: "replaceStyleContents" },
|
|
|
|
|
+ { action: "resetCharsetMeta" },
|
|
|
|
|
+ { option: "insertFaviconLink", action: "insertFaviconLink" },
|
|
|
|
|
+ { action: "replaceCanvasElements" },
|
|
|
|
|
+ { action: "insertFonts" },
|
|
|
|
|
+ { action: "insertShadowRootContents" },
|
|
|
|
|
+ { action: "setInputValues" },
|
|
|
|
|
+ { option: "removeScripts", action: "removeScripts" },
|
|
|
{ option: "selected", action: "removeUnselectedElements" },
|
|
{ option: "selected", action: "removeUnselectedElements" },
|
|
|
{ option: "removeVideoSrc", action: "insertVideoPosters" },
|
|
{ option: "removeVideoSrc", action: "insertVideoPosters" },
|
|
|
{ option: "removeFrames", action: "removeFrames" },
|
|
{ option: "removeFrames", action: "removeFrames" },
|
|
|
- { option: "removeScripts", action: "removeScripts" },
|
|
|
|
|
{ option: "removeVideoSrc", action: "removeVideoSources" },
|
|
{ option: "removeVideoSrc", action: "removeVideoSources" },
|
|
|
{ option: "removeAudioSrc", action: "removeAudioSources" },
|
|
{ option: "removeAudioSrc", action: "removeAudioSources" },
|
|
|
{ action: "removeDiscardedResources" },
|
|
{ action: "removeDiscardedResources" },
|
|
|
- { action: "resetCharsetMeta" },
|
|
|
|
|
- { action: "setInputValues" },
|
|
|
|
|
- { option: "insertFaviconLink", action: "insertFaviconLink" },
|
|
|
|
|
- { action: "replaceCanvasElements" },
|
|
|
|
|
- { action: "insertFonts" },
|
|
|
|
|
- { action: "insertShadowRootContents" },
|
|
|
|
|
{ option: "removeHiddenElements", action: "removeHiddenElements" },
|
|
{ option: "removeHiddenElements", action: "removeHiddenElements" },
|
|
|
{ action: "resolveHrefs" },
|
|
{ action: "resolveHrefs" },
|
|
|
{ action: "resolveStyleAttributeURLs" }
|
|
{ action: "resolveStyleAttributeURLs" }
|
|
@@ -332,6 +332,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
const NOSCRIPT_TAG_FOUND = /<noscript/gi;
|
|
const NOSCRIPT_TAG_FOUND = /<noscript/gi;
|
|
|
const SHADOW_MODE_ATTRIBUTE_NAME = "shadowmode";
|
|
const SHADOW_MODE_ATTRIBUTE_NAME = "shadowmode";
|
|
|
const SHADOW_DELEGATE_FOCUS_ATTRIBUTE_NAME = "delegatesfocus";
|
|
const SHADOW_DELEGATE_FOCUS_ATTRIBUTE_NAME = "delegatesfocus";
|
|
|
|
|
+ const SCRIPT_TEMPLATE_SHADOW_ROOT = "data-template-shadow-root";
|
|
|
|
|
|
|
|
class Processor {
|
|
class Processor {
|
|
|
constructor(options, batchRequest) {
|
|
constructor(options, batchRequest) {
|
|
@@ -618,7 +619,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
element.removeAttribute("src");
|
|
element.removeAttribute("src");
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- const scriptElements = this.doc.querySelectorAll("script:not([type=\"application/ld+json\"])");
|
|
|
|
|
|
|
+ const scriptElements = this.doc.querySelectorAll("script:not([type=\"application/ld+json\"]):not([" + SCRIPT_TEMPLATE_SHADOW_ROOT + "])");
|
|
|
this.stats.set("discarded", "scripts", scriptElements.length);
|
|
this.stats.set("discarded", "scripts", scriptElements.length);
|
|
|
this.stats.set("processed", "scripts", scriptElements.length);
|
|
this.stats.set("processed", "scripts", scriptElements.length);
|
|
|
scriptElements.forEach(element => element.remove());
|
|
scriptElements.forEach(element => element.remove());
|
|
@@ -910,7 +911,11 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
const options = this.options;
|
|
const options = this.options;
|
|
|
if (this.options.shadowRoots && this.options.shadowRoots.length) {
|
|
if (this.options.shadowRoots && this.options.shadowRoots.length) {
|
|
|
processElement(this.doc);
|
|
processElement(this.doc);
|
|
|
|
|
+ if (this.options.removeScripts) {
|
|
|
|
|
+ this.doc.querySelectorAll("script[" + SCRIPT_TEMPLATE_SHADOW_ROOT + "]").forEach(element => element.remove());
|
|
|
|
|
+ }
|
|
|
const scriptElement = doc.createElement("script");
|
|
const scriptElement = doc.createElement("script");
|
|
|
|
|
+ scriptElement.setAttribute(SCRIPT_TEMPLATE_SHADOW_ROOT, "");
|
|
|
scriptElement.textContent = `(()=>{document.currentScript.remove();processNode(document);function processNode(node){node.querySelectorAll("template[${SHADOW_MODE_ATTRIBUTE_NAME}]").forEach(element=>{if (!element.parentElement.shadowRoot) {const shadowRoot=element.parentElement.attachShadow({mode:element.getAttribute("${SHADOW_MODE_ATTRIBUTE_NAME}"),delegatesFocus:Boolean(element.getAttribute("${SHADOW_DELEGATE_FOCUS_ATTRIBUTE_NAME}"))});shadowRoot.innerHTML=element.innerHTML;element.remove();processNode(shadowRoot)}})}})()`;
|
|
scriptElement.textContent = `(()=>{document.currentScript.remove();processNode(document);function processNode(node){node.querySelectorAll("template[${SHADOW_MODE_ATTRIBUTE_NAME}]").forEach(element=>{if (!element.parentElement.shadowRoot) {const shadowRoot=element.parentElement.attachShadow({mode:element.getAttribute("${SHADOW_MODE_ATTRIBUTE_NAME}"),delegatesFocus:Boolean(element.getAttribute("${SHADOW_DELEGATE_FOCUS_ATTRIBUTE_NAME}"))});shadowRoot.innerHTML=element.innerHTML;element.remove();processNode(shadowRoot)}})}})()`;
|
|
|
doc.body.appendChild(scriptElement);
|
|
doc.body.appendChild(scriptElement);
|
|
|
}
|
|
}
|