« get me outta code hell

content, client: use 'track-in-sidebar' for random link in nav - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/static/client2.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-11-15 18:17:15 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-11-15 18:56:55 -0400
commitc399b00ccea8280032e0576a99eab2d34a04355c (patch)
treea4803ffc4c554d13e0a7a91d9b3f95b237d4d571 /src/static/client2.js
parente9d4cd7fb8bb9c55f3dd90b36eec7e246bc2589e (diff)
content, client: use 'track-in-sidebar' for random link in nav
Diffstat (limited to 'src/static/client2.js')
-rw-r--r--src/static/client2.js17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/static/client2.js b/src/static/client2.js
index 0ec052b..b72933d 100644
--- a/src/static/client2.js
+++ b/src/static/client2.js
@@ -187,6 +187,19 @@ function addRandomLinkListeners() {
           break;
         }
 
+        case 'track-in-sidebar': {
+          // Note that the container for track links may be <ol> or <ul>, and
+          // they can't be identified by href, since links from one track to
+          // another don't include "track" in the href.
+          const trackLinks =
+            Array.from(document
+              .querySelector('.track-list-sidebar-box')
+              .querySelectorAll('li a'));
+
+          a.href = pick(trackLinks).href;
+          break;
+        }
+
         /* Legacy links, for old versions             *
          * of generateListRandomPageLinksGroupSection */
 
@@ -255,9 +268,7 @@ function addNavigationKeyPressListeners() {
       } else if (event.charCode === 'P'.charCodeAt(0)) {
         scriptedLinkInfo.previousNavLink?.click();
       } else if (event.charCode === 'R'.charCodeAt(0)) {
-        if (ready) {
-          scriptedLinkInfo.randomNavLink?.click();
-        }
+        scriptedLinkInfo.randomNavLink?.click();
       }
     }
   });