A rewrite of Poly+, my quality-of-life browser extension for Polytoria. Built entirely fresh using the WXT extension framework, Typescript, and with added better overall code quality.
extension
1import { WxtStorageItem } from "wxt/storage";
2
3export const defaultPreferences = {
4 favoritedPlaces: { enabled: true },
5 bestFriends: { enabled: true },
6 forumMentions: { enabled: true },
7 improvedFriendLists: { enabled: true },
8 irlBrickPrice: { enabled: true }
9}
10
11export type preferencesSchema = typeof defaultPreferences & {
12 [key: string]: any;
13};
14
15// Sync
16interface PreferencesStorageItem extends WxtStorageItem<typeof defaultPreferences, {}> {
17 /**
18 * Wrapper for the standard `.getValue()` method that merges the user's saved preferences with the default preferences to make sure there are no unexpected errors.
19 */
20 getPreferences: () => Promise<typeof defaultPreferences>;
21}
22
23export const preferences: PreferencesStorageItem = storage.defineItem('sync:preferences', { fallback: defaultPreferences, version: 1 }) as PreferencesStorageItem;
24export const _favoritedPlaces = storage.defineItem('sync:favoritedPlaces', { fallback: ["9656"], version: 1 });
25export const _bestFriends = storage.defineItem('sync:bestFriends', { fallback: ["2782"], version: 1 });
26
27preferences.getPreferences = async function() {
28 const userPreferences = await this.getValue();
29 return { ...defaultPreferences, ...userPreferences };
30};
31
32// Cache
33export const cache = storage.defineItem('local:cache', {
34 fallback: {
35 favoritedPlaces: []
36 },
37 version: 1
38});
39
40// Limits
41export const limits = {
42 favoritedPlaces: 15
43}