Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recommitted #1813 (lost in git history) #1834

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 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,28 @@ 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}`);
"use strict";
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 () {
"use strict";
//~ check if the video ID in the link of the video title matches the original video ID in the URL and if not remove the playlist from the URL (reloads the page).
const videoLink = this.document.querySelector('div#player div.ytp-title-text>a[href]');
if (videoLink && videoLink.href.match(ImprovedTube.regex.video_id)[1] !== videoID) this.location.search = this.location.search.replace(/(\?)list=[^&]+&|&list=[^&]+/, '$1');
}, {passive: true, once: true});
}
},
title: 'Popup'
});
Expand Down