Cleanup boot.js and fix rllayout cookie

This commit is contained in:
the-djmaze 2022-02-08 14:15:22 +01:00
parent 827421e116
commit f3717815e1
3 changed files with 37 additions and 41 deletions

View file

@ -1,13 +1,37 @@
const
CLIENT_SIDE_STORAGE_INDEX_NAME = 'rlcsc',
getStorage = () => {
try {
const value = localStorage.getItem(CLIENT_SIDE_STORAGE_INDEX_NAME);
return value ? JSON.parse(value) : null;
} catch (e) {
return null;
}
};
win = window,
CLIENT_SIDE_STORAGE_INDEX_NAME = 'rlcsc',
sName = 'localStorage',
getStorage = () => {
try {
const value = localStorage.getItem(CLIENT_SIDE_STORAGE_INDEX_NAME);
return value ? JSON.parse(value) : null;
} catch (e) {
return null;
}
};
// Storage
try {
win[sName].setItem(sName, '');
win[sName].getItem(sName);
win[sName].removeItem(sName);
} catch (e) {
console.error(e);
// initialise if there's already data
let data = document.cookie.match(/(^|;) ?localStorage=([^;]+)/);
data = data ? decodeURIComponent(data[2]) : null;
data = data ? JSON.parse(data) : {};
win[sName] = {
getItem: key => data[key] == null ? null : data[key],
setItem: (key, value) => {
data[key] = ''+value; // forces the value to a string
document.cookie = sName+'='+encodeURIComponent(JSON.stringify(data))
+"; expires="+((new Date(Date.now()+(365*24*60*60*1000))).toGMTString())
+"; path=/; samesite=strict";
}
};
}
/**
* @param {number} key