Skip to content

Commit 9bb651c

Browse files
committed
#488 transmit regex + switches to regex101
1 parent 00bdb4a commit 9bb651c

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

html/options.js

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ async function validateLicenseInOptions(evt = false) {
804804
// util.logDebug("validateLicense - result = " + result);
805805
}
806806

807-
function initButtons() {
807+
async function initButtons() {
808808
// License Tab
809809
document.getElementById("btnValidateLicense").addEventListener("click", QuickFolders.Options.validateNewKey);
810810
document.getElementById("btnPasteLicense").addEventListener("click", QuickFolders.Options.pasteLicense);
@@ -863,12 +863,33 @@ function initButtons() {
863863
QuickFolders.Util.openLinkInTab("https://quickfolders.org/premium.html#findRelated");
864864
});
865865

866-
document.querySelector(".editRegex").addEventListener("click", (event) => {
867-
const editBox = document.getElementById("findRelatedPattern"),
868-
expression = editBox.value,
869-
encodedRegex = expression ? encodeURIComponent(expression) : "enter search pattern";
866+
document.querySelector(".editRegex").addEventListener("click", async(event) => {
867+
const editBox = document.getElementById("findRelatedPattern");
868+
869+
let searchValue = editBox.value, // allow overwriting in debugger for test!
870+
searchFlags = "",
871+
flagsParam = "";
872+
873+
if (searchValue.charAt(0) == "/") {
874+
let endIdx = searchValue.lastIndexOf("/");
875+
if (endIdx) { // must be>0! otherwise 2nd slash is missing!!
876+
searchValue = editBox.value.substring(1, endIdx);
877+
searchFlags = editBox.value.substring(endIdx + 1);
878+
} else {
879+
const isDebug = await messenger.LegacyPrefs.getPref(legacyPrefPath("debug"));
880+
if (isDebug){
881+
console.log(`Invalid search string in find Related - missing 2nd '/' : ${searchFlags}`);
882+
}
883+
searchFlags = searchOptions.pattern.substring(1); // removing beginning '/'
884+
}
885+
}
886+
887+
encodedRegex = searchValue ? encodeURIComponent(searchValue) : "enter search pattern";
888+
if (searchFlags) {
889+
flagsParam = "&flags=" + encodeURIComponent(searchFlags);
890+
}
870891

871-
const targetUrl = `https://regex101.com/?flavor=javascript&regex=${encodedRegex}`;
892+
const targetUrl = `https://regex101.com/?flavor=javascript&regex=${encodedRegex}${flagsParam}`;
872893
QuickFolders.Util.openLinkInTab(targetUrl);
873894
});
874895

0 commit comments

Comments
 (0)