Rename index.js -> search.js

This commit is contained in:
foxster-mp4
2023-04-30 11:00:33 -07:00
parent 7e19894e75
commit cca9ea406f

19
js/search.js Normal file
View File

@@ -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);
}
});
})();