diff options
Diffstat (limited to 'source/features/user-profile-follower-badge.tsx')
-rw-r--r-- | source/features/user-profile-follower-badge.tsx | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/source/features/user-profile-follower-badge.tsx b/source/features/user-profile-follower-badge.tsx index ee3ae41e..8c6ea519 100644 --- a/source/features/user-profile-follower-badge.tsx +++ b/source/features/user-profile-follower-badge.tsx @@ -1,5 +1,5 @@ import React from 'dom-chef'; -import cache from 'webext-storage-cache'; +import {CachedFunction} from 'webext-storage-cache'; import elementReady from 'element-ready'; import * as pageDetect from 'github-url-detection'; @@ -8,17 +8,18 @@ import api from '../github-helpers/api.js'; import {getUsername, getCleanPathname} from '../github-helpers/index.js'; import attachElement from '../helpers/attach-element.js'; -const doesUserFollow = cache.function('user-follows', async (userA: string, userB: string): Promise<boolean> => { - const {httpStatus} = await api.v3(`/users/${userA}/following/${userB}`, { - json: false, - ignoreHTTPStatus: true, - }); +const doesUserFollow = new CachedFunction('user-follows', { + async updater(userA: string, userB: string): Promise<boolean> { + const {httpStatus} = await api.v3(`/users/${userA}/following/${userB}`, { + json: false, + ignoreHTTPStatus: true, + }); - return httpStatus === 204; -}); + return httpStatus === 204; + }}); async function init(): Promise<void> { - if (!await doesUserFollow(getCleanPathname(), getUsername()!)) { + if (!await doesUserFollow.get(getCleanPathname(), getUsername()!)) { return; } @@ -40,3 +41,14 @@ void features.add(import.meta.url, { ], init, }); + +/* + +Test URLs: + +1. Visit your own profile +2. Click on "X followers" below your profile picture +3. Click on a follower +4. Look for a "Follows you" badge below their profile picture + +*/ |