From 9000b2a3b0747b08b0c65c0a080857a9b2585c5a Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Wed, 28 Feb 2024 18:52:02 -0600 Subject: [PATCH] =?UTF-8?q?Substitute=20=E2=80=9C%s=E2=80=9D=20in=20comman?= =?UTF-8?q?ds=20with=20the=20target=20URL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- background.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/background.js b/background.js index 26793c7..b4a5b40 100644 --- a/background.js +++ b/background.js @@ -5,19 +5,20 @@ let port = browser.runtime.connectNative("shellfox"); function getUrlCommand(url) { let matchCommand = undefined; let matchRegex = ""; - try { let savedCommands = JSON.parse(localStorage.getItem("commands")); + // Find the most-applicable command… for (regexCommandPair of savedCommands) { let regex = regexCommandPair[0]; let match = url.match(regex); let compared = compareRegexComplexity(matchRegex, regex); - console.log(matchRegex, "v", regex, "=", compared); if (match && (compared == 0 || compared == 1)) { matchCommand = regexCommandPair[1]; matchRegex = regex; } } + // … and replace the substitution-string with the URL. + matchCommand = matchCommand.replaceAll("%s", url); } catch {}; return matchCommand; }