mirror of
https://git.sr.ht/~emersion/gamja
synced 2024-11-14 19:25:26 -05:00
37 lines
592 B
JavaScript
37 lines
592 B
JavaScript
const PREFIX = "gamja_";
|
|
|
|
class Item {
|
|
constructor(k) {
|
|
this.k = PREFIX + k;
|
|
}
|
|
|
|
load() {
|
|
let v = localStorage.getItem(this.k);
|
|
if (!v) {
|
|
return null;
|
|
}
|
|
return JSON.parse(v);
|
|
}
|
|
|
|
put(v) {
|
|
if (v) {
|
|
localStorage.setItem(this.k, JSON.stringify(v));
|
|
} else {
|
|
localStorage.removeItem(this.k);
|
|
}
|
|
}
|
|
}
|
|
|
|
export const autoconnect = new Item("autoconnect");
|
|
|
|
const rawReceipts = new Item("receipts");
|
|
|
|
export const receipts = {
|
|
load() {
|
|
let v = rawReceipts.load();
|
|
return new Map(Object.entries(v || {}));
|
|
},
|
|
put(m) {
|
|
rawReceipts.put(Object.fromEntries(m));
|
|
},
|
|
};
|