Sfoglia il codice sorgente

remove meta refresh tags in noscript tags
(fix #907)

Gildas 3 anni fa
parent
commit
1c2c4483ca
1 ha cambiato i file con 13 aggiunte e 1 eliminazioni
  1. 13 1
      src/single-file/single-file-core.js

+ 13 - 1
src/single-file/single-file-core.js

@@ -778,7 +778,19 @@ class Processor {
 
 	removeDiscardedResources() {
 		this.doc.querySelectorAll("." + util.SINGLE_FILE_UI_ELEMENT_CLASS).forEach(element => element.remove());
-		this.doc.querySelectorAll("meta[http-equiv=refresh], meta[disabled-http-equiv], meta[http-equiv=\"content-security-policy\"]").forEach(element => element.remove());
+		const noscriptPlaceholders = new Map();
+		this.doc.querySelectorAll("noscript").forEach(noscriptElement => {
+			const placeholderElement = this.doc.createElement("div");
+			placeholderElement.innerHTML = noscriptElement.dataset.singleFileDisabledNoscript;
+			noscriptElement.replaceWith(placeholderElement);
+			noscriptPlaceholders.set(placeholderElement, noscriptElement);
+		});
+		this.doc.querySelectorAll("meta[http-equiv=refresh], meta[disabled-http-equiv]").forEach(element => element.remove());
+		Array.from(noscriptPlaceholders).forEach(([placeholderElement, noscriptElement]) => {
+			noscriptElement.dataset.singleFileDisabledNoscript = placeholderElement.innerHTML;
+			placeholderElement.replaceWith(noscriptElement);
+		});
+		this.doc.querySelectorAll("meta[http-equiv=\"content-security-policy\"]").forEach(element => element.remove());
 		const objectElements = this.doc.querySelectorAll("applet, object[data]:not([type=\"image/svg+xml\"]):not([type=\"image/svg-xml\"]):not([type=\"text/html\"]), embed[src]:not([src*=\".svg\"]):not([src*=\".pdf\"])");
 		this.stats.set("discarded", "objects", objectElements.length);
 		this.stats.set("processed", "objects", objectElements.length);