Kaynağa Gözat

added option 'file name conflict resolution'

Gildas 7 yıl önce
ebeveyn
işleme
cf15092b20

+ 16 - 0
_locales/en/messages.json

@@ -119,6 +119,22 @@
         "message": "open the \"Save as\" dialog to confirm the file name",
         "description": "Options page label: 'open the \"Save as\" dialog to confirm the file name'"
     },
+    "optionConflictAction": {
+        "message": "file name conflict resolution",
+        "description": "Options page label: 'filename conflict resolution'"
+    },
+    "optionConflictActionUniquify": {
+        "message": "create a unique name",
+        "description": "Value for 'filename conflict resolution' option: 'create a unique name'"
+    },
+    "optionConflictActionOverwrite": {
+        "message": "overwrite the existing file",
+        "description": "Value for 'filename conflict resolution' option: 'overwrite the existing file'"
+    },
+    "optionConflictActionPrompt": {
+        "message": "prompt for a name",
+        "description": "Value for 'name conflict resolution' option: 'prompt for a name'"
+    },
     "optionsHTMLContentSubTitle": {
         "message": "HTML content",
         "description": "Options sub-title: 'HTML content'"

+ 16 - 0
_locales/fr/messages.json

@@ -119,6 +119,22 @@
         "message": "ouvrir la boite de dialogue \"Sauver sous\" pour confimer le nom de fichier",
         "description": "Options page label: 'open the \"Save as\" dialog to confirm the file name'"
     },
+    "optionConflictAction": {
+        "message": "résolution de conflit de noms",
+        "description": "Options page label: 'filename conflict resolution'"
+    },
+    "optionConflictActionUniquify": {
+        "message": "créer un nom unique",
+        "description": "Value for 'filename conflict resolution' option: 'create a unique filename'"
+    },
+    "optionConflictActionOverwrite": {
+        "message": "écraser le fichier existant",
+        "description": "Value for 'filename conflict resolution' option: 'overwrite the existing file'"
+    },
+    "optionConflictActionPrompt": {
+        "message": "demander un nom de fichier",
+        "description": "Value for 'filename conflict resolution' option: 'prompt for a filename'"
+    },
     "optionsHTMLContentSubTitle": {
         "message": "Contenu HTML",
         "description": "Options sub-title: 'HTML content'"

+ 16 - 0
_locales/ja/messages.json

@@ -119,6 +119,22 @@
         "message": "を開く(として保存する:ファイル名を確認するためのダイアログ)",
         "description": "オプションのページラベル: 'を開く(として保存する:ファイル名を確認するためのダイアログ)'"
     },
+    "optionConflictAction": {
+        "message": "file name conflict resolution",
+        "description": "Options page label: 'filename conflict resolution'"
+    },
+    "optionConflictActionUniquify": {
+        "message": "create a unique name",
+        "description": "Value for 'filename conflict resolution' option: 'create a unique name'"
+    },
+    "optionConflictActionOverwrite": {
+        "message": "overwrite the existing file",
+        "description": "Value for 'filename conflict resolution' option: 'overwrite the existing file'"
+    },
+    "optionConflictActionPrompt": {
+        "message": "prompt for a name",
+        "description": "Value for 'name conflict resolution' option: 'prompt for a name'"
+    },
     "optionsHTMLContentSubTitle": {
         "message": "HTML コンテンツ",
         "description": "オプションのサブタイトル: 'HTML コンテンツ'"

+ 16 - 0
_locales/pl/messages.json

@@ -119,6 +119,22 @@
         "message": "otwieraj okno \"Zapisz jako\", aby potwierdzić nazwę pliku",
         "description": "Options page label: 'open the \"Save as\" dialog to confirm the file name'"
     },
+    "optionConflictAction": {
+        "message": "file name conflict resolution",
+        "description": "Options page label: 'filename conflict resolution'"
+    },
+    "optionConflictActionUniquify": {
+        "message": "create a unique name",
+        "description": "Value for 'filename conflict resolution' option: 'create a unique name'"
+    },
+    "optionConflictActionOverwrite": {
+        "message": "overwrite the existing file",
+        "description": "Value for 'filename conflict resolution' option: 'overwrite the existing file'"
+    },
+    "optionConflictActionPrompt": {
+        "message": "prompt for a name",
+        "description": "Value for 'name conflict resolution' option: 'prompt for a name'"
+    },
     "optionsHTMLContentSubTitle": {
         "message": "Zawartość HTML",
         "description": "Options sub-title: 'HTML content'"

+ 16 - 0
_locales/ru/messages.json

@@ -119,6 +119,22 @@
         "message": "открывать диалоговое окно \"Сохранить как\" для подтверждения имени файла",
         "description": "Options page label: 'open the \"Save as\" dialog to confirm the file name'"
     },
