]> littlesong.place Git - littlesongplace.git/commitdiff
Fix bugs with refreshing the page
authorChris Fulljames <christianfulljames@gmail.com>
Thu, 26 Jun 2025 11:15:59 +0000 (07:15 -0400)
committerChris Fulljames <christianfulljames@gmail.com>
Thu, 26 Jun 2025 11:22:01 +0000 (07:22 -0400)
src/littlesongplace/static/nav.js
src/littlesongplace/static/player.js

index b369974306f8cd2c863c06c4b01c63a025756e90..8a03c74271a085ee85833043091ce6734f5bd337 100644 (file)
@@ -1,4 +1,9 @@
-document.addEventListener("DOMContentLoaded", (e) => {
+var m_firstLoadNav = true;
+document.addEventListener("DOMContentLoaded", async (e) => {
+    if (m_firstLoadNav) {
+        m_firstLoadNav = false;
+        window.history.replaceState(document.documentElement.outerHTML, "");
+    }
 
     // Handle link clicks with AJAX
     document.querySelectorAll("a").forEach((anchor) => {
index e48fe811fce5acbf875ffafa899737ddaee6589f..b14d598c5fc88e0754f88e342ac458cfdb8ac924 100644 (file)
@@ -177,17 +177,21 @@ function songUpdate() {
 }
 
 // Add event listeners
-var m_firstLoad = true;
+var m_firstLoadPlayer = true;
 document.addEventListener("DOMContentLoaded", (event) => {
 
+    // Sync volume with current slider position (may be reset after refresh)
+    var audio = document.getElementById("player-audio");
+    const slider = document.getElementById("volume-slider");
+    audio.volume = slider.value;
+
     // The player never gets rebuilt, so we only need to set it up the first time
-    if (!m_firstLoad) {
+    if (!m_firstLoadPlayer) {
         return;
     }
-    m_firstLoad = false;
+    m_firstLoadPlayer = false;
 
     // Audio playback position while playing
-    var audio = document.getElementById("player-audio");
     audio.addEventListener("timeupdate", songUpdate);
 
     // Next song on audio playback end