Substitute “%s” in commands with the target URL
This commit is contained in:
parent
a41b7a70cf
commit
9000b2a3b0
|
@ -5,19 +5,20 @@ let port = browser.runtime.connectNative("shellfox");
|
||||||
function getUrlCommand(url) {
|
function getUrlCommand(url) {
|
||||||
let matchCommand = undefined;
|
let matchCommand = undefined;
|
||||||
let matchRegex = "";
|
let matchRegex = "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let savedCommands = JSON.parse(localStorage.getItem("commands"));
|
let savedCommands = JSON.parse(localStorage.getItem("commands"));
|
||||||
|
// Find the most-applicable command…
|
||||||
for (regexCommandPair of savedCommands) {
|
for (regexCommandPair of savedCommands) {
|
||||||
let regex = regexCommandPair[0];
|
let regex = regexCommandPair[0];
|
||||||
let match = url.match(regex);
|
let match = url.match(regex);
|
||||||
let compared = compareRegexComplexity(matchRegex, regex);
|
let compared = compareRegexComplexity(matchRegex, regex);
|
||||||
console.log(matchRegex, "v", regex, "=", compared);
|
|
||||||
if (match && (compared == 0 || compared == 1)) {
|
if (match && (compared == 0 || compared == 1)) {
|
||||||
matchCommand = regexCommandPair[1];
|
matchCommand = regexCommandPair[1];
|
||||||
matchRegex = regex;
|
matchRegex = regex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// … and replace the substitution-string with the URL.
|
||||||
|
matchCommand = matchCommand.replaceAll("%s", url);
|
||||||
} catch {};
|
} catch {};
|
||||||
return matchCommand;
|
return matchCommand;
|
||||||
}
|
}
|
||||||
|
|
Ŝarĝante…
Reference in New Issue