+    "optionConflictAction": {
+        "message": "file name conflict resolution",
+        "description": "Options page label: 'filename conflict resolution'"
+    },
+    "optionConflictActionUniquify": {
+        "message": "create a unique name",
+        "description": "Value for 'filename conflict resolution' option: 'create a unique name'"
+    },
+    "optionConflictActionOverwrite": {
+        "message": "overwrite the existing file",
+        "description": "Value for 'filename conflict resolution' option: 'overwrite the existing file'"
+    },
+    "optionConflictActionPrompt": {
+        "message": "prompt for a name",
+        "description": "Value for 'name conflict resolution' option: 'prompt for a name'"
+    },
     "optionsHTMLContentSubTitle": {
         "message": "HTML-контент",
         "description": "Options sub-title: 'HTML content'"

+ 16 - 0
_locales/zh_CN/messages.json

@@ -119,6 +119,22 @@
         "message": "打开“另存为”对话框以确认文件名",
         "description": "选项页标签: '打开“另存为”对话框以确认文件名'"
     },
+    "optionConflictAction": {
+        "message": "file name conflict resolution",
+        "description": "Options page label: 'filename conflict resolution'"
+    },
+    "optionConflictActionUniquify": {
+        "message": "create a unique name",
+        "description": "Value for 'filename conflict resolution' option: 'create a unique name'"
+    },
+    "optionConflictActionOverwrite": {
+        "message": "overwrite the existing file",
+        "description": "Value for 'filename conflict resolution' option: 'overwrite the existing file'"
+    },
+    "optionConflictActionPrompt": {
+        "message": "prompt for a name",
+        "description": "Value for 'name conflict resolution' option: 'prompt for a name'"
+    },
     "optionsHTMLContentSubTitle": {
         "message": "HTML 内容",
         "description": "选项页副标题: 'HTML 内容'"

+ 4 - 0
extension/core/bg/config.js

@@ -37,6 +37,7 @@ singlefile.config = (() => {
 		infobarTemplate: "",
 		confirmInfobar: false,
 		confirmFilename: false,
+		conflictAction: "uniquify",
 		contextMenuEnabled: true,
 		shadowEnabled: true,
 		maxResourceSizeEnabled: false,
@@ -166,6 +167,9 @@ singlefile.config = (() => {
 		if (config.confirmFilename === undefined) {
 			config.confirmFilename = false;
 		}
+		if (config.conflictAction === undefined) {
+			config.conflictAction = "uniquify";
+		}
 	}
 
 	async function getConfig() {

+ 4 - 3
extension/core/bg/download.js

@@ -28,10 +28,10 @@ singlefile.download = (() => {
 				if (request.content) {
 					request.url = URL.createObjectURL(new Blob([request.content], { type: "text/html" }));
 				}
-				return downloadPage(request, { confirmFilename: request.confirmFilename, incognito: sender.tab.incognito })
+				return downloadPage(request, { confirmFilename: request.confirmFilename, incognito: sender.tab.incognito, conflictAction: request.conflictAction })
 					.catch(error => {
 						if (error.message && error.message.includes("'incognito'")) {
-							return downloadPage(request, { confirmFilename: request.confirmFilename });
+							return downloadPage(request, { confirmFilename: request.confirmFilename, conflictAction: request.conflictAction });
 						} else {
 							return { notSupported: true };
 						}
@@ -48,7 +48,8 @@ singlefile.download = (() => {
 		const downloadInfo = {
 			url: page.url,
 			saveAs: options.confirmFilename,
-			filename: page.filename
+			filename: page.filename,
+			conflictAction: options.conflictAction
 		};
 		if (options.incognito) {
 			downloadInfo.incognito = true;

+ 2 - 2
extension/core/content/content.js

@@ -194,9 +194,9 @@ this.singlefile.top = this.singlefile.top || (() => {
 
 	async function downloadPage(page, options) {
 		if (options.backgroundSave) {
-			const response = await browser.runtime.sendMessage({ download: true, url: page.url, confirmFilename: options.confirmFilename, filename: page.filename });
+			const response = await browser.runtime.sendMessage({ download: true, url: page.url, confirmFilename: options.confirmFilename, conflictAction: options.conflictAction, filename: page.filename });
 			if (response.notSupported) {
-				const response = await browser.runtime.sendMessage({ download: true, content: page.content, confirmFilename: options.confirmFilename, filename: page.filename });
+				const response = await browser.runtime.sendMessage({ download: true, content: page.content, confirmFilename: options.confirmFilename, conflictAction: options.conflictAction, filename: page.filename });
 				if (response.notSupported) {
 					downloadPageFallback(page, options);
 				}

+ 11 - 0
extension/ui/bg/options.js

@@ -39,6 +39,10 @@
 	const setMaxResourceSizeLabel = document.getElementById("setMaxResourceSizeLabel");
 	const maxResourceSizeLabel = document.getElementById("maxResourceSizeLabel");
 	const confirmFilenameLabel = document.getElementById("confirmFilenameLabel");
+	const conflictActionLabel = document.getElementById("conflictActionLabel");
+	const conflictActionUniquifyLabel = document.getElementById("conflictActionUniquifyLabel");
+	const conflictActionOverwriteLabel = document.getElementById("conflictActionOverwriteLabel");
+	const conflictActionPromptLabel = document.getElementById("conflictActionPromptLabel");
 	const removeAudioLabel = document.getElementById("removeAudioLabel");
 	const removeVideoLabel = document.getElementById("removeVideoLabel");
 	const displayInfobarLabel = document.getElementById("displayInfobarLabel");
@@ -81,6 +85,7 @@
 	const maxResourceSizeInput = document.getElementById("maxResourceSizeInput");
 	const maxResourceSizeEnabledInput = document.getElementById("maxResourceSizeEnabledInput");
 	const confirmFilenameInput = document.getElementById("confirmFilenameInput");
+	const conflictActionInput = document.getElementById("conflictActionInput");
 	const removeAudioSrcInput = document.getElementById("removeAudioSrcInput");
 	const removeVideoSrcInput = document.getElementById("removeVideoSrcInput");
 	const displayInfobarInput = document.getElementById("displayInfobarInput");
@@ -149,6 +154,10 @@
 	setMaxResourceSizeLabel.textContent = browser.i18n.getMessage("optionSetMaxResourceSize");
 	maxResourceSizeLabel.textContent = browser.i18n.getMessage("optionMaxResourceSize");
 	confirmFilenameLabel.textContent = browser.i18n.getMessage("optionConfirmFilename");
+	conflictActionLabel.textContent = browser.i18n.getMessage("optionConflictAction");
+	conflictActionUniquifyLabel.textContent = browser.i18n.getMessage("optionConflictActionUniquify");
+	conflictActionOverwriteLabel.textContent = browser.i18n.getMessage("optionConflictActionOverwrite");
+	conflictActionPromptLabel.textContent = browser.i18n.getMessage("optionConflictActionPrompt");
 	removeAudioLabel.textContent = browser.i18n.getMessage("optionRemoveAudio");
 	removeVideoLabel.textContent = browser.i18n.getMessage("optionRemoveVideo");
 	displayInfobarLabel.textContent = browser.i18n.getMessage("optionDisplayInfobar");
@@ -199,6 +208,7 @@
 		maxResourceSizeInput.value = config.maxResourceSize;
 		maxResourceSizeInput.disabled = !config.maxResourceSizeEnabled;
 		confirmFilenameInput.checked = config.confirmFilename;
+		conflictActionInput.value = config.conflictAction;
 		removeAudioSrcInput.checked = config.removeAudioSrc;
 		removeVideoSrcInput.checked = config.removeVideoSrc;
 		displayInfobarInput.checked = config.displayInfobar;
@@ -238,6 +248,7 @@
 			maxResourceSizeEnabled: maxResourceSizeEnabledInput.checked,
 			maxResourceSize: Math.max(maxResourceSizeInput.value, 0),
 			confirmFilename: confirmFilenameInput.checked,
+			conflictAction: conflictActionInput.value,
 			removeAudioSrc: removeAudioSrcInput.checked,
 			removeVideoSrc: removeVideoSrcInput.checked,
 			displayInfobar: displayInfobarInput.checked,

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

@@ -173,6 +173,11 @@
 						<p class="notice">It is recommended to
 							<u>uncheck</u> this option</p>
 					</li>
+					<li>
+						<span class="option">file name conflict resolution</span>
+						<p>Choose the most appropriate action when a the filename of the saved page is conflicting with existing ones on
+							the filesystem.</p>
+					</li>
 				</ul>
 				<p>HTML content</p>
 				<ul>

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

@@ -42,6 +42,14 @@
 			<label for="confirmFilenameInput" id="confirmFilenameLabel"></label>
 			<input type="checkbox" id="confirmFilenameInput">
 		</div>
+		<div class="option">
+			<label for="conflictActionInput" id="conflictActionLabel"></label>
+			<select id="conflictActionInput">
+				<option id="conflictActionUniquifyLabel" value="uniquify"></option>
+				<option id="conflictActionOverwriteLabel" value="overwrite"></option>
+				<option id="conflictActionPromptLabel" value="prompt"></option>
+			</select>
+		</div>
 	</details>
 	<details>
 		<summary id="htmlContentLabel"></summary>