Skip to content

Instantly share code, notes, and snippets.

@shripadk
Created December 31, 2010 12:08
Show Gist options
  • Save shripadk/760963 to your computer and use it in GitHub Desktop.
Save shripadk/760963 to your computer and use it in GitHub Desktop.
var f=this;function g(a,c,b){a=a.split(".");b=b||f;!(a[0]in b)&&b.execScript&&b.execScript("var "+a[0]);for(var d;a.length&&(d=a.shift());)if(!a.length&&c!==undefined)b[d]=c;else b=b[d]?b[d]:b[d]={}}var h=Date.now||function(){return+new Date},i,j,k,l;function m(){return f.navigator?f.navigator.userAgent:null}l=k=j=i=false;var n;if(n=m()){var o=f.navigator;i=n.indexOf("Opera")==0;j=!i&&n.indexOf("MSIE")!=-1;k=!i&&n.indexOf("WebKit")!=-1;l=!i&&!k&&o.product=="Gecko"}var p=j,q=l,r=k,s="",t;
if(i&&f.opera){var u=f.opera.version;s=typeof u=="function"?u():u}else{if(q)t=/rv\:([^\);]+)(\)|;)/;else if(p)t=/MSIE\s+([^\);]+)(\)|;)/;else if(r)t=/WebKit\/(\S+)/;if(t){var v=t.exec(m());s=v?v[1]:""}}var w=/\s*;\s*/;
function x(a,c,b,d,e){if(/[;=\s]/.test(a))throw Error('Invalid cookie name "'+a+'"');if(/[;\r\n]/.test(c))throw Error('Invalid cookie value "'+c+'"');b!==undefined||(b=-1);e=e?";domain="+e:"";d=d?";path="+d:"";b=b<0?"":b==0?";expires="+(new Date(1970,1,1)).toUTCString():";expires="+(new Date(h()+b*1E3)).toUTCString();document.cookie=a+"="+c+e+d+b}function z(a,c){a+="=";for(var b=(document.cookie||"").split(w),d=0,e;e=b[d];d++)if(e.indexOf(a)==0)return e.substr(a.length);return c}
function A(a,c,b){var d=z(a)!==undefined;x(a,"",0,c,b);return d}function B(){for(var a=(document.cookie||"").split(w),c=[],b=[],d,e,y=0;e=a[y];y++){d=e.indexOf("=");if(d==-1){c.push("");b.push(e)}else{c.push(e.substring(0,d));b.push(e.substring(d+1))}}return{a:c,b:b}}g("__tc.clear",function(){for(var a=B().a,c=a.length-1;c>=0;c--)A(a[c])},void 0);g("__tc.containsKey",function(a){return z(a)!==undefined},void 0);
g("__tc.containsValue",function(a){a:{for(var c=B().b,b=0;b<c.length;b++)if(c[b]==a){a=true;break a}a=false}return a},void 0);g("__tc.get",function(a,c){return z(a,c)},void 0);g("__tc.getCount",function(){return document.cookie?(document.cookie||"").split(w).length:0},void 0);g("__tc.getKeys",function(){return B().a},void 0);g("__tc.getValues",function(){return B().b},void 0);g("__tc.isEmpty",function(){return!document.cookie},void 0);
g("__tc.isEnabled",function(){var a;if((a=navigator.cookieEnabled)&&r){var c="COOKIES_TEST_"+h();x(c,"1");if(z(c))A(c);else a=false}return a},void 0);g("__tc.remove",function(a,c,b){return A(a,c,b)},void 0);g("__tc.set",function(a,c,b,d,e){return x(a,c,b,d,e)},void 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment