(function () { "use strict"; version.extensions['youtubeAudioMacros'] = { major: 2, minor: 1, revision: 0 }; var ytplayers = {}, videocount = 0, ready = false, readyBuffer = {}, s = document.createElement("script"), protocol = location.protocol == "file:" ? "http:" : location.protocol; s.src = protocol + "//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(protocol + "//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)); ready = true; yt.style.visibility="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; while(readyBuffer[hash].length > 0) { readyBuffer[hash].shift()(yt); } } 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, fn; if(n[0]) { yt = ytplayers[n[0]]; switch(t) { case "playbgm": case "loopbgm": fn = function(yt) { yt.LOOP = (t == "loopbgm"); if (n[1]) yt.seekTo(n[1]); yt.playVideo(); }; break; case "stopbgm": fn = function(yt) { yt.stopVideo(); }; break; case "pausebgm": fn = function(yt) { yt.stopVideo(); }; break; case "unloopbgm": fn = function(yt) { yt.LOOP = false; }; break; } if (fn) { if (!yt || yt.LOAD) { readyBuffer[n[0]] = readyBuffer[n[0]] || []; readyBuffer[n[0]].push(fn); } else fn(yt); } } } } }); }());