Also substitute referrer-URL into commands
… as the variable $REFERRER.
This commit is contained in:
parent
d2a98a0870
commit
da847fc55c
|
@ -107,7 +107,7 @@
|
|||
},
|
||||
|
||||
"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.",
|
||||
"message": "Assign commands to be executed for certain URLs (by regex) when downloads are initiated or finished. In commands, $FILE will be replaced with the target file, $URL will be replaced with the download’s URL, and $REFERRER with the referring URL.",
|
||||
"description": "Description of options-page section for download commands."
|
||||
},
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@
|
|||
},
|
||||
|
||||
"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.",
|
||||
"message": "Agordi ordonojn kiuj ruliĝu dum komenciĝo aŭ finiĝo de elŝutado, laŭ URL (regulesprime). En ordonoj, «$FILE» anstataŭiĝos per la elŝuta dosiervojo, «$URL» anstataŭiĝos per la elŝuta URL, kaj «$REFERRER» per la deelŝutita URL.",
|
||||
"description": "Priskribo de agordo-parto por elŝutaj ordonoj."
|
||||
},
|
||||
|
||||
|
|
|
@ -99,25 +99,27 @@ function getDownloadCommand(url, type) {
|
|||
}
|
||||
|
||||
|
||||
// Execute the given command string, subsituting “$URL” with url and
|
||||
// “$FILE” with filepath.
|
||||
function runCommand(command, url, filepath) {
|
||||
// Execute the given command string, subsituting “$URL” with url,
|
||||
// “$FILE” with filepath, and “$REFERRER” with referrer.
|
||||
function runCommand(command, url, filepath, referrer) {
|
||||
if (!port)
|
||||
initShellfoxProgram();
|
||||
if (command && port)
|
||||
port.postMessage(command
|
||||
.replaceAll("$URL", url)
|
||||
.replaceAll("${URL}", url)
|
||||
.replaceAll("$REFERRER", referrer || "")
|
||||
.replaceAll("${REFERRER}", referrer || "")
|
||||
.replaceAll("$FILE", filepath)
|
||||
.replaceAll("${FILE}", filepath));
|
||||
}
|
||||
|
||||
|
||||
// Execute the shell command associated with the given URL, if any.
|
||||
function runUrlCommand(url) {
|
||||
function runUrlCommand(url, referrer) {
|
||||
let commands = getUrlCommands(url);
|
||||
if (commands)
|
||||
runCommand(commands[0], url);
|
||||
runCommand(commands[0], url, "", referrer);
|
||||
}
|
||||
|
||||
|
||||
|
@ -264,10 +266,10 @@ browser.menus.onClicked.addListener((info, tab) => {
|
|||
if (itemName == "run-page-command")
|
||||
runUrlCommand(tab.url);
|
||||
else if (itemName == "run-link-command" && info.linkUrl)
|
||||
runUrlCommand(info.linkUrl);
|
||||
runUrlCommand(info.linkUrl, tab.url);
|
||||
else if (itemName.startsWith("run-")) {
|
||||
let command_i = itemName.split("-command-")[1];
|
||||
runCommand(savedArray("commands")[command_i][1], info.linkUrl || tab.url);
|
||||
runCommand(savedArray("commands")[command_i][1], info.linkUrl || tab.url, tab.url);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -280,7 +282,7 @@ browser.browserAction.onClicked.addListener(() => {
|
|||
browser.downloads.onCreated.addListener((downloadItem) => {
|
||||
let command = getDownloadCommand(downloadItem.url, 0);
|
||||
if (command)
|
||||
runCommand(command, downloadItem.url, downloadItem.filename);
|
||||
runCommand(command, downloadItem.url, downloadItem.filename, downloadItem.referrer);
|
||||
});
|
||||
|
||||
|
||||
|
@ -290,7 +292,8 @@ browser.downloads.onChanged.addListener((downloadDelta) => {
|
|||
if (downloadDelta.state.current == "complete" && downloadItems.length > 0) {
|
||||
let command = getDownloadCommand(downloadItems[0].url, 1);
|
||||
if (command)
|
||||
runCommand(command, downloadItems[0].url, downloadItems[0].filename);
|
||||
runCommand(command, downloadItems[0].url,
|
||||
downloadItems[0].filename, downloadItems[0].referrer);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
<article>
|
||||
<h3 id="downloadTitle">Download commands</h3>
|
||||
<p id="downloadP">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.</p>
|
||||
<p id="downloadP">Assign commands to be executed for certain URLs (by regex) when downloads are initiated or finished. In commands, $FILE will be replaced with the target file, $URL will be replaced with the download’s URL, and $REFERRER with the referring URL.</p>
|
||||
<table id="downloadTable">
|
||||
<tr>
|
||||
<th id="downloadTypeTh">On start/finish</th>
|
||||
|
|
Ŝarĝante…
Reference in New Issue