Pārlūkot izejas kodu

added saveFavicon hidden option (fix #339)

Former-commit-id: 2744bac750cd533f78c59ef1a39273bf7e66cd8f
Gildas 6 gadi atpakaļ
vecāks
revīzija
a7849c5903

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

@@ -86,7 +86,8 @@ singlefile.extension.core.bg.config = (() => {
 		userScriptEnabled: false,
 		openEditor: false,
 		autoOpenEditor: false,
-		saveCreatedBookmarks: false
+		saveCreatedBookmarks: false,
+		saveFavicon: true
 	};
 
 	let configStorage;

+ 0 - 1
lib/single-file/index.js

@@ -56,7 +56,6 @@ this.singlefile = this.singlefile || {
 			options.doc = doc;
 			options.win = win;
 			options.insertSingleFileComment = true;
-			options.insertFaviconLink = true;
 			const singleFile = new this.SingleFile(options);
 			await singleFile.run();
 			return await singleFile.getPageData();

+ 10 - 6
lib/single-file/single-file-core.js

@@ -35,7 +35,6 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 	class SingleFileClass {
 		constructor(options) {
 			this.options = options;
-			options.insertFaviconLink = true;
 			if (options.sessionId === undefined) {
 				options.sessionId = sessionId;
 				sessionId++;
@@ -96,7 +95,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 			{ action: "preProcessPage" },
 			{ action: "replaceStyleContents" },
 			{ action: "resetCharsetMeta" },
-			{ option: "insertFaviconLink", action: "insertFaviconLink" },
+			{ option: "saveFavicon", action: "saveFavicon" },
 			{ action: "replaceCanvasElements" },
 			{ action: "insertFonts" },
 			{ action: "insertShadowRootContents" },
@@ -700,6 +699,9 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 			if (this.options.compressHTML) {
 				this.doc.querySelectorAll("input[type=hidden]").forEach(element => element.remove());
 			}
+			if (!this.options.saveFavicon) {
+				this.doc.querySelectorAll("link[rel*=\"icon\"]").forEach(element => element.remove());
+			}
 			this.doc.querySelectorAll("a[ping]").forEach(element => element.removeAttribute("ping"));
 		}
 
@@ -749,7 +751,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 			});
 		}
 
-		insertFaviconLink() {
+		saveFavicon() {
 			let faviconElement = this.doc.querySelector("link[href][rel=\"icon\"]");
 			if (!faviconElement) {
 				faviconElement = this.doc.querySelector("link[href][rel=\"shortcut icon\"]");
@@ -956,7 +958,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 
 			async function initializeProcessor(frameData, frameElement, frameWindowId, batchRequest, options) {
 				options.insertSingleFileComment = false;
-				options.insertFaviconLink = false;
+				options.saveFavicon = false;
 				options.doc = null;
 				options.win = null;
 				options.url = frameData.baseURI;
@@ -1043,7 +1045,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 				linkElement.removeAttribute("href");
 				const options = Object.create(this.options);
 				options.insertSingleFileComment = false;
-				options.insertFaviconLink = false;
+				options.saveFavicon = false;
 				options.removeUnusedStyles = false;
 				options.removeAlternativeMedias = false;
 				options.removeUnusedFonts = false;
@@ -1132,7 +1134,9 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 				resourcePromises.push(ProcessorHelper.processAttribute(this.doc.querySelectorAll("video[src], video > source[src]"), "src", this.baseURI, this.options, this.cssVariables, this.styles, this.batchRequest));
 			}
 			await Promise.all(resourcePromises);
-			ProcessorHelper.processShortcutIcons(this.doc);
+			if (this.options.saveFavicon) {
+				ProcessorHelper.processShortcutIcons(this.doc);
+			}
 		}
 
 		async processScripts() {