Skip to content

Commit

Permalink
Update player.js
Browse files Browse the repository at this point in the history
recommitted code-charity#1813 (with some minor changes)
  • Loading branch information
MAZ01001 committed Nov 15, 2023
1 parent bbe2df3 commit 3c82806
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions js&css/web-accessible/www.youtube.com/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -725,15 +725,26 @@ ImprovedTube.playerPopupButton = function () {
child: svg,
opacity: 0.8,
onclick: function () {
var player = ImprovedTube.elements.player;

player.pauseVideo();

let urlPopup = `${location.protocol}//www.youtube.com/embed/${location.search.match(ImprovedTube.regex.video_id)[1]}?start=${parseInt(player.getCurrentTime())}&autoplay=${(ImprovedTube.storage.player_autoplay ?? true) ? '1' : '0'}`;
const listMatch = location.search.match(ImprovedTube.regex.playlist_id);
if (listMatch) urlPopup += `&list=${listMatch[1]}`;

window.open(urlPopup, '_blank', `directories=no,toolbar=no,location=no,menubar=no,status=no,titlebar=no,scrollbars=no,resizable=no,width=${player.offsetWidth},height=${player.offsetHeight}`);
const ytPlayer = ImprovedTube.elements.player;

ytPlayer.pauseVideo();

const videoID = location.search.match(ImprovedTube.regex.video_id)[1],
listMatch = location.search.match(ImprovedTube.regex.playlist_id),
popup = window.open(
`${location.protocol}//www.youtube.com/embed/${videoID}?start=${parseInt(ytPlayer.getCurrentTime())}&autoplay=${(ImprovedTube.storage.player_autoplay ?? true) ? '1' : '0'}${listMatch?`&list=${listMatch[1]}`:''}`,
'_blank',
`directories=no,toolbar=no,location=no,menubar=no,status=no,titlebar=no,scrollbars=no,resizable=no,width=${ytPlayer.offsetWidth},height=${ytPlayer.offsetHeight}`
);

if(popup && listMatch){
//! If the video is not in the playlist or not within the first 200 entries, then it automatically selects the first video in the list.
popup.addEventListener('load', function () {
//~ check if the video ID in the title link matches the original video ID in the URL and if not remove the playlist from the URL (reloads the page).
const videoLink = popup.document.querySelector('div#player div.ytp-title-text>a[href]');
if (videoLink && videoLink.href.match(ImprovedTube.regex.video_id)[1] !== videoID) popup.location.search = popup.location.search.replace(/(\?)list=[^&]+&|&list=[^&]+/, '$1');
}, {passive: true, once: true});
}
},
title: 'Popup'
});
Expand Down

0 comments on commit 3c82806

Please sign in to comment.