Created
October 1, 2019 07:39
-
-
Save Punk-UnDeaD/cde42d2f8c24790c21fdc4bed1bc0457 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
((document, window) => { | |
window.App = window.App || {}; | |
let tag = null; | |
let YT = null; | |
const html = document.querySelector('html'); | |
App.YT = function (callback) { | |
if (!tag) { | |
tag = document.createElement('script'); | |
tag.src = "https://www.youtube.com/iframe_api"; | |
document.querySelector('head').append(tag); | |
window.YTConfig = {}; | |
window.YT = {}; | |
window.onYouTubeIframeAPIReady = () => { | |
YT = window.YT; | |
html.dispatchEvent(new CustomEvent('YouTubeIframeAPIReady')); | |
delete window.YT; | |
delete window.YTConfig; | |
delete window.onYouTubeIframeAPIReady; | |
} | |
} | |
if (YT) { | |
callback(YT); | |
} | |
else { | |
html.addEventListener('YouTubeIframeAPIReady', e => callback(YT)); | |
} | |
}; | |
})(document, window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment