-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtv.jquery-min.js
12 lines (11 loc) · 5.07 KB
/
tv.jquery-min.js
1
2
3
4
5
6
7
8
9
10
11
12
/**
* @author Vladimir Reznichenko <kalessil@gmail.com>
* @date 12.05.2012
*
* https://github.com/kalessil/tv.jquery
*
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://www.opensource.org/licenses/mit-license.php
* http://www.opensource.org/licenses/GPL-2.0
*/
(function(h){h.fn.extend({tvready:function(i){h(this).bind("tvready",i)}});var b=false;var d=function(i){if(typeof i!="undefined"){b=i}if(b==="wait"){return}h(document).ready(function(){h(document).trigger("tvready");window.console.log("Device: "+h.tv.type+" #"+h.tv.id)})};var f={unknown:"unknown",loewe:"Loewe",smartbox:"smartBox",videoweb:"VideoWEB",technisat:"TechniSat",philips:"Philips",lge:"LG Electronics"};var a=false;var e=false;var g=document.querySelector("head");var c=function(){var i=function(){d("wait");h(document).ready(function(){if(!document.getElementById("jquery-tv-hwdetect")){var l=document.createElement("div");l.setAttribute("id","jquery-tv-hwdetect");l.setAttribute("style","display:none; position:absolute; left:0px; top:0px; width:0px; height:0px;");var p=document.createElement("object");p.setAttribute("id","oipf-config");p.setAttribute("type","application/oipfConfiguration");l.appendChild(p);var n=document.createElement("object");n.setAttribute("id","lgNetCastDevice");p.setAttribute("type","application/x-netcast-info");l.appendChild(n);document.querySelector("body").appendChild(l);if(h.browser.opera){a=true}if(!a){var k=document.createElement("input");k.setAttribute("id","css3ui-nav-test");k.setAttribute("type","text");k.setAttribute("style","nav-up:#css3ui-nav-test;nav-down:#css3ui-nav-test;");a=(typeof k.style.navDown!="undefined"&&k.style.navDown=="#css3ui-nav-test")}h.tv.hasSpatialNav=a;var o=navigator.cookieEnabled;if(!o&&typeof navigator.cookieEnabled=="undefined"){document.cookie="testcookie";o=(document.cookie.indexOf("testcookie")!=-1)}e=o}var s=function(y){y=y.toLowerCase().split(":");var v="";for(var x=0,w=0;x<y.length;++x){w=parseInt(y[x],16);v+=(w>99?w:(w>9?"0"+w:"00"+w))}return v};var r=function(){if(!e){return f.unknown}var z="__";var w=function(){if(typeof localStorage!="undefined"&&localStorage.getItem("deviceId")!=null){return localStorage.getItem("deviceId")}var E=document.cookie.split("; ");for(var D=0,F;(F=E[D]&&E[D].split("="));D++){if(F.shift()==="deviceId"){if(typeof localStorage!="undefined"){localStorage.setItem("deviceId",F.join("="))}return F.join("=")}}return null};var B=w();if(B!=null){return z+s(B)}var v=[],A="0123456789abcdef";for(var y=0,x="";y<6;y++){x=A.charAt(Math.floor(Math.random()*A.length));x+=A.charAt(Math.floor(Math.random()*A.length));v.push(x)}v=v.join(":");var C=function(E){if(typeof localStorage!="undefined"){localStorage.setItem("deviceId",E);return}var D=new Date();D.setDate(D.getDate()+365*25);document.cookie=["deviceId","=",E,"; expires="+D.toUTCString(),"","",""].join("")};C(v);return z+s(v)};var t=function(v){if(v==f.unknown){return v}switch(h.tv.type){case f.loewe:v="LO"+v;break;case f.smartbox:v="SB"+v;break;case f.videoweb:v="VW"+v;break;case f.technisat:v="TS"+v;break;case f.philips:v="PH"+v;break;case f.lge:v="LG"+v;break;default:v="XX"+v;break}return v};var q=document.getElementById("oipf-config");if(typeof q.localSystem!="undefined"){var m=q.localSystem;if(typeof m.serialNumber!="undefined"){h.tv.id=t(m.serialNumber);return d(true)}if(typeof m.deviceID!="undefined"){h.tv.id=t(m.deviceID);return d(true)}if(typeof m.networkInterfaces!="undefined"){h.tv.id=t(s(m.networkInterfaces.item(0).macAddress));return d(true)}}if(typeof q.configuration!="undefined"){}if(typeof NetRangeDevice=="object"){h.tv.id=t(s(NetRangeDevice.getMACID()));return d(true)}var u=document.getElementById("lgNetCastDevice");if(typeof u.manufacturer!="undefined"){if(typeof n.serialNumber!="undefine"){h.tv.id=t(n.serialNumber);return d(true)}if(typeof n.net_macAddress!="undefine"){h.tv.id=t(s(n.net_macAddress));return d(true)}}h.tv.id=t(r());return d(true)})};var j=function(){var l={Loewe:f.loewe,"smart;":f.smartbox,"videoweb;":f.videoweb,TechniSat:f.technisat,Philips:f.philips,NetTV:f.philips,"LG NetCast":f.lge};var k=navigator.userAgent.toLowerCase();for(var m in l){if(k.indexOf(m.toLowerCase())>=0){return h.tv.type=l[m]}}return f.unknown};j();i();h.tv.isTv=(h.tv.isHbbtv||h.tv.type!=f.unknown||navigator.userAgent.indexOf("CE-HTML")>=0)};h.extend({tv:{isTv:false,isHbbtv:(navigator.userAgent.indexOf("HbbTV")>=0),type:f.unknown,id:f.unknown,hasSpatialNav:false}});c();h.extend({tvinfo:function(){if(b!=true){return"TV plugin is starting (concern using $(document).tvready(callback));"}var i=[];if(h.tv.isTv){i.push("TV/TV box")}if(h.tv.isHbbtv){i.push("HbbTV")}var j=document.getElementById("oipf-config");if(typeof j.localSystem!="undefined"){i.push("OIPF config (HW info)")}if(typeof j.configuration!="undefined"){i.push("OIPF config (basic)")}if(a){i.push("CSS3 UI nav-*")}if(e){i.push("Cookies")}if(typeof localStorage!="undefined"){i.push("localStorage")}if(typeof sessionStorage!="undefined"){i.push("sessionStorage")}if(h.browser.webkit){i.push("WebKit")}if(h.browser.opera){i.push("Opera")}i=(i.length>0?(" ("+i.join(", ")+")"):"");return h.tv.type+i+" #"+h.tv.id}});d()})(jQuery);