diff --git a/js/search.js b/js/search.js new file mode 100644 index 0000000..5934088 --- /dev/null +++ b/js/search.js @@ -0,0 +1,19 @@ +(function main() { + const success = url => window.location.replace(`${window.location.host}?source=${url}`); + + // If valid source provided + if (urlSearchParams.has('source') && isValidHTTPURL(sourceURL)) + success(sourceURL); + + const textField = document.querySelector("input"); + textField.addEventListener("keypress", function (event) { + if (event.key === "Enter") { + event.preventDefault(); + + const url = textField.value; + if (!isValidHTTPURL(url)) + alert("Invalid HTTP URL."); + else success(url); + } + }); +})(); \ No newline at end of file