Parcourir la source

added "remove HTML imports" option

Gildas il y a 7 ans
Parent
commit
be15313744

+ 5 - 0
extension/core/scripts/bg/config.js

@@ -48,6 +48,10 @@ singlefile.config = (() => {
 			config.appendSaveDate = true;
 			localStorage.config = JSON.stringify(config);
 		}
+		if (config.removeImports == undefined) {
+			config.removeImports = true;
+			localStorage.config = JSON.stringify(config);
+		}
 	}
 
 	return {
@@ -59,6 +63,7 @@ singlefile.config = (() => {
 				removeHidden: false,
 				removeUnusedCSSRules: false,
 				removeFrames: true,
+				removeImports: true,
 				removeScripts: true,
 				rawDocument: false,
 				compressHTML: true,

+ 5 - 0
extension/ui/pages/help.html

@@ -87,6 +87,11 @@
 						<p class="notice">It is recommended to
 							<u>check</u> this option</p>
 					</li>
+
+					<li>
+						<span class="option">remove HTML import</span>
+						<p>Check this option to remove all link elements used to import HTML documents. This can reduce the size of the file without
+							altering the document most of the time.</p>
 						<p class="notice">It is recommended to
 							<u>check</u> this option</p>
 					</li>

+ 4 - 0
extension/ui/pages/options.html

@@ -35,6 +35,10 @@
 				<label for="removeFramesInput">remove frames</label>
 				<input type="checkbox" id="removeFramesInput">
 			</div>
+			<div class="option">
+				<label for="removeImportsInput">remove HTML imports</label>
+				<input type="checkbox" id="removeImportsInput">
+			</div>
 			<div class="option">
 				<label for="removeScriptsInput">remove scripts</label>
 				<input type="checkbox" id="removeScriptsInput">

+ 3 - 0
extension/ui/scripts/bg/options.js

@@ -28,6 +28,7 @@
 		const removeHiddenInput = document.getElementById("removeHiddenInput");
 		const removeUnusedCSSRulesInput = document.getElementById("removeUnusedCSSRulesInput");
 		const removeFramesInput = document.getElementById("removeFramesInput");
+		const removeImportsInput = document.getElementById("removeImportsInput");
 		const removeScriptsInput = document.getElementById("removeScriptsInput");
 		const saveRawPageInput = document.getElementById("saveRawPageInput");
 		const compressHTMLInput = document.getElementById("compressHTMLInput");
@@ -48,6 +49,7 @@
 			removeHiddenInput.checked = config.removeHidden;
 			removeUnusedCSSRulesInput.checked = config.removeUnusedCSSRules;
 			removeFramesInput.checked = config.removeFrames;
+			removeImportsInput.checked = config.removeImports;
 			removeScriptsInput.checked = config.removeScripts;
 			saveRawPageInput.checked = config.saveRawPage;
 			compressHTMLInput.checked = config.compressHTML;
@@ -62,6 +64,7 @@
 				removeHidden: removeHiddenInput.checked,
 				removeUnusedCSSRules: removeUnusedCSSRulesInput.checked,
 				removeFrames: removeFramesInput.checked,
+				removeImports: removeImportsInput.checked,
 				removeScripts: removeScriptsInput.checked,
 				saveRawPage: saveRawPageInput.checked,
 				compressHTML: compressHTMLInput.checked,

+ 15 - 3
lib/single-file/single-file-core.js

@@ -88,6 +88,9 @@ const SingleFileCore = (() => {
 			if (this.options.removeFrames) {
 				this.processor.removeFrames();
 			}
+			if (this.options.removeImports) {
+				this.processor.removeImports();
+			}
 			if (this.options.removeScripts) {
 				this.processor.removeScripts();
 			}
@@ -110,10 +113,13 @@ const SingleFileCore = (() => {
 			if (this.options.removeUnusedCSSRules) {
 				this.processor.removeUnusedCSSRules();
 			}
-			const initializationPromises = [this.processor.inlineStylesheets(true), this.processor.linkStylesheets(), this.processor.attributeStyles(true), this.processor.linkRelImport(true)];
+			const initializationPromises = [this.processor.inlineStylesheets(true), this.processor.linkStylesheets(), this.processor.attributeStyles(true)];
 			if (!this.options.removeFrames) {
 				initializationPromises.push(this.processor.frames(true));
 			}
+			if (!this.options.removeImports) {
+				initializationPromises.push(this.processor.htmlImports(true));
+			}
 			await Promise.all(initializationPromises);
 			this.pendingPromises = [this.processor.inlineStylesheets(), this.processor.attributeStyles(), this.processor.pageResources()];
 			if (!this.options.removeScripts) {
@@ -145,7 +151,9 @@ const SingleFileCore = (() => {
 			if (!this.options.removeFrames) {
 				await this.processor.frames();
 			}
-			await this.processor.linkRelImport();
+			if (!this.options.removeImports) {
+				await this.processor.htmlImports();
+			}
 			if (this.onprogress) {
 				this.onprogress(new ProgressEvent(PAGE_ENDED, { pageURL: this.options.url }));
 			}
@@ -293,6 +301,10 @@ const SingleFileCore = (() => {
 			this.doc.querySelectorAll("iframe, frame").forEach(element => element.remove());
 		}
 
+		removeImports() {
+			this.doc.querySelectorAll("link[rel=import]").forEach(element => element.remove());
+		}
+
 		resetCharsetMeta() {
 			this.doc.querySelectorAll("meta[charset]").forEach(element => element.remove());
 			const metaElement = this.doc.createElement("meta");
@@ -486,7 +498,7 @@ const SingleFileCore = (() => {
 			}));
 		}
 
-		async linkRelImport(initialization) {
+		async htmlImports(initialization) {
 			let linkElements = this.doc.querySelectorAll("link[rel=import][href]");
 			linkElements = DomUtil.removeNoScriptFrames(linkElements);
 			if (!this.relImportProcessors) {