3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-11 21:39:37 +01:00
dbot/public/ytembed.js
2012-03-12 22:07:08 +00:00

23 lines
957 B
JavaScript

// 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
});
}
}
}