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