1
0
src/homepage/js/cookies.js

39 lines
992 B
JavaScript

/* cookies.js; Deven Blake 2021; Public Domain */
window.setCookie = function(name, value){
var d;
d = new Date();
/* seconds, minutes, hours, days, years */
d.setTime(d.getTime() + 1000 * 60 * 60 * 24 * 365);
/* ( == one year in milliseconds) */
document.cookie = name + "=" + value + ";" + d.toUTCString() + ";path=/";
}
window.getCookie = function(name){
var c;
var i;
try{
c = decodeURIComponent(document.cookie);
}catch(URIError){
console.log("Could not decode cookie URIComponent (cookies.js: getCookie: URIError)");
return '';
}
c = c.split(';');
for(i = 0; i < c.length; ++i){
while(c[i].charAt(0) == ' ')
c[i] = c[i].slice(1);
/* check if the first bit + '=' matches name + '=' */
/* the added '=' is so 'a' doesn't match 'ab=' */
if(c[i].slice(0, name.length + 1) == name + '=')
/* return the associated value */
return c[i].slice(name.length + 1, c[i].length);
}
return '';
}