فهرست منبع

added options to remove audio & video sources

Gildas 7 سال پیش
والد
کامیت
678a7615e9

+ 9 - 1
extension/core/bg/config.js

@@ -37,7 +37,9 @@ singlefile.config = (() => {
 		contextMenuEnabled: true,
 		shadowEnabled: true,
 		maxResourceSizeEnabled: false,
-		maxResourceSize: 10
+		maxResourceSize: 10,
+		removeAudioSrc: true,
+		removeVideoSrc: true
 	};
 
 	let pendingUpgradePromise;
@@ -94,6 +96,12 @@ singlefile.config = (() => {
 		if (config.removeFrames === undefined) {
 			config.removeFrames = true;
 		}
+		if (config.removeAudioSrc === undefined) {
+			config.removeAudioSrc = true;
+		}
+		if (config.removeVideoSrc === undefined) {
+			config.removeVideoSrc = true;
+		}
 	}
 
 	return {

+ 7 - 1
extension/ui/bg/options.js

@@ -38,6 +38,8 @@
 	const maxResourceSizeInput = document.getElementById("maxResourceSizeInput");
 	const maxResourceSizeEnabledInput = document.getElementById("maxResourceSizeEnabledInput");
 	const confirmFilenameInput = document.getElementById("confirmFilenameInput");
+	const removeAudioSrcInput = document.getElementById("removeAudioSrcInput");
+	const removeVideoSrcInput = document.getElementById("removeVideoSrcInput");
 	let pendingSave = Promise.resolve();
 	document.getElementById("resetButton").addEventListener("click", async () => {
 		await bgPage.singlefile.config.reset();
@@ -66,6 +68,8 @@
 		maxResourceSizeInput.value = config.maxResourceSize;
 		maxResourceSizeInput.disabled = !config.maxResourceSizeEnabled;
 		confirmFilenameInput.checked = config.confirmFilename;
+		removeAudioSrcInput.checked = config.removeAudioSrc;
+		removeVideoSrcInput.checked = config.removeVideoSrc;
 	}
 
 	async function update() {
@@ -85,7 +89,9 @@
 			shadowEnabled: shadowEnabledInput.checked,
 			maxResourceSizeEnabled: maxResourceSizeEnabledInput.checked,
 			maxResourceSize: maxResourceSizeInput.value,
-			confirmFilename: confirmFilenameInput.checked
+			confirmFilename: confirmFilenameInput.checked,
+			removeAudioSrc: removeAudioSrcInput.checked,
+			removeVideoSrc: removeVideoSrcInput.checked
 		});
 		await pendingSave;
 		await bgPage.singlefile.ui.update();

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

@@ -123,6 +123,20 @@
 							<u>check</u> this option</p>
 					</li>
 
+					<li>
+						<span class="option">remove video sources</span>
+						<p>Check this option to empty all the "src" attribute of video elements.</p>
+						<p class="notice">It is recommended to
+							<u>check</u> this option</p>
+					</li>
+
+					<li>
+						<span class="option">remove audio sources</span>
+						<p>Check this option to empty all the "src" attribute of audio elements.</p>
+						<p class="notice">It is recommended to
+							<u>check</u> this option</p>
+					</li>
+
 					<li>
 						<span class="option">compress CSS</span>
 						<p>Check this option to minify CSS stylesheets. This helps to reduce the size of the file without altering the document.</p>

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

@@ -59,6 +59,14 @@
 			<label for="removeScriptsInput">remove scripts</label>
 			<input type="checkbox" id="removeScriptsInput">
 		</div>
+		<div class="option">
+			<label for="removeVideoSrcInput">remove video sources</label>
+			<input type="checkbox" id="removeVideoSrcInput">
+		</div>
+		<div class="option">
+			<label for="removeAudioSrcInput">remove audio sources</label>
+			<input type="checkbox" id="removeAudioSrcInput">
+		</div>
 		<div class="option">
 			<label for="compressCSSInput">compress CSS</label>
 			<input type="checkbox" id="compressCSSInput">

+ 12 - 1
lib/single-file/single-file-core.js

@@ -303,7 +303,12 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 			this.doc.querySelectorAll("applet, meta[http-equiv=refresh], object:not([type=\"image/svg+xml\"]):not([type=\"image/svg-xml\"]):not([type=\"text/html\"]), embed:not([src*=\".svg\"]), link[rel*=preload], link[rel*=prefetch]").forEach(element => element.remove());
 			this.doc.querySelectorAll("[onload]").forEach(element => element.removeAttribute("onload"));
 			this.doc.querySelectorAll("[onerror]").forEach(element => element.removeAttribute("onerror"));
-			this.doc.querySelectorAll("audio[src], audio > source[src], video[src], video > source[src]").forEach(element => element.removeAttribute("src"));
+			if (this.options.removeAudioSrc) {
+				this.doc.querySelectorAll("audio[src], audio > source[src]").forEach(element => element.removeAttribute("src"));
+			}
+			if (this.options.removeVideoSrc) {
+				this.doc.querySelectorAll("video[src], video > source[src]").forEach(element => element.removeAttribute("src"));
+			}
 		}
 
 		removeEmptyInlineElements() {
@@ -416,6 +421,12 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 				DomProcessorHelper.processAttribute(this.doc.querySelectorAll("image, use"), "xlink:href", this.baseURI),
 				DomProcessorHelper.processSrcset(this.doc.querySelectorAll("[srcset]"), "srcset", this.baseURI, this.dom.parseSrcset)
 			];
+			if (!this.options.removeAudioSrc) {
+				resourcePromises.push(DomProcessorHelper.processAttribute(this.doc.querySelectorAll("audio[src], audio > source[src]"), "src", this.baseURI));
+			}
+			if (!this.options.removeVideoSrc) {
+				resourcePromises.push(DomProcessorHelper.processAttribute(this.doc.querySelectorAll("video[src], video > source[src]"), "src", this.baseURI));
+			}
 			if (this.options.lazyLoadImages) {
 				resourcePromises.push(DomProcessorHelper.processAttribute(this.doc.querySelectorAll("img[data-src]"), "data-src", this.baseURI));
 				resourcePromises.push(DomProcessorHelper.processAttribute(this.doc.querySelectorAll("img[data-original]"), "data-original", this.baseURI));