Skip to content

Instantly share code, notes, and snippets.

@swinton
Created April 15, 2014 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swinton/10742813 to your computer and use it in GitHub Desktop.
Save swinton/10742813 to your computer and use it in GitHub Desktop.
javascript: (function(){window.docCookies={getItem:function(a){return decodeURIComponent(document.cookie.replace(RegExp("(?:(?:^|.*;)\\s*"+encodeURIComponent(a).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*([^;]*).*$)|^.*$"),"$1"))||null},setItem:function(a,b,c,e,f,g){if(!a||/^(?:expires|max\-age|path|domain|secure)$/i.test(a))return!1;var d="";if(c)switch(c.constructor){case Number:d=Infinity===c?"; expires=Fri, 31 Dec 9999 23:59:59 GMT":"; max-age="+c;break;case String:d="; expires="+c;break;case Date:d="; expires="+c.toUTCString()}document.cookie=encodeURIComponent(a)+"="+encodeURIComponent(b)+d+(f?"; domain="+f:"")+(e?"; path="+e:"")+(g?"; secure":"");return!0},removeItem:function(a,b,c){if(!a||!this.hasItem(a))return!1;document.cookie=encodeURIComponent(a)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT"+(c?"; domain="+c:"")+(b?"; path="+b:"");return!0},hasItem:function(a){return RegExp("(?:^|;\\s*)"+encodeURIComponent(a).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(document.cookie)},keys:function(){for(var a=document.cookie.replace(/((?:^|\s*;)[^\=]+)(?=;|$)|^\s*|\s*(?:\=[^;]*)?(?:\1|$)/g,"").split(/\s*(?:\=[^;]*)?;\s*/),b=0;b<a.length;b++)a[b]=decodeURIComponent(a[b]);return a}};})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment