Skip to content

Commit

Permalink
Merge pull request #2387 from raszpl/patch-17
Browse files Browse the repository at this point in the history
playlist.js undefined 'playlistData' proper fix, even safer
  • Loading branch information
ImprovedTube authored Jun 18, 2024
2 parents 3cb2844 + b979e4c commit 9e3a96c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
4 changes: 4 additions & 0 deletions js&css/web-accessible/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ document.addEventListener('it-message-from-extension', function () {
case 'playerHideControls':
ImprovedTube.playerControls();
break
case 'playerlistUpNextAutoplay':
if (this.storage.playlist_up_next_autoplay !== false) {
if (playlistData.currentIndex != playlistData.localCurrentIndex) { playlistData.currentIndex = playlistData.localCurrentIndex;} }
break
}

if (ImprovedTube[camelized_key]) {
Expand Down
23 changes: 9 additions & 14 deletions js&css/web-accessible/www.youtube.com/playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,16 @@
/*------------------------------------------------------------------------------
4.5.1 UP NEXT AUTOPLAY
------------------------------------------------------------------------------*/
ImprovedTube.playlistUpNextAutoplay = function (event) {
if (
ImprovedTube.getParam(location.href, 'list') &&
ImprovedTube.storage.playlist_up_next_autoplay === false
) {
try { if (this.elements.ytd_watch.playlistData)
{this.elements.ytd_watch.playlistData.currentIndex = this.elements.ytd_watch.playlistData.totalVideos}
else {var tries = 0; var intervalMs = 300; var maxTries = 6;
var waitForPlaylist = setInterval(() => {
if (this.elements.ytd_watch.playlistData || (++tries >= maxTries) ) {
this.elements.ytd_watch.playlistData.currentIndex = this.elements.ytd_watch.playlistData.totalVideos; clearInterval(waitForPlaylist );}
intervalMs *= 1.4;}, intervalMs);
} } catch (error) { console.error("Waiting for playlist", error);}
ImprovedTube.playlistUpNextAutoplay = function (event) { if (this.storage.playlist_up_next_autoplay === false) {
const playlistData = this.elements.ytd_watch?.playlistData;
if (this.getParam(location.href, 'list') && playlistData
&& playlistData.currentIndex
&& playlistData.totalVideos
&& playlistData.localCurrentIndex) {
playlistData.currentIndex = playlistData.totalVideos;
}
}
};
};
/*------------------------------------------------------------------------------
4.5.2 REVERSE
------------------------------------------------------------------------------*/
Expand Down

0 comments on commit 9e3a96c

Please sign in to comment.