Selaa lähdekoodia

add accept headers for video and audio contents

Gildas 4 vuotta sitten
vanhempi
sitoutus
00cd2f92bc
2 muutettua tiedostoa jossa 8 lisäystä ja 6 poistoa
  1. 3 1
      src/extension/core/bg/config.js
  2. 5 5
      src/single-file/single-file-core.js

+ 3 - 1
src/extension/core/bg/config.js

@@ -120,7 +120,9 @@ const DEFAULT_CONFIG = {
 		image: "image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8",
 		stylesheet: "text/css,*/*;q=0.1",
 		script: "*/*",
-		document: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
+		document: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
+		video: "video/webm,video/ogg,video/*;q=0.9,application/ogg;q=0.7,audio/*;q=0.6,*/*;q=0.5",
+		audio: "audio/webm,audio/ogg,audio/wav,audio/*;q=0.9,application/ogg;q=0.7,video/*;q=0.6,*/*;q=0.5"
 	},
 	moveStylesInHead: false,
 	woleetKey: ""

+ 5 - 5
src/single-file/single-file-core.js

@@ -1210,17 +1210,17 @@ class Processor {
 			["image", "href"]
 		];
 		let resourcePromises = processAttributeArgs.map(([selector, attributeName, processDuplicates, removeElementIfMissing]) =>
-			ProcessorHelper.processAttribute(this.doc.querySelectorAll(selector), attributeName, this.baseURI, this.options, this.cssVariables, this.styles, this.batchRequest, processDuplicates, removeElementIfMissing)
+			ProcessorHelper.processAttribute(this.doc.querySelectorAll(selector), attributeName, this.baseURI, this.options, "image", this.cssVariables, this.styles, this.batchRequest, processDuplicates, removeElementIfMissing)
 		);
 		resourcePromises = resourcePromises.concat([
 			ProcessorHelper.processXLinks(this.doc.querySelectorAll("use"), this.doc, this.baseURI, this.options, this.batchRequest),
 			ProcessorHelper.processSrcset(this.doc.querySelectorAll("img[srcset], source[srcset]"), "srcset", this.baseURI, this.batchRequest)
 		]);
 		if (!this.options.removeAudioSrc) {
-			resourcePromises.push(ProcessorHelper.processAttribute(this.doc.querySelectorAll("audio[src], audio > source[src]"), "src", this.baseURI, this.options, this.cssVariables, this.styles, this.batchRequest));
+			resourcePromises.push(ProcessorHelper.processAttribute(this.doc.querySelectorAll("audio[src], audio > source[src]"), "src", this.baseURI, this.options, "audio", this.cssVariables, this.styles, this.batchRequest));
 		}
 		if (!this.options.removeVideoSrc) {
-			resourcePromises.push(ProcessorHelper.processAttribute(this.doc.querySelectorAll("video[src], video > source[src]"), "src", this.baseURI, this.options, this.cssVariables, this.styles, this.batchRequest));
+			resourcePromises.push(ProcessorHelper.processAttribute(this.doc.querySelectorAll("video[src], video > source[src]"), "src", this.baseURI, this.options, "video", this.cssVariables, this.styles, this.batchRequest));
 		}
 		await Promise.all(resourcePromises);
 		if (this.options.saveFavicon) {
@@ -1904,7 +1904,7 @@ class ProcessorHelper {
 		}
 	}
 
-	static async processAttribute(resourceElements, attributeName, baseURI, options, cssVariables, styles, batchRequest, processDuplicates, removeElementIfMissing) {
+	static async processAttribute(resourceElements, attributeName, baseURI, options, expectedType, cssVariables, styles, batchRequest, processDuplicates, removeElementIfMissing) {
 		await Promise.all(Array.from(resourceElements).map(async resourceElement => {
 			let resourceURL = resourceElement.getAttribute(attributeName);
 			if (resourceURL != null) {
@@ -1924,7 +1924,7 @@ class ProcessorHelper {
 						}
 						if (testValidURL(resourceURL)) {
 							let { content, indexResource, duplicate } = await batchRequest.addURL(resourceURL,
-								{ asBinary: true, expectedType: "image", groupDuplicates: options.groupDuplicateImages && resourceElement.tagName == "IMG" && attributeName == "src" });
+								{ asBinary: true, expectedType: expectedType, groupDuplicates: options.groupDuplicateImages && resourceElement.tagName == "IMG" && attributeName == "src" });
 							if (originURL) {
 								if (content == EMPTY_DATA_URI) {
 									try {