|
@@ -95,6 +95,8 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
{ option: "removeFrames", action: "removeFrames" },
|
|
{ option: "removeFrames", action: "removeFrames" },
|
|
|
{ option: "removeImports", action: "removeImports" },
|
|
{ option: "removeImports", action: "removeImports" },
|
|
|
{ option: "removeScripts", action: "removeScripts" },
|
|
{ option: "removeScripts", action: "removeScripts" },
|
|
|
|
|
+ { option: "removeVideoSrc", action: "removeVideoSources" },
|
|
|
|
|
+ { option: "removeAudioSrc", action: "removeAudiosources" },
|
|
|
{ action: "removeDiscardedResources" },
|
|
{ action: "removeDiscardedResources" },
|
|
|
{ action: "resetCharsetMeta" },
|
|
{ action: "resetCharsetMeta" },
|
|
|
{ action: "setInputValues" },
|
|
{ action: "setInputValues" },
|
|
@@ -461,43 +463,6 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
this.doc.querySelectorAll("input[type=hidden]").forEach(element => element.remove());
|
|
this.doc.querySelectorAll("input[type=hidden]").forEach(element => element.remove());
|
|
|
}
|
|
}
|
|
|
this.doc.querySelectorAll("a[ping]").forEach(element => element.removeAttribute("ping"));
|
|
this.doc.querySelectorAll("a[ping]").forEach(element => element.removeAttribute("ping"));
|
|
|
- if (this.options.removeScripts) {
|
|
|
|
|
- this.onEventAttributeNames.forEach(attributeName => this.doc.querySelectorAll("[" + attributeName + "]").forEach(element => element.removeAttribute(attributeName)));
|
|
|
|
|
- this.doc.querySelectorAll("[href]").forEach(element => {
|
|
|
|
|
- if (element.href && element.href.match && element.href.match(/^\s*javascript:/)) {
|
|
|
|
|
- element.setAttribute("href", "");
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- this.doc.querySelectorAll("[src]").forEach(element => {
|
|
|
|
|
- if (element.src && element.src.match(/^\s*javascript:/)) {
|
|
|
|
|
- element.removeAttribute("src");
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- const audioSourceElements = this.doc.querySelectorAll("audio[src], audio > source[src]");
|
|
|
|
|
- this.stats.set("processed", "audio sources", audioSourceElements.length);
|
|
|
|
|
- if (this.options.removeAudioSrc) {
|
|
|
|
|
- this.stats.set("discarded", "audio sources", audioSourceElements.length);
|
|
|
|
|
- audioSourceElements.forEach(element => {
|
|
|
|
|
- if (element.tagName == "SOURCE") {
|
|
|
|
|
- element.remove();
|
|
|
|
|
- } else {
|
|
|
|
|
- audioSourceElements.forEach(element => element.removeAttribute("src"));
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- const videoSourceElements = this.doc.querySelectorAll("video[src], video > source");
|
|
|
|
|
- this.stats.set("processed", "video sources", videoSourceElements.length);
|
|
|
|
|
- if (this.options.removeVideoSrc) {
|
|
|
|
|
- this.stats.set("discarded", "video sources", videoSourceElements.length);
|
|
|
|
|
- videoSourceElements.forEach(element => {
|
|
|
|
|
- if (element.tagName == "SOURCE") {
|
|
|
|
|
- element.remove();
|
|
|
|
|
- } else {
|
|
|
|
|
- videoSourceElements.forEach(element => element.removeAttribute("src"));
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async end() {
|
|
async end() {
|
|
@@ -560,12 +525,49 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
removeScripts() {
|
|
removeScripts() {
|
|
|
|
|
+ this.onEventAttributeNames.forEach(attributeName => this.doc.querySelectorAll("[" + attributeName + "]").forEach(element => element.removeAttribute(attributeName)));
|
|
|
|
|
+ this.doc.querySelectorAll("[href]").forEach(element => {
|
|
|
|
|
+ if (element.href && element.href.match && element.href.match(/^\s*javascript:/)) {
|
|
|
|
|
+ element.setAttribute("href", "");
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ this.doc.querySelectorAll("[src]").forEach(element => {
|
|
|
|
|
+ if (element.src && element.src.match(/^\s*javascript:/)) {
|
|
|
|
|
+ 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\"])");
|
|
|
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());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ removeAudioSources() {
|
|
|
|
|
+ const audioSourceElements = this.doc.querySelectorAll("audio[src], audio > source[src]");
|
|
|
|
|
+ this.stats.set("discarded", "audio sources", audioSourceElements.length);
|
|
|
|
|
+ this.stats.set("processed", "audio sources", audioSourceElements.length);
|
|
|
|
|
+ audioSourceElements.forEach(element => {
|
|
|
|
|
+ if (element.tagName == "SOURCE") {
|
|
|
|
|
+ element.remove();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ audioSourceElements.forEach(element => element.removeAttribute("src"));
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ removeVideoSources() {
|
|
|
|
|
+ const videoSourceElements = this.doc.querySelectorAll("video[src], video > source");
|
|
|
|
|
+ this.stats.set("discarded", "video sources", videoSourceElements.length);
|
|
|
|
|
+ this.stats.set("processed", "video sources", videoSourceElements.length);
|
|
|
|
|
+ videoSourceElements.forEach(element => {
|
|
|
|
|
+ if (element.tagName == "SOURCE") {
|
|
|
|
|
+ element.remove();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ videoSourceElements.forEach(element => element.removeAttribute("src"));
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
removeFrames() {
|
|
removeFrames() {
|
|
|
const frameElements = this.doc.querySelectorAll("iframe, frame, object[type=\"text/html\"][data]");
|
|
const frameElements = this.doc.querySelectorAll("iframe, frame, object[type=\"text/html\"][data]");
|
|
|
this.stats.set("discarded", "frames", frameElements.length);
|
|
this.stats.set("discarded", "frames", frameElements.length);
|