Localstorage
This commit is contained in:
parent
c1213e40ef
commit
3af231ca38
2 changed files with 57 additions and 0 deletions
|
@ -1,2 +1,5 @@
|
|||
import knownSoftware from "./known_software.mjs";
|
||||
import storageManager from "./storage_manager.mjs";
|
||||
console.log(knownSoftware);
|
||||
|
||||
console.log(storageManager.storage.instances);
|
||||
|
|
54
static/storage_manager.mts
Normal file
54
static/storage_manager.mts
Normal file
|
@ -0,0 +1,54 @@
|
|||
type Instance = {
|
||||
/**
|
||||
* The instance's (nick)name
|
||||
* @example "eepy.moe"
|
||||
* @example "KitsuClub"
|
||||
* @example "My Sharkey Instance"
|
||||
*/
|
||||
name: string,
|
||||
/**
|
||||
* The instance's origin
|
||||
* @example "https://eepy.moe"
|
||||
* @example "https://kitsunes.club"
|
||||
*/
|
||||
origin: string,
|
||||
/**
|
||||
* The kind of software the instance is running
|
||||
* @example "misskey"
|
||||
* @example "sharkey"
|
||||
* @example "akkoma"
|
||||
*/
|
||||
software: string,
|
||||
/**
|
||||
* The instance's icon URL
|
||||
*
|
||||
* Make sure to sanitize this! Could lead to XSS
|
||||
*/
|
||||
iconURL: string,
|
||||
}
|
||||
|
||||
type LocalStorage = {
|
||||
instances: Instance[],
|
||||
}
|
||||
|
||||
export default new class StorageManager {
|
||||
storage: LocalStorage;
|
||||
|
||||
constructor() {
|
||||
this.load();
|
||||
}
|
||||
|
||||
default(): LocalStorage {
|
||||
return {
|
||||
instances: []
|
||||
}
|
||||
}
|
||||
|
||||
load() {
|
||||
this.storage = JSON.parse(window.localStorage.getItem("storage") ?? "null") ?? this.default();
|
||||
}
|
||||
|
||||
save() {
|
||||
window.localStorage.setItem("storage", JSON.stringify(this.storage));
|
||||
}
|
||||
}();
|
Loading…
Add table
Reference in a new issue