diff --git a/manifest.json b/manifest.json index 1ea6f8b..3741f75 100644 --- a/manifest.json +++ b/manifest.json @@ -30,7 +30,8 @@ ], "js": [ "src/content/deps/amd.ts", - "src/content/user-details.ts" + "src/content/user-details.ts", + "src/content/fun.ts" ] }, { diff --git a/src/content/fun.ts b/src/content/fun.ts new file mode 100644 index 0000000..4eb1d43 --- /dev/null +++ b/src/content/fun.ts @@ -0,0 +1,34 @@ +import roundFeatherFontUrl from "../assets/icon/fonts/roundfeather-regular-1.001.ttf?url"; +import FunPreferences from "$lib/extension/preferences/FunPreferences"; + +const preferences = new FunPreferences(); +const url = (browser ?? chrome).runtime.getURL(roundFeatherFontUrl); +const avaliFontDefinitionStyleTag = document.createElement('style'); + +// language=CSS +avaliFontDefinitionStyleTag.textContent = ` + @font-face { + font-family: Roundfeather; + url('${url}') format('truetype'); + } + + :root { + --font-family-base: Roundfeather, verdana, arial, helvetica, sans-serif !important; + --font-family-monospace: Roundfeather, "Droid Sans Mono", monospace !important; + } + `; + +function refreshAvaliFont(isFontEnabled: boolean) { + if (!isFontEnabled) { + avaliFontDefinitionStyleTag.remove(); + return; + } + + document.head.append(avaliFontDefinitionStyleTag); +} + +preferences.subscribe(settings => { + refreshAvaliFont(settings.useAvaliFont ?? false); +}); + +preferences.useAvaliFont.get().then(refreshAvaliFont); diff --git a/src/lib/extension/preferences/FunPreferences.ts b/src/lib/extension/preferences/FunPreferences.ts new file mode 100644 index 0000000..60c5c4a --- /dev/null +++ b/src/lib/extension/preferences/FunPreferences.ts @@ -0,0 +1,16 @@ +import CacheablePreferences, { PreferenceField, type WithFields } from "$lib/extension/base/CacheablePreferences"; + +interface FunPreferencesFields { + useAvaliFont: boolean; +} + +export default class FunPreferences extends CacheablePreferences implements WithFields { + constructor() { + super('fun'); + } + + readonly useAvaliFont = new PreferenceField(this, { + field: "useAvaliFont", + defaultValue: false, + }); +} diff --git a/src/routes/preferences/+page.svelte b/src/routes/preferences/+page.svelte index 22f44df..70502fb 100644 --- a/src/routes/preferences/+page.svelte +++ b/src/routes/preferences/+page.svelte @@ -11,6 +11,7 @@
Tagging Misc & Tools + Fun
Debug diff --git a/src/routes/preferences/fun/+page.svelte b/src/routes/preferences/fun/+page.svelte new file mode 100644 index 0000000..b64d6b1 --- /dev/null +++ b/src/routes/preferences/fun/+page.svelte @@ -0,0 +1,31 @@ + + + + Back +
+
+ + These features are not to mean be really useful. Just a little bit of fun. + + +
+
+ + + + Display everything in Avali Scratch
+ + This will apply the special font across the whole website, making it unusable unless you can read Avali Scratch + alphabet. Unfortunately, text will flicker on every page load. + +
+
+
diff --git a/src/stores/preferences/fun.ts b/src/stores/preferences/fun.ts new file mode 100644 index 0000000..6002e4c --- /dev/null +++ b/src/stores/preferences/fun.ts @@ -0,0 +1,11 @@ +import FunPreferences from "$lib/extension/preferences/FunPreferences"; +import { PreferenceSync } from "$lib/store-sync"; +import { writable } from "svelte/store"; + +export const useAvaliFont = writable(false); + +const preferences = new FunPreferences(); + +void PreferenceSync.for(preferences) + .connect(preferences.useAvaliFont, useAvaliFont, {updateToStore: Boolean}) + .startSync()