From b6eca7f9ef14bfc47188e07c744f33ad65974fe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Heym=C3=A8s?= Date: Thu, 14 May 2020 22:44:56 +0200 Subject: [PATCH] Enforce activated class on track waypoint when using previous/next handlers --- contentScript.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/contentScript.js b/contentScript.js index 4ef72bc..868b848 100644 --- a/contentScript.js +++ b/contentScript.js @@ -1,7 +1,7 @@ (function(window, document) { function FeedPlaylist() { - if (!window.playerview) { + if (!window.playerview || !window.Dom) { console.error('[bandcampFeedPlaylist] player is not found.') return null; } @@ -22,7 +22,7 @@ this.$position = this.$el.querySelector('#track_play_waypoints_controls_position'); this.$duration = this.$el.querySelector('#track_play_waypoints_controls_duration'); - this.observe(); + this.observe(); this.registerMediaKeys(); console.debug('[bandcampFeedPlaylist] injected'); } @@ -82,6 +82,19 @@ let timer = setTimeout(this.handlerNextTrack, 1000); timer = undefined; } + + // We try to force the waypoint offset to show 'activated' properly + const track = window.playerview._current_track_list_entry(); + const $story = document.querySelector(`[data-trackid='${track.id}'`); + + if (!$story) return + + if (!window.Dom.inViewport($story)) { + // We push at the end of execution stack + setTimeout(() => { + this.$trackPlayWaypoint.classList.add('activated') + }, 0) + } return; }