Skip to content

Commit fa7fef0

Browse files
committed
add isStars, isOwnStars, isStarsList, isOwnStarsList to support new Stars and Star Lists functionality
1 parent 48af931 commit fa7fef0

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ distribution
1212
dist
1313
.cache
1414
.parcel-cache
15+
.vscode/

index.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,34 @@ TEST: addTests('isRepositoryActions', [
812812
'https://github.com/refined-github/github-url-detection/actions/workflows/esm-lint.yml',
813813
]);
814814

815+
export const isStars = (url: URL | HTMLAnchorElement | Location = location): boolean => {
816+
const patharr = getCleanPathname(url).split('/'), [stars, user, lists, ...extra] = patharr;
817+
return stars === 'stars'
818+
&& ([1, 2, 4].includes(patharr.length)
819+
|| lists === 'lists' && extra.length !== 0);
820+
};
821+
TEST: addTests('isStars', [
822+
'https://github.com/stars',
823+
'https://github.com/stars/lstn',
824+
'https://github.com/stars/lstn/repositories',
825+
'https://github.com/stars/lstn/lists/test'
826+
]);
827+
828+
export const isOwnStars = (url: URL | HTMLAnchorElement | Location = location): boolean =>
829+
isStars(url)
830+
&& [['stars'],['stars', getLoggedInUser()]].some(
831+
(needle => arr => arr.length === needle.length
832+
&& arr.every((v, i) => v === needle[i]))(getCleanPathname(url).split('/').slice(0,2))
833+
);
834+
835+
export const isStarsList = (url: URL | HTMLAnchorElement | Location = location): boolean => isStars(url) && getCleanPathname(url).split('/')[2] === 'lists';
836+
TEST: addTests('isStarsList', [
837+
'https://github.com/stars/lstn/lists/test'
838+
]);
839+
840+
export const isOwnStarsList = (url: URL | HTMLAnchorElement | Location = location): boolean => isOwnStars(url) && getCleanPathname(url).split('/')[2] === 'lists';
841+
842+
815843
export const isUserTheOrganizationOwner = (): boolean => isOrganizationProfile() && exists('[aria-label="Organization"] [data-tab-item="org-header-settings-tab"]');
816844

817845
export const canUserAdminRepo = (): boolean => isRepo() && exists('.reponav-item[href$="/settings"], [data-tab-item$="settings-tab"]');

0 commit comments

Comments
 (0)