From c4039f10452516ddc1a8ded25b5750624b02bc14 Mon Sep 17 00:00:00 2001 From: Ashley Date: Sun, 12 Mar 2023 07:29:19 +0000 Subject: [PATCH] add ambient music !! --- html/search.ejs | 82 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 4 deletions(-) diff --git a/html/search.ejs b/html/search.ejs index 68adcfd7..7d215fcc 100644 --- a/html/search.ejs +++ b/html/search.ejs @@ -200,7 +200,7 @@ border:solid; opacity: 1; transform: scale(1, 1); } - + .loading { position: fixed; top: 0; @@ -230,6 +230,9 @@ border:solid; } } + .a { + display:none; + } @@ -296,8 +299,13 @@ video[counter].classList.add("shake"); - +
+ + + @@ -431,7 +439,9 @@ font-weight: 1000; <%=j.Search.estimatedResults.toLocaleString()%> Results (estimated)

- + + + @@ -518,7 +528,71 @@ links.forEach(link => { window.location.href = link.href; }, 500); }); -}); +}); + const audioElement = document.getElementById("audio"); +audioElement.volume = 0.1; +let audioToggled = JSON.parse(localStorage.getItem("audioToggled")); + +// When the audio player is loaded, check for stored time value and set current time +audioElement.addEventListener("loadedmetadata", () => { + if (audioToggled) { + const storedTime = localStorage.getItem("audioTime"); + if (storedTime) { + audioElement.currentTime = storedTime; + } + } +}); + +// When the user leaves the page, store the current time value +window.addEventListener("beforeunload", () => { + if (audioToggled) { + localStorage.setItem("audioTime", audioElement.currentTime); + } +}); + +const audio = document.getElementById("audio"); +const button = document.getElementById("audioButton"); +const icon = document.getElementById("audioIcon"); + +function toggleAudio() { + if (audio.paused) { + audio.play(); + audio.volume = 0.1; + button.classList.add("playing"); + icon.classList.remove("fa-play"); + icon.classList.add("fa-pause"); + localStorage.setItem("audioToggled", true); // save that audio is toggled + } else { + audio.pause(); + button.classList.remove("playing"); + icon.classList.remove("fa-pause"); + icon.classList.add("fa-play"); + localStorage.setItem("audioToggled", false); // save that audio is not toggled + } +} + +if (audioToggled === null || audioToggled === undefined) { + audioToggled = true; +} + +if (audioToggled == false) { + audio.pause(); + button.classList.remove("playing"); + icon.classList.remove("fa-pause"); + icon.classList.add("fa-play"); +} else { + audio.play(); + audio.volume = 0.1; + audio.src = "https://tube.kuylar.dev/proxy/media/MGPx242O--U/18" + button.classList.add("playing"); + icon.classList.remove("fa-play"); + icon.classList.add("fa-pause"); +} + +// Show the audio button +button.style.display = "block"; + + \ No newline at end of file