MCPcopy
hub / github.com/monkeytypegame/monkeytype / randomizeTheme

Function randomizeTheme

frontend/src/ts/controllers/theme-controller.ts:193–240  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

191}
192
193export async function randomizeTheme(): Promise<void> {
194 if (themesList.length === 0) {
195 await changeThemeList();
196 if (themesList.length === 0) return;
197 }
198
199 let filter = (_: string): boolean => true;
200 if (Config.randomTheme === "auto") {
201 filter = prefersColorSchemeDark() ? isColorDark : isColorLight;
202 }
203
204 let nextTheme = null;
205 do {
206 randomTheme = themesList[randomThemeIndex] as ThemeIdentifier;
207 nextTheme = themes[themesList[randomThemeIndex] as ThemeName];
208 randomThemeIndex++;
209 if (randomThemeIndex >= themesList.length) {
210 Arrays.shuffle(themesList);
211 randomThemeIndex = 0;
212 }
213 } while (!filter(nextTheme.bg));
214
215 let colorsOverride: CustomThemeColors | undefined;
216
217 if (Config.randomTheme === "custom") {
218 const theme = CustomThemes.__nonReactive.getCustomTheme(
219 randomTheme as string,
220 );
221 colorsOverride = theme?.colors;
222 randomTheme = "custom";
223 }
224
225 setConfig("customTheme", false, {
226 nosave: true,
227 });
228 await apply(randomTheme, colorsOverride);
229
230 if (randomThemeIndex >= themesList.length) {
231 let name = randomTheme.replace(/_/g, " ");
232 if (Config.randomTheme === "custom") {
233 name = (
234 CustomThemes.__nonReactive.getCustomTheme(randomTheme as string)
235 ?.name ?? "custom"
236 ).replace(/_/g, " ");
237 }
238 showNoticeNotification(name);
239 }
240}
241
242async function clearRandom(): Promise<void> {
243 if (randomTheme === null) return;

Callers 1

lists.tsFile · 0.90

Calls 6

setConfigFunction · 0.90
showNoticeNotificationFunction · 0.90
changeThemeListFunction · 0.85
prefersColorSchemeDarkFunction · 0.85
filterFunction · 0.85
applyFunction · 0.70

Tested by

no test coverage detected