-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtwitch-channel-status.min.js
1 lines (1 loc) · 3.43 KB
/
twitch-channel-status.min.js
1
!function(){function a(a){if("string"==typeof a&&a)for(var b=0,c=i.length;c>b;b++)if(i[b].src===a)return i[b]}function b(){for(var a,b=0,c=i.length;c>b;b++)if(!i[b].src){if(a)return void 0;a=i[b]}return a}function c(){var a=0;return"undefined"!=typeof e&&e&&"number"==typeof e.skipStackDepth&&(a=e.skipStackDepth),a}function d(a,b){var e,f,g,h="number"==typeof b;return b=h?b:c(),"string"==typeof a&&a&&(h?f=a.match(/((?:|blob:)(?:http[s]?|file):\/\/[\/]?.+?\/[^:\)]*?)(?::\d+)(?::\d+)?/):(f=a.match(/^(?:|[^:@]*@|.+\)@(?=blob|http[s]?|file)|.+?\s+(?: at |@)(?:[^:\(]+ )*[\(]?)((?:|blob:)(?:http[s]?|file):\/\/[\/]?.+?\/[^:\)]*?)(?::\d+)(?::\d+)?/),f&&f[1]||(f=a.match(/\)@((?:|blob:)(?:http[s]?|file):\/\/[\/]?.+?\/[^:\)]*?)(?::\d+)(?::\d+)?/),f&&f[1]&&(e=f[1]))),f&&f[1]&&(b>0?(g=a.slice(a.indexOf(f[0])+f[0].length),e=d(g,b-1)):e=f[1])),e}function e(){if(0!==i.length){if(1===i.length)return i[0];if("readyState"in i[0])for(var c=i.length;c--;)if("interactive"===i[c].readyState)return i[c];if("loading"===document.readyState)return i[i.length-1];var e,j=new Error;if(f&&(e=j.stack),!e&&g)try{throw j}catch(k){e=k.stack}if(e){var l=d(e),m=a(l);return m||l!==h||(m=b()),m}}}var f=!1,g=!1;!function(){try{var a=new Error;throw f="string"==typeof a.stack&&!!a.stack,a}catch(b){g="string"==typeof b.stack&&!!b.stack}}();var h=window.location.href,i=document.getElementsByTagName("script");e.skipStackDepth=1;var j=!("currentScript"in document),k=document.__defineGetter__,l="function"==typeof Object.defineProperty&&function(){var a;try{Object.defineProperty(document,"_xyz",{value:"blah",enumerable:!0,writable:!1,configurable:!1}),a="blah"===document._xyz,delete document._xyz}catch(b){a=!1}return a}();document._currentScript=e,j&&(l?Object.defineProperty(document,"currentScript",{get:e,enumerable:!0,configurable:!1}):k&&document.__defineGetter__("currentScript",e))}(),function(a,b){var c=b.attr("data-attribute")||"data-twitch-channel",d=parseInt(b.attr("data-interval"))||!1,e=b.attr("data-online-image")||'data:image/svg+xml,<?xml version="1.0"?><svg height="20px" viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg"><circle cx="10" cy="10" r="8" fill="green"/></svg>',f=b.attr("data-offline-image")||'data:image/svg+xml,<?xml version="1.0"?><svg height="20px" viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg"><circle cx="10" cy="10" r="8" fill="red"/></svg>',g=30;a.refreshTwitchChannelStatuses=function(){var b={};return $("img["+c+"]").each(function(){var a=$(this),d=a.attr(c).toLowerCase();b[d]=b[d]||[],b[d].push(a),a.attr("src")||a.attr("src",a.attr("data-offline-image")||f)}),Object.keys(b).length?($.ajax({url:"https://api.twitch.tv/kraken/streams",data:{channel:Object.keys(b).join(","),limit:Object.keys(b).length},cache:!1,dataType:"jsonp"}).done(function(c){c.streams.length<c._total&&console.warn("refreshTwitchChannelStatuses couldn't load all online channels! Please reduce the number of channels you are trying to check.");for(var h={},i=0;i<c.streams.length;i++)h[c.streams[i].channel.name]=!0;for(var j in b)if(b.hasOwnProperty(j))for(var k=h[j],l=k?e:f,m=b[j],i=0;i<m.length;i++){var n=m[i],o=n.attr("data-"+(k?"online":"offline")+"-image")||l;n.attr("src",o)}d&&setTimeout(a.refreshTwitchChannelStatuses,1e3*Math.max(d,g))}).fail(function(){setTimeout(a.refreshTwitchChannelStatuses,5e3)}),void 0):(d&&setTimeout(a.refreshTwitchChannelStatuses,1e3*Math.max(d,g)),void 0)},$(a.refreshTwitchChannelStatuses)}(document,$(document.currentScript));