diff --git a/goodtube.js b/goodtube.js
index 4a71617..14f371e 100644
--- a/goodtube.js
+++ b/goodtube.js
@@ -655,6 +655,9 @@
// Populate the playlist info
let goodTube_player_populatePlaylistInfo_timeout = setTimeout(() => {}, 0);
function goodTube_player_populatePlaylistInfo() {
+ // Re fetch the page API
+ goodTube_page_api = document.getElementById('movie_player');
+
// Make sure we have access to the frame API
if (typeof goodTube_page_api.getPlaylist === 'function' && typeof goodTube_page_api.getPlaylistIndex === 'function') {
goodTube_playlist = goodTube_page_api.getPlaylist();
@@ -1105,11 +1108,14 @@
// Video has ended
function goodTube_nav_videoEnded() {
+ // Populate the playlist info
+ goodTube_player_populatePlaylistInfo();
+
// If (autoplay is enabled) OR (we're viewing a playlist AND we're not on the last video)
if (
goodTube_autoplay === 'true'
||
- (goodTube_playlist && (goodTube_playlistIndex === (goodTube_playlist.length - 1)))
+ (goodTube_playlist && (goodTube_playlistIndex < (goodTube_playlist.length - 1)))
) {
// Play the next video
goodTube_nav_next();
@@ -1277,8 +1283,7 @@
// Next video
else if (event.data === 'goodTube_nextVideo') {
- // Call the video ended function here, this helps support the shuffle and repeat playlist functionality
- goodTube_nav_videoEnded();
+ goodTube_nav_next();
}
// Video has ended
@@ -2328,7 +2333,7 @@