From 596b383a540ce6c16ae6b4a6d572ff9b31a4c329 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Sun, 3 Mar 2024 22:13:04 -0600 Subject: [PATCH] =?UTF-8?q?Add=20options-page=20section=20for=20=E2=80=9CD?= =?UTF-8?q?ownload=20commands=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … though it is completely non-functional, as yet. --- _locales/en/messages.json | 35 +++++++++++++ _locales/eo/messages.json | 35 +++++++++++++ options.html | 55 +++++++++++++------- options.js | 107 +++++++++++++++++++++++++++++++++++++- 4 files changed, 211 insertions(+), 21 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 82afa5d..a62b366 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -101,6 +101,41 @@ "description": "Displayed placeholder for options-page input for regex." }, + "optionsTitleDownload": { + "message": "Download commands", + "description": "Title of options-page section for download commands." + }, + + "optionsDescDownload": { + "message": "Assign commands to be executed for certain URLs (by regex) when downloads are initiated or finished. In commands, $URL will be replaced with the download’s URL, and $FILE with the target file.", + "description": "Description of options-page section for download commands." + }, + + "optionsHeadDownloadRule": { + "message": "URL regex", + "description": "Header of table-element for options-page section for download commands." + }, + + "optionsHeadDownloadCommand": { + "message": "Shell command", + "description": "Header of table-element for options-page section for download commands." + }, + + "optionsHeadDownloadType": { + "message": "Run when…", + "description": "Header of table-element for options-page section for download commands." + }, + + "optionsDownloadWhenStarted": { + "message": "… started", + "description": "Member of menu-list for options-page section for download commands. Completes the sentence, “Run when…”" + }, + + "optionsDownloadWhenFinished": { + "message": "… finished", + "description": "Member of menu-list for options-page section for download commands. Completes the sentence, “Run when…”" + }, + "optionsSaveButton": { "message": "Apply", "description": "Name of button in options-page to save changes." diff --git a/_locales/eo/messages.json b/_locales/eo/messages.json index e626f97..95b7031 100644 --- a/_locales/eo/messages.json +++ b/_locales/eo/messages.json @@ -101,6 +101,41 @@ "description": "Provizora valoro ĉe agordopaĝo por enigo de reteja regula esprimo." }, + "optionsTitleDownload": { + "message": "Elŝutaj ŝel-ordonoj", + "description": "Titolo de agordo-parto por elŝutaj ordonoj." + }, + + "optionsDescDownload": { + "message": "Agordi ordonojn kiuj ruliĝu dum komenciĝo aŭ finiĝo de elŝutado, laŭ URL (regulesprime). En ordonoj, «$URL» anstataŭiĝos per la elŝuta URL, kaj «$FILE» per la elŝuta dosiervojo.", + "description": "Priskribo de agordo-parto por elŝutaj ordonoj." + }, + + "optionsHeadDownloadRule": { + "message": "URL regula esprimo", + "description": "Titolo de tabelo-kolumno ĉe agordo-parto por elŝutaj ordonoj." + }, + + "optionsHeadDownloadCommand": { + "message": "Ŝel-ordono", + "description": "Titolo de tabelo-kolumno ĉe agordo-parto por elŝutaj ordonoj." + }, + + "optionsHeadDownloadType": { + "message": "Rulu je…", + "description": "Titolo de tabelo-kolumno ĉe agordo-parto por elŝutaj ordonoj." + }, + + "optionsDownloadWhenStarted": { + "message": "… komenciĝo", + "description": "Menuero ĉe agordo-parto por elŝutaj ordonoj. Finas la frazon, «Rulu je…»" + }, + + "optionsDownloadWhenFinished": { + "message": "… finiĝo", + "description": "Menuero ĉe agordo-parto por elŝutaj ordonoj. Finas la frazon, «Rulu je…»" + }, + "optionsSaveButton": { "message": "Konservi", "description": "Nomo de butono ĉe agordopaĝo por konservi ŝanĝojn." diff --git a/options.html b/options.html index 55bc6ce..2532fd3 100644 --- a/options.html +++ b/options.html @@ -4,30 +4,47 @@ -
-

Shell commands

-

Add shell commands, to be executed with a page’s URL as its argument. In a command, $URL will be replaced with the target page’s URL.

- - - - - -
NameShell command
- -
+
+
+

Shell commands

+

Add shell commands, to be executed with a page’s URL as its argument. In a command, $URL will be replaced with the target page’s URL.

+ + + + + +
NameShell command
+ +
-
-

URL/Page rules

-

Associate the above commands with URLs, based on regex rules. When a URL is tied to a command, a button will appear in context-menus and the address bar to run said command.

- +
+

URL/Page rules

+

Associate the above commands with URLs, based on regex rules. When a URL is tied to a command, a button will appear in context-menus and the address bar to run said command.

+
+ + + + +
URL regexShell command
+ +
+
+ +
+ +
+

Download commands

+

Assign commands to be executed for certain URLs (by regex) when downloads are initiated or finished. In commands, $URL will be replaced with the download’s URL, and $FILE with the target file.

+ - - + + +
URL regexShell commandOn start/finishURL regexShell command
- - + +
diff --git a/options.js b/options.js index 2518ec5..6c607ce 100644 --- a/options.js +++ b/options.js @@ -35,6 +35,22 @@ function saveRegexRules() { } +// Iterate over the commands-table and save each of the user’s valid +// name+command rows to storage. +function saveDownloadCommands() { + let downloads = []; + for (downloadTr of document.getElementsByClassName("downloadCommandRow")) { + let regex = downloadTr.getElementsByClassName("regex")[0].value; + let command = downloadTr.getElementsByClassName("command")[0].value; + let type = downloadTr.getElementsByClassName("startFinishMenu")[0].value; + if (regex && command && type) + downloads.push([regex, command, type]); + } + console.log(downloads); + localStorage.setItem("downloadCommands", JSON.stringify(downloads)); +} + + // Read the user’s saved name+command pairs from storage, and populate the // command-table with them. function populateCommandTable() { @@ -67,13 +83,29 @@ function populateRegexTable() { } +// Read the user’s saved type+name+command pairs from storage, and populate the +// downloads-table with them. +function populateDownloadTable() { + let downloadTable = document.getElementById("downloadTable"); + try { + let savedDownloads = savedArray("downloadCommands") || []; + for (regexCommandType of savedDownloads) { + let downloadTr = createDownloadTr(regexCommandType[0], regexCommandType[1], regexCommandType[2]); + downloadTable.appendChild(downloadTr); + } + } catch {}; + // And yet again! Have spares!!! + downloadTable.appendChild(createDownloadTr("", "", 0)); +} + + // Create a