PageSourceSearch

https://escaperoad3.io/themes/escaperoad3.io/rs/js/gm-storage.js

js escaperoad3.io collected 2026-10-07 00:10:10 UTC 2,768 bytes, 92 lines download raw bytes

1class GMStorage {
2    constructor(key = 'gm-storage', limit = 18) {
3        this.key = key;
4        this.arrayIdGameStorage = localStorage.getItem(this.key) ? JSON.parse(localStorage.getItem(this.key)) : [];
5        this.limit = limit;
6    }
7
8
9    save = () => {
10        return localStorage.setItem(this.key, JSON.stringify(this.arrayIdGameStorage))
11    }
12
13    get = () => {
14        return localStorage.getItem(this.key) || null;
15    }
16
17    addGame = (id_game) => {
18        if (!this.checkGameExist(id_game)) {
19            this.arrayIdGameStorage.push(id_game)
20            this.arrayIdGameStorage = this.arrayIdGameStorage.slice(-this.limit);
21            this.save();
22        }
23    }
24
25    checkGameExist = (id_game) => {
26        if (this.arrayIdGameStorage.includes(id_game)) return true;
27        return false;
28    }
29
30    checkGameObjectExist = (id_game) => {
31        let favorites = JSON.parse(localStorage.getItem(this.key) || '[]');
32        const index = favorites.findIndex(v => v.id === id_game);
33        return index !== -1
34    }
35
36    removeGame = (id_game) => {
37        if (this.checkGameExist(id_game)) {
38            const index = this.arrayIdGameStorage.findIndex(v => v === id_game);
39            if (index !== -1) {
40                this.arrayIdGameStorage.splice(index, 1);
41                this.save(); // Don't forget to save after removal
42                return true;
43            }
44        }
45        return false;
46    }
47
48    addGameObject = (gameObject) => {
49        let favorites = JSON.parse(localStorage.getItem(this.key) || '[]');
50
51        const exists = favorites.some(game => game.id === gameObject.id);
52        const index = favorites.findIndex(game => game.id === gameObject.id);
53        if (!exists) {
54            favorites.push(gameObject);
55            localStorage.setItem(this.key, JSON.stringify(favorites));
56
57        } else {
58            favorites[index] = {
59                ...favorites[index],
60                ...gameObject
61            };
62            localStorage.setItem(this.key, JSON.stringify(favorites));
63
64        }
65
66        if (typeof loadFavoriteGames === 'function') {
67            loadFavoriteGames();
68        }
69
70        return true;
71    }
72
73    removeGameObject = (gameId) => {
74        let items = JSON.parse(localStorage.getItem(this.key) || '[]');
75
76        const originalLength = items.length;
77        items = items.filter(game => game.id !== gameId);
78
79        localStorage.setItem(this.key, JSON.stringify(items));
80
81        if (typeof loadFavoriteGames === 'function') {
82            loadFavoriteGames();
83        }
84
85        return items.length < originalLength;
86    }
87
88    clear = () => {
89        localStorage.removeItem(this.key)
90    }
91
92}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.