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