diff options
Diffstat (limited to 'src/utils-common.ts')
| -rw-r--r-- | src/utils-common.ts | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/utils-common.ts b/src/utils-common.ts index 153bbaa..7bca889 100644 --- a/src/utils-common.ts +++ b/src/utils-common.ts @@ -22,6 +22,20 @@ export function datetimeStringNow() { return DATETIME_FMT.format(new Date()); } +declare global { + var M: { cfg: { userId: number; courseId: number } }; +} + +export function getUserId(): number { + // M is exported by Moodle + return globalThis.M.cfg.userId; +} + +export function getCourseId(): number { + // M is exported by Moodle + return globalThis.M.cfg.courseId; +} + // TODO(muhq): Cache the retrieved URL export async function getUserIconUrl(userId: number): Promise<string> { const userRes = await fetch(`https://lernplattform.bycs.de/user/profile.php?id=${userId}`); |
