From 60a7c48e078ddd2a8b5b90f101f5179a4eda92aa Mon Sep 17 00:00:00 2001 From: lostydust <47502554+lostdusty@users.noreply.github.com> Date: Fri, 23 Feb 2024 12:04:27 -0300 Subject: [PATCH] Add URL search on frontend Fixes https://github.com/wukko/cobalt/issues/364 Signed-off-by: lostydust <47502554+lostdusty@users.noreply.github.com> --- src/front/cobalt.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/front/cobalt.js b/src/front/cobalt.js index cdf143bc..91409887 100644 --- a/src/front/cobalt.js +++ b/src/front/cobalt.js @@ -7,7 +7,7 @@ const isSafari = ua.match("safari/"); const isFirefox = ua.match("firefox/"); const isOldFirefox = ua.match("firefox/") && ua.split("firefox/")[1].split('.')[0] < 103; -const regex = new RegExp(/https:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()!@:%_\+.~#?&\/\/=]*)/); +const regex = new RegExp(/[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/g); const notification = `
`; const switchers = { @@ -103,13 +103,13 @@ document.addEventListener("keydown", (event) => { } }) function button() { - let regexTest = regex.test(eid("url-input-area").value); + let regexTest = (eid("url-input-area").value).match(regex); if ((eid("url-input-area").value).length > 0) { eid("url-clear").style.display = "block"; } else { eid("url-clear").style.display = "none"; } - regexTest ? changeDownloadButton(1, '>>') : changeDownloadButton(0, '>>'); + regexTest ? changeDownloadButton(1, '>>') : changeDownloadButton(0, '>>'); eid("url-input-area").value = regexTest[0]; } function clearInput() { eid("url-input-area").value = '';