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
at main 1.9 kB view raw
1import { WxtStorageItem } from "wxt/storage"; 2 3export const defaultPreferences = { 4 enabled: [ 5 "favoritedPlaces", 6 "bestFriends", 7 "forumMentions", 8 "improvedFriendLists", 9 "irlBrickPrice", 10 "storeOwnedTags", 11 "tryItems", 12 "outfitCost", 13 "placeRevenue", 14 "accurateOwners", 15 ], 16 config: { 17 irlBrickPrice: { 18 currency: "USD", 19 }, 20 membershipThemes: { 21 themeId: "plus", 22 }, 23 placeManagement: { 24 activityToggle: true, 25 download: true, 26 multipleWhitelist: true, 27 clearWhitelist: true, 28 }, 29 }, 30}; 31 32export type preferencesSchema = typeof defaultPreferences & { 33 [key: string]: any; 34}; 35 36// Sync 37interface PreferencesStorageItem 38 extends WxtStorageItem<typeof defaultPreferences, {}> { 39 /** 40 * 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. 41 */ 42 getPreferences: () => Promise<typeof defaultPreferences>; 43} 44 45export const preferences: PreferencesStorageItem = storage.defineItem( 46 "sync:preferences", 47 { 48 fallback: defaultPreferences, 49 version: 3, 50 migrations: { 51 3: () => defaultPreferences, 52 }, 53 }, 54) as PreferencesStorageItem; 55 56export const _favoritedPlaces = storage.defineItem<string[]>( 57 "sync:favoritedPlaces", 58 { 59 fallback: [], 60 version: 1, 61 }, 62); 63 64export const _bestFriends = storage.defineItem("sync:bestFriends", { 65 fallback: [], 66 version: 1, 67}); 68 69preferences.getPreferences = async function () { 70 const userPreferences = await this.getValue(); 71 return { ...defaultPreferences, ...userPreferences }; 72}; 73 74// Cache 75export const cache = storage.defineItem("local:cache", { 76 fallback: { 77 favoritedPlaces: [], 78 bestFriends: [], 79 inventory: [], 80 userIDs: {}, 81 avatars: {}, 82 items: {}, 83 placeRevenue: {}, 84 ownerCount: {}, 85 }, 86 version: 1, 87});