schoolbox web extension :)
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: update plugin and snippet usage

willow e589266b 4ea7562d

+43 -47
+24 -28
src/entrypoints/popup/routes/Plugins.svelte
··· 32 32 update={(toggled: boolean) => { 33 33 plugin.toggle.set({ toggle: toggled }); 34 34 }} 35 - text={plugin.info.name} 36 - description={plugin.info.description} 35 + text={plugin.name} 36 + description={plugin.description} 37 37 size="small"> 38 38 {#if plugin.settings !== undefined} 39 39 <Button 40 - title={plugin.info.name + " Settings"} 40 + title={plugin.name + " Settings"} 41 41 {id} 42 42 onclick={() => { 43 43 selectedPluginId = id as PluginId; ··· 53 53 {#if selectedPlugin} 54 54 <Modal bind:showModal> 55 55 {#snippet header()} 56 - <h2 class="mb-4 text-xl">{selectedPlugin.info.name}</h2> 56 + <h2 class="mb-4 text-xl">{selectedPlugin.name}</h2> 57 57 {/snippet} 58 - <!-- toggles --> 59 - {#if selectedPlugin.settings?.toggle !== undefined} 60 - {#each Object.entries(selectedPlugin.settings.toggle) as [id, setting] (id)} 61 - <Toggle 62 - text={setting.info.name} 63 - description={setting.info.description} 64 - size="small" 65 - checked={setting.toggle.state.toggle} 66 - update={async (toggled) => { 67 - setting.toggle.set({ toggle: toggled }); 68 - }} 69 - {id} /> 70 - {/each} 71 - {/if} 72 - 73 - <!-- sliders --> 74 - {#if selectedPlugin.settings?.slider !== undefined} 75 - {#each Object.entries(selectedPlugin.settings.slider) as [id, setting] (id)} 76 - <Slider 77 - {id} 78 - update={async (newValue) => { 79 - setting.slider.set({ value: newValue }); 80 - }} 81 - {...setting.slider.state} /> 58 + {#if selectedPlugin.settings !== undefined} 59 + {#each Object.entries(selectedPlugin.settings) as [id, setting] (id)} 60 + {#if setting.type === "toggle"} 61 + <Toggle 62 + text={setting.name} 63 + description={setting.description} 64 + size="small" 65 + checked={setting.state.state.toggle} 66 + update={async (toggled) => { 67 + setting.state.set({ toggle: toggled }); 68 + }} 69 + {id} /> 70 + {:else if setting.type === "slider"} 71 + <Slider 72 + {id} 73 + update={async (newValue) => { 74 + setting.state.set({ value: newValue }); 75 + }} 76 + {...setting.state.state} /> 77 + {/if} 82 78 {/each} 83 79 {/if} 84 80 </Modal>
+2 -2
src/entrypoints/popup/routes/Snippets.svelte
··· 50 50 update={(toggled: boolean) => { 51 51 snippet.toggle.set({ toggle: toggled }); 52 52 }} 53 - text={snippet.info.name} 54 - description={snippet.info.description} 53 + text={snippet.name} 54 + description={snippet.description} 55 55 size="small" /> 56 56 </div> 57 57 {/each}
-2
src/utils/index.ts
··· 1 - export * from "./storage"; 2 - 3 1 import { flavorEntries } from "@catppuccin/palette"; 4 2 5 3 export function injectStyles(styleText: string) {
+4 -4
src/utils/plugin.ts
··· 5 5 ) { 6 6 const plugin = await plugins[pluginId].toggle.storage.getValue(); 7 7 8 - logger.info(`${plugins[pluginId].info.name}: ${plugin.toggle ? "enabled" : "disabled"}`); 8 + logger.info(`${plugins[pluginId].name}: ${plugin.toggle ? "enabled" : "disabled"}`); 9 9 10 10 const settings = await globalSettings.storage.getValue(); 11 11 const urls = (await schoolboxUrls.storage.getValue()).urls; ··· 19 19 const allElementsPresent = elementsToWaitFor.every((selector) => document.querySelector(selector) !== null); 20 20 if (allElementsPresent) { 21 21 observer.disconnect(); 22 - logger.info(`all elements present, injecting plugin: ${plugins[pluginId].info.name}`); 22 + logger.info(`all elements present, injecting plugin: ${plugins[pluginId].name}`); 23 23 injectLogic(pluginId, plugins[pluginId], plugins[pluginId]?.settings); 24 24 } 25 25 }); ··· 30 30 const allElementsPresent = elementsToWaitFor.every((selector) => document.querySelector(selector) !== null); 31 31 if (allElementsPresent) { 32 32 observer.disconnect(); 33 - logger.info(`all elements already present, injecting plugin: ${plugins[pluginId].info.name}`); 33 + logger.info(`all elements already present, injecting plugin: ${plugins[pluginId].name}`); 34 34 injectLogic(pluginId, plugins[pluginId]); 35 35 } 36 36 } else { 37 37 // no elements to wait for 38 - logger.info(`injecting plugin: ${plugins[pluginId].info.name}`); 38 + logger.info(`injecting plugin: ${plugins[pluginId].name}`); 39 39 injectLogic(pluginId, plugins[pluginId]); 40 40 } 41 41 };
+6 -4
src/utils/storage/plugins.ts
··· 87 87 88 88 export const plugins = buildPluginsFromConfig(pluginConfig); 89 89 90 - function buildPluginsFromConfig(config: Record<PluginId, Types.PluginConfig>): Record<Types.PluginId, Types.Plugin> { 91 - const plugins: Partial<Record<Types.PluginId, Types.Plugin>> = {}; 90 + function buildPluginsFromConfig( 91 + config: Record<Types.PluginId, Types.PluginConfig>, 92 + ): Record<Types.PluginId, Types.PluginData> { 93 + const plugins: Partial<Record<Types.PluginId, Types.PluginData>> = {}; 92 94 93 95 for (const [pluginId, pluginConfig] of Object.entries(config)) { 94 - const plugin: Types.Plugin = { 96 + const plugin: Types.PluginData = { 95 97 name: pluginConfig.name, 96 98 description: pluginConfig.description, 97 99 toggle: new StorageState( ··· 134 136 plugins[pluginId as Types.PluginId] = plugin; 135 137 } 136 138 137 - return plugins as Record<Types.PluginId, Types.Plugin>; 139 + return plugins as Record<Types.PluginId, Types.PluginData>; 138 140 }
+5 -5
src/utils/storage/snippets.ts
··· 30 30 export const snippets = buildSnippetsFromConfig(snippetConfig); 31 31 32 32 function buildSnippetsFromConfig( 33 - config: Record<SnippetId, Types.SnippetConfig>, 34 - ): Record<Types.SnippetId, Types.Snippet> { 35 - const snippets: Partial<Record<Types.SnippetId, Types.Snippet>> = {}; 33 + config: Record<Types.SnippetId, Types.SnippetConfig>, 34 + ): Record<Types.SnippetId, Types.SnippetData> { 35 + const snippets: Partial<Record<Types.SnippetId, Types.SnippetData>> = {}; 36 36 37 37 for (const [snippetId, snippetConfig] of Object.entries(config)) { 38 - const snippet: Types.Snippet = { 38 + const snippet: Types.SnippetData = { 39 39 name: snippetConfig.name, 40 40 description: snippetConfig.description, 41 41 toggle: new StorageState( ··· 49 49 snippets[snippetId as Types.SnippetId] = snippet; 50 50 } 51 51 52 - return snippets as Record<Types.SnippetId, Types.Snippet>; 52 + return snippets as Record<Types.SnippetId, Types.SnippetData>; 53 53 }
+2 -2
src/utils/storage/types.ts
··· 69 69 max: number; 70 70 }; 71 71 72 - export type Plugin = { 72 + export type PluginData = { 73 73 toggle: StorageState<Toggle>; 74 74 settings?: Record<string, PluginSetting>; 75 75 } & ItemInfo; ··· 102 102 // Snippets 103 103 export type SnippetId = "roundedCorners" | "hidePfp" | "hidePwaPrompt" | "censor"; 104 104 105 - export type Snippet = { 105 + export type SnippetData = { 106 106 toggle: StorageState<Toggle>; 107 107 } & ItemInfo; 108 108
src/utils/storage/utils.ts

This is a binary file and will not be displayed.