|
|
|
@ -1,16 +1,30 @@
|
|
|
|
|
import fixLocalStorage from '../../util/discord/fixLocalStorage';
|
|
|
|
|
|
|
|
|
|
let storageCache = {};
|
|
|
|
|
|
|
|
|
|
export const type = 'Extension';
|
|
|
|
|
|
|
|
|
|
document.addEventListener('gmes_get_return', ({ detail }) => {
|
|
|
|
|
storageCache = detail;
|
|
|
|
|
}, { once: true });
|
|
|
|
|
export const init = () => {
|
|
|
|
|
if (!window.localStorage) fixLocalStorage();
|
|
|
|
|
|
|
|
|
|
document.addEventListener('gmes_get_return', ({ detail }) => {
|
|
|
|
|
storageCache = detail;
|
|
|
|
|
}, { once: true });
|
|
|
|
|
|
|
|
|
|
document.dispatchEvent(new CustomEvent('gmes_get'));
|
|
|
|
|
|
|
|
|
|
backup();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
document.dispatchEvent(new CustomEvent('gmes_get'));
|
|
|
|
|
export const backup = () => {
|
|
|
|
|
for (const k of keys()) localStorage.setItem(k, get(k));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const set = (key, value) => {
|
|
|
|
|
storageCache[key] = value;
|
|
|
|
|
document.dispatchEvent(new CustomEvent('gmes_set', { detail: { key, value } }));
|
|
|
|
|
|
|
|
|
|
backup();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const get = (key) => storageCache[key] || null;
|
|
|
|
@ -18,6 +32,8 @@ export const get = (key) => storageCache[key] || null;
|
|
|
|
|
export const remove = (key) => {
|
|
|
|
|
delete storageCache[key];
|
|
|
|
|
document.dispatchEvent(new CustomEvent('gmes_remove', { detail: { key } }));
|
|
|
|
|
|
|
|
|
|
backup();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const keys = () => Object.keys(storageCache);
|