mirror of
https://github.com/driftywinds/driftywinds.github.io.git
synced 2025-12-20 03:13:57 +00:00
Refactor
This commit is contained in:
29
js/index.js
29
js/index.js
@@ -1,16 +1,17 @@
|
||||
const textField = document.querySelector("input");
|
||||
(function main() {
|
||||
// If source specified, go straight to home page
|
||||
if (urlSearchParams.has('source') && sourceURL.match(urlRegex))
|
||||
window.location.replace(`home.html?source=${sourceURL}`);
|
||||
|
||||
textField.addEventListener("keypress", function (event) {
|
||||
// If the user presses the "Enter" key on the keyboard
|
||||
if (event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
const textField = document.querySelector("input");
|
||||
textField.addEventListener("keypress", function (event) {
|
||||
if (event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
|
||||
const url = textField.value;
|
||||
const urlRegex = /(https?:\/\/[^ ]*)/g;
|
||||
|
||||
if (!url.match(urlRegex))
|
||||
alert("Invalid URL.");
|
||||
else
|
||||
window.location.replace(`home.html?source=${url}`);
|
||||
}
|
||||
});
|
||||
const url = textField.value;
|
||||
if (!url.match(urlRegex))
|
||||
alert("Invalid URL.");
|
||||
else window.location.replace(`home.html?source=${url}`);
|
||||
}
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user