Skip to content

Commit e31c170

Browse files
authored
Use faster detections for user profiles (#82)
1 parent 0d3afb9 commit e31c170

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

index.ts

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -494,25 +494,45 @@ collect.set('isProfile', [
494494
'https://github.com/sindresorhus?tab=following',
495495
]);
496496

497-
export const isUserProfile = (): boolean => exists('.user-profile-nav');
497+
export const isUserProfile = (): boolean => isProfile() && !isOrganizationProfile();
498498

499-
export const isUserProfileMainTab = (): boolean => exists('[aria-label="User profile"] > .selected:first-child');
500-
501-
export const isUserProfileRepoTab = (): boolean =>
499+
export const isUserProfileMainTab = (): boolean =>
502500
isUserProfile()
503-
&& new URLSearchParams(location.search).get('tab') === 'repositories';
501+
&& !new URLSearchParams(location.search).has('tab');
504502

505-
export const isUserProfileStarsTab = (): boolean =>
506-
isUserProfile()
507-
&& new URLSearchParams(location.search).get('tab') === 'stars';
503+
// The following can be URL-based because they have a `tab` parameter, unlike the organizations
504+
export const isUserProfileRepoTab = (url: URL | HTMLAnchorElement | Location = location): boolean =>
505+
isProfile(url)
506+
&& new URLSearchParams(url.search).get('tab') === 'repositories';
507+
collect.set('isUserProfileRepoTab', [
508+
'https://github.com/fregante?tab=repositories',
509+
'https://github.com/fregante?tab=repositories&type=source',
510+
'https://github.com/fregante?tab=repositories&q=&type=source&language=css&sort=',
511+
]);
508512

509-
export const isUserProfileFollowersTab = (): boolean =>
510-
isUserProfile()
511-
&& new URLSearchParams(location.search).get('tab') === 'followers';
513+
export const isUserProfileStarsTab = (url: URL | HTMLAnchorElement | Location = location): boolean =>
514+
isProfile(url)
515+
&& new URLSearchParams(url.search).get('tab') === 'stars';
516+
collect.set('isUserProfileStarsTab', [
517+
'https://github.com/fregante?tab=stars',
518+
'https://github.com/fregante?direction=desc&sort=updated&tab=stars',
519+
]);
512520

513-
export const isUserProfileFollowingTab = (): boolean =>
514-
isUserProfile()
515-
&& new URLSearchParams(location.search).get('tab') === 'following';
521+
export const isUserProfileFollowersTab = (url: URL | HTMLAnchorElement | Location = location): boolean =>
522+
isProfile(url)
523+
&& new URLSearchParams(url.search).get('tab') === 'followers';
524+
collect.set('isUserProfileFollowersTab', [
525+
'https://github.com/fregante?tab=followers',
526+
'https://github.com/sindresorhus?tab=followers',
527+
]);
528+
529+
export const isUserProfileFollowingTab = (url: URL | HTMLAnchorElement | Location = location): boolean =>
530+
isProfile(url)
531+
&& new URLSearchParams(url.search).get('tab') === 'following';
532+
collect.set('isUserProfileFollowingTab', [
533+
'https://github.com/fregante?tab=following',
534+
'https://github.com/sindresorhus?tab=following',
535+
]);
516536

517537
export const isSingleTag = (url: URL | HTMLAnchorElement | Location = location): boolean => /^(releases\/tag)/.test(getRepo(url)?.path!);
518538
collect.set('isSingleTag', [

0 commit comments

Comments
 (0)