Tangled notifications browser extension
1const BASE_URL = "https://tangled.org";
2
3export const getNotificationsUrl = (): string => `${BASE_URL}/notifications`;
4
5export const getNotificationsUrlPattern = (): string =>
6 `${BASE_URL}/notifications*`;
7
8export const fetchNotificationCount = async (): Promise<number> => {
9 const response = await fetch(`${BASE_URL}/notifications/count`, {
10 credentials: "include",
11 });
12 // FIX: requires backend to return 401 when not logged in (currently returns 200 even if not logged in)
13 if (!response.ok) throw new Error(`HTTP ${response.status}`);
14 const html = await response.text();
15 const match = html.match(/>\s*(\d+\+?)\s*</);
16 return match ? parseInt(match[1], 10) : 0;
17};