3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-05 02:19:26 +01:00
dbot/public/ytembed.js

23 lines
957 B
JavaScript
Raw Normal View History

// let's fetch us some goddamn API
var apiEmbed = document.createElement('script');
apiEmbed.src = 'http://www.youtube.com/player_api';
document.getElementsByTagName('script')[0].parentNode.insertBefore(apiEmbed, document.getElementsByTagName('script')[0]);
// this will be called by the player API when it's finished downloading
function onYouTubePlayerAPIReady() {
var youTubePlaceholders = document.getElementsByClassName('ytplaceholder');
for(var i = 0; i < youTubePlaceholders.length; i++) {
var videoURL = youTubePlaceholders[i].innerHTML;
var videoIDMaybe = videoURL.match(/[?&]v=([A-Za-z0-9\-_]+)(?:[?&]|$)/);
youTubePlaceholders[i].innerText = '';
if(videoIDMaybe) {
var ytVideoID = videoIDMaybe[1];
var player = new YT.Player(youTubePlaceholders[i], {
height: '203',
width: '336',
videoId: ytVideoID
});
}
}
}