Skip to content

Latest commit

 

History

History
81 lines (81 loc) · 3.1 KB

user.md

File metadata and controls

81 lines (81 loc) · 3.1 KB
<style> body { display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; } section { text-align: center; } .nes-field { margin-bottom: 20px; } </style>
Name
PLAY NOW
<script> var hoverSound = document.getElementById("hoverSound"); var myButton = document.getElementById("myButton"); var inputField = document.getElementById("error_field"); myButton.addEventListener("mouseenter", playHoverSound); myButton.addEventListener("click", saveInputValue); function playHoverSound() { hoverSound.currentTime = 0; // Reset the playback position to the beginning hoverSound.play(); } function saveInputValue(event) { event.preventDefault(); var name = inputField.value; // Send the data to the server var xhr = new XMLHttpRequest(); xhr.open("POST", "/save-name", true); xhr.setRequestHeader("Content-Type", "application/json"); xhr.onreadystatechange = function () { if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) { // Handle the server response here console.log(xhr.responseText); // Redirect to the next page window.location.href = "{{ site.baseurl }}/story"; } }; xhr.send(JSON.stringify({ name: name })); } // function saveName() { // var nameInput = document.getElementById("nameInput"); // var name = nameInput.value; // localStorage.setItem("name", name); // alert("Name saved to local storage: " + name); // // Redirect to the next page with the name as a query parameter // window.location.href = "{{ site.baseurl }}/story?name=" + encodeURIComponent(name); // } // // Load the saved name from local storage on page load // window.onload = function() { // var savedName = localStorage.getItem("name"); // if (savedName) { // var nameInput = document.getElementById("nameInput"); // nameInput.value = savedName; // } // }; function saveName() { var name = document.getElementById("nameInput").value; localStorage.setItem("userName", name); window.location.href = "page2.html"; } </script>