X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Futils%2Fcookie.js;fp=client%2Fsrc%2Futils%2Fcookie.js;h=b051844286dc5329e8826de8896e684cebda86cf;hb=c66a829b3770122fe0ff2fb9db8def9635bbc334;hp=0000000000000000000000000000000000000000;hpb=ccd4a2b74aecdd6e52960a9ed42acea3e40c9271;p=vchess.git diff --git a/client/src/utils/cookie.js b/client/src/utils/cookie.js new file mode 100644 index 00000000..b0518442 --- /dev/null +++ b/client/src/utils/cookie.js @@ -0,0 +1,22 @@ +// Source: https://www.quirksmode.org/js/cookies.html +export function setCookie(name, value) +{ + var date = new Date(); + date.setTime(date.getTime()+(183*24*60*60*1000)); //6 months + var expires = "; expires="+date.toGMTString(); + document.cookie = name+"="+value+expires+"; path=/"; +} + +export function getCookie(name, defaut) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for (var i=0;i < ca.length;i++) + { + var c = ca[i]; + while (c.charAt(0)==' ') + c = c.substring(1,c.length); + if (c.indexOf(nameEQ) == 0) + return c.substring(nameEQ.length,c.length); + } + return defaut; //cookie not found +}