(function () { "use strict"; version.extensions['youtubeAudioMacros'] = { major: 2, minor: 0, revision: 0 }; var ytplayers = {}, videocount = 0, s = document.createElement("script"); s.src = "http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject_src.js"; s.onreadystatechange = s.onload = function () { var re = new RegExp('(?:playbgm|loopbgm) ([^"&?/ ]{11})', "gi"), div = document.getElementById("storeArea").firstChild, done = [], d; function newplayer(hash) { var id = "YouTube-" + hash; insertElement(document.body, "div", id); swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=" + id, id, "0", "0", "8", null, {}, { allowScriptAccess: "always", wmode: "transparent", modestbranding: "1", version: "3" }, { id: "ytplayer-" + hash, }); }; while(div) { do { d = re.exec(div.innerHTML); if(d && done.indexOf(d[1]) == -1) { newplayer(d[1]); done.push(d[1]); } } while (d); div = div.nextSibling; }; }; document.head.appendChild(s); window.onYTAudioError = function (e) { alert("There is a problem with the YouTube background music (" + e + ")" + (e == 2 ? ": The video ID (" + hash + ") is probably invalid." : e == 100 ? ": The requested video (" + hash + ") was not found." : e == 101 || e == 150 ? ": Embedding has been disabled for the video (" + hash + ")." : "")); }; window.onYouTubePlayerReady = function (e) { var hash = e.slice(8), yt = (ytplayers[hash] = document.getElementById("ytplayer-" + hash)); yt.style.visiblity="hidden"; yt.addEventListener("onError", "onYTAudioError"); yt.mute(); yt.loadVideoById(hash, 0); yt.LOAD = true; videocount += 1; window["onYTAudioStateChange_" + videocount] = function (newState) { if(newState == 1 && yt.LOAD) { yt.pauseVideo(); yt.unMute(); yt.LOAD = false; } if(newState == 0 && yt.LOOP) { yt.playVideo(); } }; yt.addEventListener("onStateChange", "onYTAudioStateChange_" + videocount); }; ["playbgm","loopbgm","stopbgm","pausebgm","unloopbgm"].forEach(function(e) { macros[e] = { handler: function (e, t, n, r) { var yt; if(n[0]) { yt = ytplayers[n[0]]; if(yt) { switch(t) { case "playbgm": case "loopbgm": yt.LOOP = (t == "loopbgm"); if (n[1]) yt.seekTo(n[1]); yt.playVideo(); break; case "stopbgm": yt.stopVideo(); break; case "pausebgm": yt.stopVideo(); break; case "unloopbgm": yt.LOOP = false; break; } } } } } }); }());