« 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
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
parente9d4cd7fb8bb9c55f3dd90b36eec7e246bc2589e (diff)
content, client: use 'track-in-sidebar' for random link in nav
Diffstat (limited to 'src')
-rw-r--r--src/content/dependencies/generateAlbumNavAccent.js2
-rw-r--r--src/static/client2.js17
2 files changed, 15 insertions, 4 deletions
diff --git a/src/content/dependencies/generateAlbumNavAccent.js b/src/content/dependencies/generateAlbumNavAccent.js
index 7eb1dac0..01c88bf7 100644
--- a/src/content/dependencies/generateAlbumNavAccent.js
+++ b/src/content/dependencies/generateAlbumNavAccent.js
@@ -92,7 +92,7 @@ export default {
         html.tag('a',
           {
             href: '#',
-            'data-random': 'track-in-album',
+            'data-random': 'track-in-sidebar',
             id: 'random-button',
           },
           (data.isTrackPage
diff --git a/src/static/client2.js b/src/static/client2.js
index 0ec052bd..b72933d0 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();
       }
     }
   });