Skip to content

Video and Playlist popup buttons #1805

Closed
@MAZ01001

Description

Feature request

[1] Video popup button should include the playlist (add support)

[1] has been merged ( #1806 & #1813 & #1834 )

[1] What

When opening a video within a playlist via the popup button (Player→Butttons→Popup player), it opens the video but not with the playlist.

Video: https://www.youtube.com/watch?v=CBIQNiNBbYs?list=PLTfxJETd3IiArIOQSSYLAsYXui34D1cnW

Video-Popup: https://www.youtube.com/embed/CBIQNiNBbYs?start=25&autoplay=1
Does not include the playlist ID (list).

[1] Implementation

When opening the popup, if the current URL includes a list parameter, add it to the embed URL.

Video: https://www.youtube.com/watch?v=CBIQNiNBbYs?list=PLTfxJETd3IiArIOQSSYLAsYXui34D1cnW

Popup: https://www.youtube.com/embed/CBIQNiNBbYs?start=25&autoplay=1&list=PLTfxJETd3IiArIOQSSYLAsYXui34D1cnW

Something like this:

onclick: function () {
var player = ImprovedTube.elements.player;
player.pauseVideo();
window.open('//www.youtube.com/embed/' + location.href.match(/watch\?v=([A-Za-z0-9\-\_]+)/g)[0].slice(8) + '?start=' + parseInt(player.getCurrentTime()) + '&autoplay=' + (ImprovedTube.storage.player_autoplay == false ? '0' : '1'), '_blank', 'directories=no,toolbar=no,location=no,menubar=no,status=no,titlebar=no,scrollbars=no,resizable=no,width=' + player.offsetWidth + ',height=' + player.offsetHeight);
},

↓ modify as follows ↓

function () {
    var player = ImprovedTube.elements.player;

    player.pauseVideo();

    const urlSearch = new URLSearchParams(location.search),
        urlPopup = new URL(`${location.protocol}//www.youtube.com/embed/${urlSearch.get('v')}`);

    urlPopup.searchParams.set('start', parseInt(player.getCurrentTime()));
    urlPopup.searchParams.set('autoplay', (ImprovedTube.storage.player_autoplay ?? true) ? '1' : '0');
    if (urlSearch.has('list')) urlPopup.searchParams.set('list', urlSearch.get('list'));

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

[2] playlist popup button (new)

[2] has been merged ( #1832 )

[2] What

Add a button to the playlist window (ytd-playlist-panel-renderer) like the playlist reverse button ( #1544 ) or sites like youtube.com/playlist?list=... that opens that playlist embed page.

Playlist: https://www.youtube.com/playlist?list=PLTfxJETd3IiArIOQSSYLAsYXui34D1cnW

Playlist-Popup: https://www.youtube.com/embed/videoseries?list=PLTfxJETd3IiArIOQSSYLAsYXui34D1cnW

[2] Implementation

For the playlist window, the same functionality as in [1] Implementation can be used, but instead of /embed/<video-ID>?list=<playlist-ID> it's /embed/videoseries?list=<playlist-ID>.

I'd say It can be an option like the video popup button (default off) under the playlist menu of the extension, maybe "popup playlist".

This probably goes in js&css/web-accessible/www.youtube.com/playlist.js, but I don't understand enough about the project to know where else to add things.

Workaround

Bookmark can now also be found here: code-charity/bookmarklets-hub/yt_popup_player.md

In the meantime, I made myself (and you reading) a quick workaround (updated to #1813 ).

Navigate to a YouTube video or playlist page, open dev-console (F12), and copy & paste the following.

(()=>{// Open YouTube video or playlist as embed in a popup window (reads `v` and `list` URL parameters and get the time from the first `video.video-stream.html5-main-video` element found)
    "use strict";
    const player=document.body.querySelector("video.video-stream.html5-main-video"),
        video=window.location.search.match(/[?&]v=([^&]+)/)?.[1],
        list=window.location.search.match(/[?&]list=([^&]+)/)?.[1];
    if(!video&&!list)return alert("No video and/or playlist found");
    const popup=player?(()=>{
        "use strict";
        player.pause();
        const{left,top,width,height}=player.getBoundingClientRect();
        return window.open(
            `${window.location.protocol}//www.youtube.com/embed/${video??"videoseries"}?autoplay=1&start=${Math.trunc(player.currentTime)}${video?`&v=${video}`:""}${list?`&list=${list}`:""}`,
            "_blank",
            `menubar=0,status=0,titlebar=0,top=${window.screenTop+top},left=${window.screenLeft+left},width=${Math.max(100,width)},height=${Math.max(100,height)}`
        );
    })():window.open(
        `${window.location.protocol}//www.youtube.com/embed/${video??"videoseries"}?autoplay=1${video?`&v=${video}`:""}${list?`&list=${list}`:""}`,
        "_blank",
        `menubar=0,status=0,titlebar=0,top=${window.screenTop},left=${window.screenLeft},width=${Math.max(100,window.innerWidth)},height=${Math.max(100,window.innerHeight)}`
    );
    if(popup&&video&&list){
        popup.addEventListener("load",()=>{
            "use strict";
            const title=popup.document.querySelector("div#player div.ytp-title-text>a[href]");
            if(title&&title.href.match(/[?&]v=([^&]+)/)?.[1]!==video)popup.location.search=popup.location.search.replace(/(\?)list=[^&]+&|&list=[^&]+/,"$1");
        },{passive:true,once:true});
    }
})();

Or, even better, create a bookmark with any name and use the following as the URL (above JS minified).

javascript:(()=>{"use strict";const t=document.body.querySelector("video.video-stream.html5-main-video"),e=window.location.search.match(/[?&]v=([^&]+)/)?.[1],o=window.location.search.match(/[?&]list=([^&]+)/)?.[1];if(!e&&!o)return alert("No video and/or playlist found");const i=t?(()=>{t.pause();const{left:i,top:n,width:a,height:r}=t.getBoundingClientRect();return window.open(`${window.location.protocol}//www.youtube.com/embed/${e??"videoseries"}?autoplay=1&start=${Math.trunc(t.currentTime)}${e?`&v=${e}`:""}${o?`&list=${o}`:""}`,"_blank",`menubar=0,status=0,titlebar=0,top=${window.screenTop+n},left=${window.screenLeft+i},width=${Math.max(100,a)},height=${Math.max(100,r)}`)})():window.open(`${window.location.protocol}//www.youtube.com/embed/${e??"videoseries"}?autoplay=1${e?`&v=${e}`:""}${o?`&list=${o}`:""}`,"_blank",`menubar=0,status=0,titlebar=0,top=${window.screenTop},left=${window.screenLeft},width=${Math.max(100,window.innerWidth)},height=${Math.max(100,window.innerHeight)}`);i&&e&&o&&i.addEventListener("load",(()=>{const t=i.document.querySelector("div#player div.ytp-title-text>a[href]");t&&t.href.match(/[?&]v=([^&]+)/)?.[1]!==e&&(i.location.search=i.location.search.replace(/(\?)list=[^&]+&|&list=[^&]+/,"$1"))}),{passive:!0,once:!0})})();

Then, you can click on the bookmark to open the video or playlist as a popup.

Metadata

Assignees

No one assigned

    Labels

    Feature requestWish or ideagood first issueA GitHub standard for inviting (new) contributors *Congratulations in advance!*help wantedJust an old github standard we add automatically. (The team can remove it when working on it.)up-for-grabs(a github standard for inviting new contributors) - Welcome! ♥

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions