Note for now much of the docs is LLM written. This was done to save time and focus on code development. The docs have been LOOSLEY reviewed. However, the code itself has been either fully written by hand or fully reviewed. Therefore, the docs should at the moment be seen as a loose resource rather than authoratiative (and this is on top of the general ability for docs to drift)
59 lines
1.8 KiB
JavaScript
59 lines
1.8 KiB
JavaScript
/*!
|
|
Cookie helper functions
|
|
Copyright (c) 2023 Dimitri van Heesch
|
|
Released under MIT license.
|
|
*/
|
|
let Cookie = {
|
|
cookie_namespace: 'doxygen_',
|
|
|
|
readSetting(cookie,defVal) {
|
|
if (window.chrome) {
|
|
const val = localStorage.getItem(this.cookie_namespace+cookie) ||
|
|
sessionStorage.getItem(this.cookie_namespace+cookie);
|
|
if (val) return val;
|
|
} else {
|
|
let myCookie = this.cookie_namespace+cookie+"=";
|
|
if (document.cookie) {
|
|
const index = document.cookie.indexOf(myCookie);
|
|
if (index != -1) {
|
|
const valStart = index + myCookie.length;
|
|
let valEnd = document.cookie.indexOf(";", valStart);
|
|
if (valEnd == -1) {
|
|
valEnd = document.cookie.length;
|
|
}
|
|
return document.cookie.substring(valStart, valEnd);
|
|
}
|
|
}
|
|
}
|
|
return defVal;
|
|
},
|
|
|
|
writeSetting(cookie,val,days=10*365) { // default days='forever', 0=session cookie, -1=delete
|
|
if (window.chrome) {
|
|
if (days==0) {
|
|
sessionStorage.setItem(this.cookie_namespace+cookie,val);
|
|
} else {
|
|
localStorage.setItem(this.cookie_namespace+cookie,val);
|
|
}
|
|
} else {
|
|
let date = new Date();
|
|
date.setTime(date.getTime()+(days*24*60*60*1000));
|
|
const expiration = days!=0 ? "expires="+date.toGMTString()+";" : "";
|
|
document.cookie = this.cookie_namespace + cookie + "=" +
|
|
val + "; SameSite=Lax;" + expiration + "path=/";
|
|
}
|
|
},
|
|
|
|
eraseSetting(cookie) {
|
|
if (window.chrome) {
|
|
if (localStorage.getItem(this.cookie_namespace+cookie)) {
|
|
localStorage.removeItem(this.cookie_namespace+cookie);
|
|
} else if (sessionStorage.getItem(this.cookie_namespace+cookie)) {
|
|
sessionStorage.removeItem(this.cookie_namespace+cookie);
|
|
}
|
|
} else {
|
|
this.writeSetting(cookie,'',-1);
|
|
}
|
|
},
|
|
}
|