From cfb4c71f58f5624083bf7c968cb390ba410810ce Mon Sep 17 00:00:00 2001 From: KoloMl Date: Sun, 21 Jun 2026 21:53:50 +0400 Subject: [PATCH] Capture and store last seen user flags from the booru Main use case for these flags is to notify when something they're trying to use will not be usable due to authorization or their role on the site. Specifically, it will be also used later to detect when user is a part of staff and show them staff-specific features. --- manifest.json | 3 ++- src/content/user-details.ts | 14 ++++++++++++++ src/lib/extension/preferences/UserDetails.ts | 16 ++++++++++++++++ src/stores/preferences/user.ts | 18 ++++++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/content/user-details.ts create mode 100644 src/lib/extension/preferences/UserDetails.ts create mode 100644 src/stores/preferences/user.ts diff --git a/manifest.json b/manifest.json index 795647e..ee12cf4 100644 --- a/manifest.json +++ b/manifest.json @@ -28,7 +28,8 @@ "*://*.furbooru.org/*" ], "js": [ - "src/content/deps/amd.ts" + "src/content/deps/amd.ts", + "src/content/user-details.ts" ] }, { diff --git a/src/content/user-details.ts b/src/content/user-details.ts new file mode 100644 index 0000000..6d1cfa1 --- /dev/null +++ b/src/content/user-details.ts @@ -0,0 +1,14 @@ +import { UserDetails } from "$lib/extension/preferences/UserDetails"; + +(async () => { + const userDetails = new UserDetails(); + const userDataStore = document.querySelector('.js-datastore'); + + if (!userDataStore) { + return; + } + + await userDetails.isAuthorized.set(userDataStore.dataset.userIsSignedIn === 'true'); +})(); + + diff --git a/src/lib/extension/preferences/UserDetails.ts b/src/lib/extension/preferences/UserDetails.ts new file mode 100644 index 0000000..f6c760f --- /dev/null +++ b/src/lib/extension/preferences/UserDetails.ts @@ -0,0 +1,16 @@ +import CacheablePreferences, { PreferenceField, type WithFields } from "$lib/extension/base/CacheablePreferences"; + +export interface UserDetailsFields { + isAuthorized: boolean; +} + +export class UserDetails extends CacheablePreferences implements WithFields { + constructor() { + super('userDetails'); + } + + isAuthorized = new PreferenceField(this, { + field: 'isAuthorized', + defaultValue: false, + }); +} diff --git a/src/stores/preferences/user.ts b/src/stores/preferences/user.ts new file mode 100644 index 0000000..2c968e6 --- /dev/null +++ b/src/stores/preferences/user.ts @@ -0,0 +1,18 @@ +import { UserDetails, type UserDetailsFields } from "$lib/extension/preferences/UserDetails"; +import { readable } from "svelte/store"; + +const userDetails = new UserDetails(); + +export const user = readable(null, set => { + userDetails.subscribe(settings => { + set({ + isAuthorized: Boolean(settings.isAuthorized) + }); + }); + + userDetails.isAuthorized.get().then(isAuthorized => { + set({ + isAuthorized + }); + }); +});