12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- export class Save {
- constructor() {
- this.prefix = "untitled"
- }
- _get() {
- return JSON.parse(localStorage.getItem(`${this.prefix}-savedata`) || "{}")
- }
- _set(value) {
- localStorage.setItem(`${this.prefix}-savedata`, JSON.stringify(value))
- }
- setKey(key, value) {
- let saveData = this._get()
- saveData[key] = value
- this._set(saveData)
- }
- appendKey(key, value) {
- let saveData = this._get()
- if(!saveData[key]) {
- saveData[key] = []
- }
- saveData[key].push(value)
- this._set(saveData)
- }
- incrementKey(key, value) {
- let saveData = this._get()
- if(!saveData[key]) {
- saveData[key] = 0
- }
- saveData[key]+= value
- this._set(saveData)
- }
- getKey(key) {
- let saveData = this._get()
- return saveData[key]
- }
- delete() {
- localStorage.removeItem(`${this.prefix}-savedata`)
- }
- }
|