schoolbox web extension :)
0
fork

Configure Feed

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

refactor(storage): inline helper functions

willow da34b498 14eb5c24

+97 -102
-86
src/utils/storage/helpers.ts
··· 1 - import { StorageState } from "./state.svelte"; 2 - import * as Types from "./types"; 3 - 4 - export function createPlugin( 5 - id: string, 6 - name: string, 7 - description: string, 8 - fallbackToggle: boolean, 9 - settings?: Record<string, Types.PluginSetting>, 10 - ) { 11 - const plugin: Types.PluginData = { 12 - toggle: new StorageState( 13 - storage.defineItem<Types.ToggleState>(`local:plugin-${id}`, { 14 - fallback: { 15 - toggle: fallbackToggle, 16 - }, 17 - }), 18 - true, 19 - ), 20 - info: { 21 - name, 22 - description, 23 - }, 24 - }; 25 - 26 - if (settings) { 27 - plugin.settings = settings; 28 - } 29 - 30 - return plugin; 31 - } 32 - 33 - export function pluginToggle( 34 - pluginId: Types.PluginId, 35 - settingId: string, 36 - name: string, 37 - description: string, 38 - fallback: boolean, 39 - ): Types.PluginSetting { 40 - return { 41 - type: "toggle", 42 - state: new StorageState( 43 - storage.defineItem<Types.ToggleState>(`local:${pluginId}-${settingId}`, { 44 - fallback: { toggle: fallback }, 45 - }), 46 - ), 47 - info: { name, description }, 48 - }; 49 - } 50 - 51 - export function pluginSlider( 52 - pluginId: Types.PluginId, 53 - settingId: string, 54 - name: string, 55 - description: string, 56 - min: number, 57 - max: number, 58 - fallback: number, 59 - ): Types.PluginSetting { 60 - return { 61 - type: "slider", 62 - state: new StorageState( 63 - storage.defineItem<Types.SliderState>(`local:${pluginId}-${settingId}`, { 64 - fallback: { value: fallback, min, max }, 65 - }), 66 - ), 67 - info: { name, description }, 68 - }; 69 - } 70 - 71 - export function createSnippet(id: string, name: string, description: string, fallbackToggle: boolean) { 72 - return { 73 - toggle: new StorageState( 74 - storage.defineItem<Types.ToggleState>(`local:snippet-${id}`, { 75 - fallback: { 76 - toggle: fallbackToggle, 77 - }, 78 - }), 79 - true, 80 - ), 81 - info: { 82 - name, 83 - description, 84 - }, 85 - }; 86 - }
+79 -15
src/utils/storage/plugins.ts
··· 1 - import { createPlugin, pluginSlider, pluginToggle } from "./helpers"; 1 + import { StorageState } from "./state.svelte"; 2 2 import * as Types from "./types"; 3 3 4 4 export const plugins: Record<Types.PluginId, Types.PluginData> = { ··· 8 8 "Adds a clock and current period info to the subheader.", 9 9 true, 10 10 { 11 - openInNewTab: pluginToggle( 11 + openInNewTab: pluginSetting( 12 + "toggle", 12 13 "subheader", 13 14 "openInNewTab", 14 15 "Open links in new tab", 15 16 "Whether to open the class link in a new tab.", 16 - true, 17 + { toggle: true }, 17 18 ), 18 19 }, 19 20 ), ··· 26 27 ), 27 28 28 29 scrollPeriod: createPlugin("scrollPeriod", "Scroll Period", "Scrolls to the current period on the timetable.", true, { 29 - resetCooldownOnMouseMove: pluginToggle( 30 + resetCooldownOnMouseMove: pluginSetting( 31 + "toggle", 30 32 "scrollPeriod", 31 33 "resetCooldownOnMouseMove", 32 34 "Reset on mouse move", 33 35 "Whether to reset the scrolling cooldown when you move your mouse.", 34 - true, 36 + { toggle: true }, 35 37 ), 36 - cooldownDuration: pluginSlider( 38 + cooldownDuration: pluginSetting( 39 + "slider", 37 40 "scrollPeriod", 38 41 "cooldownDuration", 39 42 "Cooldown duration (s)", 40 43 "How long to wait before scrolling.", 41 - 1, 42 - 60, 43 - 10, 44 + { min: 1, max: 60, value: 10 }, 44 45 ), 45 46 }), 46 47 ··· 52 53 ), 53 54 54 55 modernIcons: createPlugin("modernIcons", "Modern Icons", "Modernise the icons across Schoolbox.", true, { 55 - filled: pluginToggle( 56 + filled: pluginSetting( 57 + "toggle", 56 58 "modernIcons", 57 59 "filled", 58 60 "Filled Icons", 59 61 "Whether the icons should be filled or outlined.", 60 - true, 62 + { toggle: true }, 61 63 ), 62 64 }), 63 65 64 66 tabTitle: createPlugin("tabTitle", "Better Tab Titles", "Improves the tab titles for easier navigation.", true, { 65 - showSubjectPrefix: pluginToggle( 67 + showSubjectPrefix: pluginSetting( 68 + "toggle", 66 69 "tabTitle", 67 70 "showSubjectPrefix", 68 71 "Show subject prefix", 69 72 `e.g. "ENG - VCE English 1 & 2" becomes "VCE English 1 & 2"`, 70 - true, 73 + { toggle: true }, 71 74 ), 72 75 }), 73 76 ··· 77 80 "The logo will switch to existing Schoolbox homepage when available.", 78 81 true, 79 82 { 80 - closeCurrentTab: pluginToggle( 83 + closeCurrentTab: pluginSetting( 84 + "toggle", 81 85 "homepageSwitcher", 82 86 "closeCurrentTab", 83 87 "Close current tab", 84 88 "When switching to another tab, close the current one.", 85 - false, 89 + { toggle: true }, 86 90 ), 87 91 }, 88 92 ), 89 93 }; 94 + 95 + function createPlugin( 96 + id: string, 97 + name: string, 98 + description: string, 99 + fallbackToggle: boolean, 100 + settings?: Record<string, Types.PluginSetting>, 101 + ) { 102 + const plugin: Types.PluginData = { 103 + toggle: new StorageState( 104 + storage.defineItem<Types.ToggleState>(`local:plugin-${id}`, { 105 + fallback: { 106 + toggle: fallbackToggle, 107 + }, 108 + }), 109 + true, 110 + ), 111 + info: { 112 + name, 113 + description, 114 + }, 115 + }; 116 + 117 + if (settings) { 118 + plugin.settings = settings; 119 + } 120 + 121 + return plugin; 122 + } 123 + 124 + export function pluginSetting( 125 + type: "toggle" | "slider", 126 + pluginId: Types.PluginId, 127 + settingId: string, 128 + name: string, 129 + description: string, 130 + fallback: Types.ToggleState | Types.SliderState, 131 + ): Types.PluginSetting { 132 + if (type === "toggle") { 133 + return { 134 + type: "toggle", 135 + state: new StorageState( 136 + storage.defineItem<Types.ToggleState>(`local:${pluginId}-${settingId}`, { 137 + fallback: fallback as Types.ToggleState, 138 + }), 139 + ), 140 + info: { name, description }, 141 + }; 142 + } else { 143 + return { 144 + type: "slider", 145 + state: new StorageState( 146 + storage.defineItem<Types.SliderState>(`local:${pluginId}-${settingId}`, { 147 + fallback: fallback as Types.SliderState, 148 + }), 149 + ), 150 + info: { name, description }, 151 + }; 152 + } 153 + }
+18 -1
src/utils/storage/snippets.ts
··· 1 - import { createSnippet } from "./helpers"; 1 + import { StorageState } from "./state.svelte"; 2 2 import * as Types from "./types"; 3 3 4 4 export const snippets: Record<Types.SnippetId, Types.SnippetData> = { ··· 25 25 false, 26 26 ), 27 27 }; 28 + 29 + function createSnippet(id: string, name: string, description: string, fallbackToggle: boolean) { 30 + return { 31 + toggle: new StorageState( 32 + storage.defineItem<Types.ToggleState>(`local:snippet-${id}`, { 33 + fallback: { 34 + toggle: fallbackToggle, 35 + }, 36 + }), 37 + true, 38 + ), 39 + info: { 40 + name, 41 + description, 42 + }, 43 + }; 44 + }