Skip to content

Instantly share code, notes, and snippets.

@darthdeus
Created November 19, 2012 21:13
Show Gist options
  • Save darthdeus/4113952 to your computer and use it in GitHub Desktop.
Save darthdeus/4113952 to your computer and use it in GitHub Desktop.
var jtv_api=function(){var e={},p=!(!document.all||window.opera),h=function(a,b){for(var d in a)a.hasOwnProperty(d)&&b(d,a[d])},k=function(a,b){for(var d=a.length,c=0;c<d;c++)b(a[c],c)},q=function(a,b){if(a.indexOf)return-1!=a.indexOf(b);for(var d=a.length,c=0;c<d;c++)if(a[c]==b)return!0;return!1},l=function(a,b){var d={};h(a,function(a,g){q(b,a)&&(d[a]=g)});return d},r=function(a){var b=[];h(a,function(a,c){b.push(a+"="+c)});return b.join("&")},n=function(a){var b={};k(a.split("&"),function(a){var a=
a.split("="),c=a[1];b[a[0]]=-1!=c.indexOf('"')?c.split('"')[1]:c});return b},m=function(a,b){var d={};h(a,function(b,a){d[b]=a});h(b,function(b,a){d[b]=a});return d},s=function(){for(var a=[],b=0;20>b;b++)a.push("abcdefghujklmnopqrstuvwxyz".charAt(26*Math.random()));a=a.join("");return document.getElementById(a)?s():a},j=function(a,b,d){a&&a[b]?a[b].apply(a,Array.prototype.slice.call(arguments).slice(2)):window.setTimeout(function(){j(a,b,d)},10)},t=function(a,b){"undefined"!=typeof a&&null!==a?b(a):
window.setTimeout(function(){t.apply(this,arguments)},10)},u=function(a,b){a()?b():window.setTimeout(function(){u(a,b)},10)};e.javascript_callbacks=[];var v=function(a){return function(b,d){return a[b](b,d)}},o=function(a){if(p){var b=[],d=document.getElementsByTagName("*");k(d,function(c){c.getAttribute("name")==a&&b.push(c)});return b}return document.getElementsByName(a)},w=function(a,b,d,c,g){var d=r(d),a="string"==typeof a?document.getElementById(a):a,f=m({allowScriptAccess:"always",allowNetworking:"all",
allowFullscreen:"true"},c),c=null;"id"in g?(c=g.id,delete g.id):c=s();f.flashvars="flashvars"in f?f.flashvars+("&"+d):d;if(p){var e="<object";g.codebase="http://macromedia.com/cabs/swflash.cab#version=6,0,0,0";g.classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";g.type="application/x-shockwave-flash";g.id=c;h(g,function(b,a){e+=" "+b+'="'+a+'"'});e+=" >";f.data=b;f.movie=b;h(f,function(b,a){e+='<param name="'+b+'" value="'+a+'">'});e+="</object>";b=document.createElement("div");a.appendChild(b);b.innerHTML+=
e;return document.getElementById(c)}var i=document.createElement("embed");i.setAttribute("pluginspage","http://www.macromedia.com/go/getflashplayer");i.setAttribute("src",b);i.setAttribute("type","application/x-shockwave-flash");i.setAttribute("name",c);h(f,function(b,a){i.setAttribute(b,a)});h(g,function(b,a){i.setAttribute(b,a)});a.appendChild(i);return i};e.new_player=function(a,b){var d=null,d=b.custom?"http://www-cdn.jtvnw.net/widgets/live_api_player.swf?channel="+b.channel:"http://www-cdn.jtvnw.net/widgets/live_embed_player.swf?channel="+
b.channel;b.clip&&(b.custom=!0);var c=m({start_volume:"26",watermark_position:"top_right",auto_play:"false"},l(b,"channel,start_volume,watermark_position,auto_play,namespace,consumer_key,publisher_guard".split(","))),g=m({height:"295",width:"353",bgcolor:"#000000"},l(b,"width,height,id,class,name,title,bgcolor,style".split(",")));b.custom&&(c.enable_javascript=!0,b.events&&(c.javascript_callback_path="jtv_api.javascript_callbacks["+e.javascript_callbacks.length+"]",e.javascript_callbacks.push(v(b.events))));
var f=w(a,d,c,{},g);b.custom&&("buffer_time"in b&&j(f,"set_buffer_time",b.buffer_time),b.publisher_guard&&j(f,"set_channel_password",b.publisher_guard),b.clip?(t(f,function(){f.play_live=f.play_clip}),b.auto_play&&j(f,"play_clip",b.channel)):b.auto_play&&(b.namespace?j(f,"play_live",b.channel,b.namespace):j(f,"play_live",b.channel)));return f};e.new_broadcaster=function(a,b){var d={javascript_callback_path:"jtv_api.javascript_callbacks["+e.javascript_callbacks.length+"]"};e.javascript_callbacks.push(v(b.events));
return w(a,"http://www-cdn.jtvnw.net/widgets/live_embed_publisher.swf",l(b,["stream_key","consumer_key","namespace"]),d,m({},l(b,"height,width,bgcolor,id,name,title,style".split(","))))};e.new_chat=function(a,b){var d=["channel","hide_chat","default_chat","tweet_suffix","over18"],c=r(l(b,d)),e=document.createElement("iframe");e.setAttribute("src","http://www.justin.tv/chat/embed?"+c);c={width:"320",height:"450"};h(b,function(a){q(d,a)&&delete b[a]});c=m(c,b);h(c,function(a,b){e.setAttribute(a,b)});
("string"==typeof a?document.getElementById(a):a).appendChild(e);return e};(function(a){window.addEventListener?window.addEventListener("DOMContentLoaded",a,!1):document.attchEvent?document.attachEvent("onreadystatechange",function(){"complete"===document.readyState&&(a(),document.detachEvent("onreadystatechange",arguments.callee))}):u(function(){try{return document.documentElement.doScroll("left"),document.documentElement.doScroll&&window==window.top}catch(a){return!1}},a)})(function(){k(o("jtv_api.new_player"),
function(a){var b=n(a.getAttribute("title"));e.new_player(a,b)});k(o("jtv_api.new_chat"),function(a){var b=n(a.getAttribute("title"));e.new_chat(a,b)});k(o("jtv_api.new_broadcaster"),function(a){var b=n(a.getAttribute("title"));e.new_broadcaster(a,b)})});return e}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment