Skip to content

Instantly share code, notes, and snippets.

@aldrik
Last active May 21, 2016 02:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aldrik/932e1eb24ea52f0fa5d1 to your computer and use it in GitHub Desktop.
Save aldrik/932e1eb24ea52f0fa5d1 to your computer and use it in GitHub Desktop.
//TODO: switch to https://developers.google.com/youtube/iframe_api_reference
var elevatorMusicLoaded;
if (!elevatorMusicLoaded) {
elevatorMusicLoaded = true;
function elevatorMusic() {
var chat_message = handlers.chat_message;
var songrequest = /\!songrequest ([a-zA-Z0-9_-]{11})/;
var videorequest = /\!videorequest ([a-zA-Z0-9_-]{11})/;
handlers.chat_message = function(payload) {
if (payload.message === "!elevator") {
payload.message = "!songrequest VBlFHuCzPgY"
}
var song_match = songrequest.exec(payload.message);
var video_match = videorequest.exec(payload.message);
var match = (song_match || video_match)
if (match) {
var player = $("#ytplayer")
var chat_bar = $("#chat-bar");
player.attr("src", "https://www.youtube.com/embed/" + match[1] + "?autoplay=1&html5=1&showinfo=0&controls=0&iv_load_policy=3&enablejsapi=1");
player.css({
"display": "block",
"position": "relative",
"height": "auto",
"z-index": 1
});
chat_bar.css({
"z-index": 1
});
chat_bar.children()[0].removeAttribute("style");
if (match[1] === "VBlFHuCzPgY") { // elevator music.
player.css("display", "none");
} else if (video_match) {
player.css({
"position": "fixed",
"top": 0,
"left": 0,
"height": "calc(100% - 141px)",
"z-index": 10000
});
chat_bar.css({
"z-index": 10001
});
chat_bar.children()[0].setAttribute("style", "border-top: 0");
}
} else {
return chat_message.apply(handlers, arguments);
}
};
$(".game_settings").append('<iframe id="ytplayer" type="text/html" style="display: none; width:100%; border: 0" src="https://www.youtube.com/embed/VBlFHuCzPgY?autoplay=1&html5=1&showinfo=0&controls=0&iv_load_policy=3&enablejsapi=1" />');
}
try {
elevatorMusic.call(model);
}
catch (e) {
console.log(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment