mirror of
https://github.com/koloml/philomena-tagging-assistant.git
synced 2026-06-23 18:22:20 +00:00
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.
This commit is contained in:
@@ -28,7 +28,8 @@
|
||||
"*://*.furbooru.org/*"
|
||||
],
|
||||
"js": [
|
||||
"src/content/deps/amd.ts"
|
||||
"src/content/deps/amd.ts",
|
||||
"src/content/user-details.ts"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
14
src/content/user-details.ts
Normal file
14
src/content/user-details.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { UserDetails } from "$lib/extension/preferences/UserDetails";
|
||||
|
||||
(async () => {
|
||||
const userDetails = new UserDetails();
|
||||
const userDataStore = document.querySelector<HTMLElement>('.js-datastore');
|
||||
|
||||
if (!userDataStore) {
|
||||
return;
|
||||
}
|
||||
|
||||
await userDetails.isAuthorized.set(userDataStore.dataset.userIsSignedIn === 'true');
|
||||
})();
|
||||
|
||||
|
||||
16
src/lib/extension/preferences/UserDetails.ts
Normal file
16
src/lib/extension/preferences/UserDetails.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import CacheablePreferences, { PreferenceField, type WithFields } from "$lib/extension/base/CacheablePreferences";
|
||||
|
||||
export interface UserDetailsFields {
|
||||
isAuthorized: boolean;
|
||||
}
|
||||
|
||||
export class UserDetails extends CacheablePreferences<UserDetailsFields> implements WithFields<UserDetailsFields> {
|
||||
constructor() {
|
||||
super('userDetails');
|
||||
}
|
||||
|
||||
isAuthorized = new PreferenceField(this, {
|
||||
field: 'isAuthorized',
|
||||
defaultValue: false,
|
||||
});
|
||||
}
|
||||
18
src/stores/preferences/user.ts
Normal file
18
src/stores/preferences/user.ts
Normal file
@@ -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<UserDetailsFields | null>(null, set => {
|
||||
userDetails.subscribe(settings => {
|
||||
set({
|
||||
isAuthorized: Boolean(settings.isAuthorized)
|
||||
});
|
||||
});
|
||||
|
||||
userDetails.isAuthorized.get().then(isAuthorized => {
|
||||
set({
|
||||
isAuthorized
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user