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 hideNotificationBadges: { enabled: false }
10}
11
12export type preferencesSchema = typeof defaultPreferences & {
13 [key: string]: any;
14};
15
16// Sync
17interface PreferencesStorageItem extends WxtStorageItem<typeof defaultPreferences, {}> {
18 /**
19 * 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.
20 */
21 getPreferences: () => Promise<typeof defaultPreferences>;
22}
23
24export const preferences: PreferencesStorageItem = storage.defineItem('sync:preferences', { fallback: defaultPreferences, version: 1 }) as PreferencesStorageItem;
25export const _favoritedPlaces = storage.defineItem('sync:favoritedPlaces', { fallback: ["9656"], version: 1 });
26export const _bestFriends = storage.defineItem('sync:bestFriends', { fallback: ["2782"], version: 1 });
27
28preferences.getPreferences = async function() {
29 const userPreferences = await this.getValue();
30 return { ...defaultPreferences, ...userPreferences };
31};
32
33// Cache
34export const cache = storage.defineItem('local:cache', {
35 fallback: {
36 favoritedPlaces: []
37 },
38 version: 1
39});
40
41// Limits
42export const limits = {
43 favoritedPlaces: 15
44}