Pārlūkot izejas kodu

added an option to enter the file name before saving the page

Gildas 7 gadi atpakaļ
vecāks
revīzija
f1e35d7774

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

@@ -33,6 +33,7 @@ singlefile.config = (() => {
 		compressCSS: true,
 		lazyLoadImages: true,
 		appendSaveDate: true,
+		confirmFilename: false,
 		contextMenuEnabled: true,
 		shadowEnabled: true,
 		maxResourceSizeEnabled: false,

+ 14 - 9
extension/core/content/content.js

@@ -18,7 +18,7 @@
  *   along with SingleFile.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-/* global SingleFile, singlefile, FrameTree, document, Blob, MouseEvent, getSelection, getComputedStyle */
+/* global SingleFile, singlefile, FrameTree, document, Blob, MouseEvent, getSelection, getComputedStyle, prompt */
 
 (() => {
 
@@ -38,7 +38,7 @@
 			processing = true;
 			try {
 				const page = await processMessage(message);
-				downloadPage(page);
+				downloadPage(page, message.options);
 				revokeDownloadURL(page);
 			} catch (error) {
 				browser.runtime.sendMessage({ processError: true, error });
@@ -183,13 +183,18 @@
 		return "";
 	}
 
-	function downloadPage(page) {
-		const link = document.createElement("a");
-		document.body.appendChild(link);
-		link.download = page.filename;
-		link.href = page.url;
-		link.dispatchEvent(new MouseEvent("click"));
-		link.remove();
+	function downloadPage(page, options) {
+		if (options.confirmFilename) {
+			page.filename = prompt("File name", page.filename);
+		}
+		if (page.filename && page.filename.length) {
+			const link = document.createElement("a");
+			document.body.appendChild(link);
+			link.download = page.filename;
+			link.href = page.url;
+			link.dispatchEvent(new MouseEvent("click"));
+			link.remove();
+		}
 	}
 
 })();

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

@@ -39,6 +39,7 @@
 		const shadowEnabledInput = document.getElementById("shadowEnabledInput");
 		const maxResourceSizeInput = document.getElementById("maxResourceSizeInput");
 		const maxResourceSizeEnabledInput = document.getElementById("maxResourceSizeEnabledInput");
+		const confirmFilenameInput = document.getElementById("confirmFilenameInput");
 		let pendingSave = Promise.resolve();
 		document.getElementById("resetButton").addEventListener("click", async () => {
 			await bgPage.singlefile.config.reset();
@@ -66,6 +67,7 @@
 			maxResourceSizeEnabledInput.checked = config.maxResourceSizeEnabled;
 			maxResourceSizeInput.value = config.maxResourceSize;
 			maxResourceSizeInput.disabled = !config.maxResourceSizeEnabled;
+			confirmFilenameInput.checked = config.confirmFilename;
 		}
 
 		async function update() {
@@ -84,7 +86,8 @@
 				appendSaveDate: appendSaveDateInput.checked,
 				shadowEnabled: shadowEnabledInput.checked,
 				maxResourceSizeEnabled: maxResourceSizeEnabledInput.checked,
-				maxResourceSize: maxResourceSizeInput.value
+				maxResourceSize: maxResourceSizeInput.value,
+				confirmFilename: confirmFilenameInput.checked
 			});
 			await pendingSave;
 			await bgPage.singlefile.ui.update();

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

@@ -66,6 +66,15 @@
 							<u>check</u> this option</p>
 					</li>
 
+					<li>
+						<span class="option">confirm file name before saving the page</span>
+						<p>Check this option to display a prompt asking you to enter the file name of the saved page.
+						</p>
+						<p class="notice">It is recommended to
+							<u>uncheck</u> this option</p>
+					</li>
+					<label for="confirmFilenameInput"></label>
+
 					<li>
 						<span class="option">save lazy loaded images</span>
 						<p>Check this option to save all the lazy loaded images that are not displayed. This may help to save all the images without

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

@@ -25,6 +25,10 @@
 				<label for="appendSaveDateInput">append the save date to the filename</label>
 				<input type="checkbox" id="appendSaveDateInput">
 			</div>
+			<div class="option">
+				<label for="confirmFilenameInput">confirm file name before saving the page</label>
+				<input type="checkbox" id="confirmFilenameInput">
+			</div>
 			<h4>Page content</h4>
 			<div class="option">
 				<label for="lazyLoadImagesInput">save lazy loaded images</label>