diff --git a/frontend/index.html b/frontend/index.html index 675ab2e..b1e350d 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -7,14 +7,14 @@ -
+ - +
{{range $Store := .Stores }} diff --git a/frontend/scripts/search.js b/frontend/scripts/search.js index 8c87c5b..812d3e1 100644 --- a/frontend/scripts/search.js +++ b/frontend/scripts/search.js @@ -1 +1,38 @@ -console.log("included search") +console.log("adding features to search..."); + +const form = document.getElementById("search-form"); +const input = document.getElementById("search-input"); + +const searchEngines = { + "g": { + action: "https://www.google.com/search/", + name: "q", + }, + "d": { + action: "https://duckduckgo.com/", + name: "q", + }, + "y": { + action: "https://yandex.com/search/", + name: "text", + }, + "lure": { + action: "https://lure.sh/pkgs", + name: "q", + }, +}; + +// https://stackoverflow.com/a/3809435/16804841 +const expression = /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gi; +const urlRegex = new RegExp(expression); + +form.addEventListener("submit", event => { + s = input.value; + + // check if url + if (s.match(urlRegex)) { + event.preventDefault(); + window.open(s, "_self"); + return + } +});