Started working on implementing official YT iframe-embed API
This commit is contained in:
parent
047c368b70
commit
1344756449
3 changed files with 69 additions and 2 deletions
|
|
@ -21,6 +21,9 @@ class channel{
|
|||
//Define socket listeners
|
||||
this.defineListeners();
|
||||
|
||||
//Flag youtube iframe-embed api as unloaded
|
||||
this.ytEmbedAPILoaded = false;
|
||||
|
||||
//Scrape channel name off URL
|
||||
this.channelName = window.location.pathname.split('/c/')[1].split('/')[0];
|
||||
|
||||
|
|
@ -119,8 +122,9 @@ class channel{
|
|||
//Switch/case by config key
|
||||
switch(key){
|
||||
case 'ytPlayerType':
|
||||
//If the user is running the embedded player
|
||||
if(value == 'embed'){
|
||||
const embedScript = document.querySelector(".yt-embed-api");
|
||||
//If the user is running the embedded player and we don't have en embed script loaded
|
||||
if(value == 'embed' && embedScript == null){
|
||||
//Find our footer
|
||||
const footer = document.querySelector('footer');
|
||||
|
||||
|
|
@ -133,7 +137,21 @@ class channel{
|
|||
|
||||
//Append the script tag to the top of the footer to give everything else access
|
||||
footer.prepend(ytEmbedAPI);
|
||||
//If we're not using the embed player but the script is loaded
|
||||
}else if(embedScript != null){
|
||||
//Pull all scripts since the main one might have pulled others
|
||||
const scripts = document.querySelectorAll('script');
|
||||
|
||||
//Iterate through all script tags on the page
|
||||
for(let script of scripts){
|
||||
//If the script came from youtube
|
||||
if(script.src.match(/youtube\.com|youtu\.be/)){
|
||||
//Rip it out
|
||||
script.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Stop while we're ahead
|
||||
return;
|
||||
}
|
||||
|
|
@ -144,4 +162,19 @@ class channel{
|
|||
]);
|
||||
}
|
||||
|
||||
//Youtube iframe-embed API load handler
|
||||
function onYoutubeIframeAPIReady(){
|
||||
//Set embed api to true
|
||||
client.ytEmbedAPILoaded = true;
|
||||
|
||||
//Get currently playing item
|
||||
const nowPlaying = client.player.mediaHandler.nowPlaying;
|
||||
|
||||
//If we're playing a youtube video and the official embeds are enabled
|
||||
if(nowPlaying.type == 'yt' && localStorage.get('ytPlayerType') == "embed"){
|
||||
//Restart the video now that the embed api has loaded
|
||||
client.player.start({media: nowPlaying});
|
||||
}
|
||||
}
|
||||
|
||||
const client = new channel();
|
||||
Loading…
Add table
Add a link
Reference in a new issue