Skip to content

Commit 0dc8bfb

Browse files
committed
🐛 Fix button not loading on navigation to video
When navigating from an index page (e.g. /results) to a video page (i.e. /watch), the toggle button was not loading. Listen to a more reliable event for triggering the injection, one that fires on any video page regardless of the user journey.
1 parent 154e697 commit 0dc8bfb

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

script.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,23 @@ function toggleComments() {
2828

2929
function inject(e) {
3030
if (e.type == 'spfdone') {
31-
injected = false; // reset for old UI navigation
31+
injected = false; // old UI requires re-injection on navigation
3232
}
3333
if (injected) {
34-
return; // guard clause because event 'yt-register-action' fires many times
34+
return; // guard clause because we're using a generic event that fires many times
3535
}
3636

3737
if (isOldInterface()) {
3838
addClass();
3939
addButton();
4040
} else {
41-
if (e.target.id != 'comments') {
42-
return; // do not inject if triggering too early
41+
if (e.target.tagName != 'YTD-VIDEO-SECONDARY-INFO-RENDERER') {
42+
return;
4343
}
4444

4545
const oldTriggerEvents = ['DOMContentLoaded', 'spfdone'];
4646
if (oldTriggerEvents.includes(e.type)) {
47-
return; // do not inject for old UI events on new UI
47+
return; // do not inject on old UI events
4848
}
4949

5050
addNewClass();
@@ -110,7 +110,8 @@ function showReadMore() {
110110
}
111111

112112
(function() {
113-
document.addEventListener('DOMContentLoaded', inject); // Static navigation (i.e. initial page load)
114-
document.addEventListener('spfdone', inject); // Dynamic navigation (i.e. subsequent page loads)
115-
document.addEventListener('yt-register-action', inject); // Polymer event for new UI
113+
document.addEventListener('DOMContentLoaded', inject); // Old: Static navigation (i.e. initial page load)
114+
document.addEventListener('spfdone', inject); // Old: Dynamic navigation (i.e. subsequent page loads)
115+
116+
document.addEventListener('yt-visibility-refresh', inject); // New: Inject on info panel render.
116117
})();

0 commit comments

Comments
 (0)