From fa7fef0f89234b99768b1e269c4b173935a4b2da Mon Sep 17 00:00:00 2001 From: Lucas Estienne Date: Sun, 23 Nov 2025 02:36:49 -0500 Subject: [PATCH 1/5] add isStars, isOwnStars, isStarsList, isOwnStarsList to support new Stars and Star Lists functionality --- .gitignore | 1 + index.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/.gitignore b/.gitignore index 46cb338..a338f91 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ distribution dist .cache .parcel-cache +.vscode/ \ No newline at end of file diff --git a/index.ts b/index.ts index 738b517..8118f52 100644 --- a/index.ts +++ b/index.ts @@ -812,6 +812,34 @@ TEST: addTests('isRepositoryActions', [ 'https://github.com/refined-github/github-url-detection/actions/workflows/esm-lint.yml', ]); +export const isStars = (url: URL | HTMLAnchorElement | Location = location): boolean => { + const patharr = getCleanPathname(url).split('/'), [stars, user, lists, ...extra] = patharr; + return stars === 'stars' + && ([1, 2, 4].includes(patharr.length) + || lists === 'lists' && extra.length !== 0); +}; +TEST: addTests('isStars', [ + 'https://github.com/stars', + 'https://github.com/stars/lstn', + 'https://github.com/stars/lstn/repositories', + 'https://github.com/stars/lstn/lists/test' +]); + +export const isOwnStars = (url: URL | HTMLAnchorElement | Location = location): boolean => + isStars(url) + && [['stars'],['stars', getLoggedInUser()]].some( + (needle => arr => arr.length === needle.length + && arr.every((v, i) => v === needle[i]))(getCleanPathname(url).split('/').slice(0,2)) + ); + +export const isStarsList = (url: URL | HTMLAnchorElement | Location = location): boolean => isStars(url) && getCleanPathname(url).split('/')[2] === 'lists'; +TEST: addTests('isStarsList', [ + 'https://github.com/stars/lstn/lists/test' +]); + +export const isOwnStarsList = (url: URL | HTMLAnchorElement | Location = location): boolean => isOwnStars(url) && getCleanPathname(url).split('/')[2] === 'lists'; + + export const isUserTheOrganizationOwner = (): boolean => isOrganizationProfile() && exists('[aria-label="Organization"] [data-tab-item="org-header-settings-tab"]'); export const canUserAdminRepo = (): boolean => isRepo() && exists('.reponav-item[href$="/settings"], [data-tab-item$="settings-tab"]'); From 956154c2ebafbe0acb17867c842005ed0f31a430 Mon Sep 17 00:00:00 2001 From: Lucas Estienne Date: Sun, 23 Nov 2025 03:00:01 -0500 Subject: [PATCH 2/5] fix logic to detect topics & repositories on the new Stars browser UI --- index.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/index.ts b/index.ts index 8118f52..2a57a28 100644 --- a/index.ts +++ b/index.ts @@ -812,16 +812,18 @@ TEST: addTests('isRepositoryActions', [ 'https://github.com/refined-github/github-url-detection/actions/workflows/esm-lint.yml', ]); -export const isStars = (url: URL | HTMLAnchorElement | Location = location): boolean => { - const patharr = getCleanPathname(url).split('/'), [stars, user, lists, ...extra] = patharr; +const isStars = (url: URL | HTMLAnchorElement | Location = location): boolean => { + const patharr = getCleanPathname(url).split('/'), [stars, user, subpath, ...extra] = patharr; return stars === 'stars' && ([1, 2, 4].includes(patharr.length) - || lists === 'lists' && extra.length !== 0); -}; + || subpath === 'lists' && patharr.length !== 3 + || ['repositories', 'topics'].includes(subpath) && patharr.length == 3); +} TEST: addTests('isStars', [ 'https://github.com/stars', 'https://github.com/stars/lstn', 'https://github.com/stars/lstn/repositories', + 'https://github.com/stars/lstn/topics', 'https://github.com/stars/lstn/lists/test' ]); From 60a85f1262f760d00e678af56e8ac76f9a63f6c5 Mon Sep 17 00:00:00 2001 From: Lucas Estienne Date: Sun, 23 Nov 2025 04:25:17 -0500 Subject: [PATCH 3/5] fixed lints --- index.ts | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/index.ts b/index.ts index 2a57a28..c1d908f 100644 --- a/index.ts +++ b/index.ts @@ -813,35 +813,36 @@ TEST: addTests('isRepositoryActions', [ ]); const isStars = (url: URL | HTMLAnchorElement | Location = location): boolean => { - const patharr = getCleanPathname(url).split('/'), [stars, user, subpath, ...extra] = patharr; - return stars === 'stars' - && ([1, 2, 4].includes(patharr.length) - || subpath === 'lists' && patharr.length !== 3 - || ['repositories', 'topics'].includes(subpath) && patharr.length == 3); -} + const patharr = getCleanPathname(url).split('/'); + const [stars, user, subpath, ...extra] = patharr; + return stars === 'stars' + && ([1, 2, 4].includes(patharr.length) + || (subpath === 'lists' && patharr.length !== 3) + || (['repositories', 'topics'].includes(subpath) && patharr.length === 3)); +}; + TEST: addTests('isStars', [ 'https://github.com/stars', 'https://github.com/stars/lstn', 'https://github.com/stars/lstn/repositories', 'https://github.com/stars/lstn/topics', - 'https://github.com/stars/lstn/lists/test' + 'https://github.com/stars/lstn/lists/test', ]); export const isOwnStars = (url: URL | HTMLAnchorElement | Location = location): boolean => - isStars(url) - && [['stars'],['stars', getLoggedInUser()]].some( - (needle => arr => arr.length === needle.length - && arr.every((v, i) => v === needle[i]))(getCleanPathname(url).split('/').slice(0,2)) - ); + isStars(url) + && [['stars'], ['stars', getLoggedInUser()]].some( + (needle => pathArray => pathArray.length === needle.length + && pathArray.every((v, i) => v === needle[i]))(getCleanPathname(url).split('/').slice(0, 2)), + ); export const isStarsList = (url: URL | HTMLAnchorElement | Location = location): boolean => isStars(url) && getCleanPathname(url).split('/')[2] === 'lists'; TEST: addTests('isStarsList', [ - 'https://github.com/stars/lstn/lists/test' + 'https://github.com/stars/lstn/lists/test', ]); export const isOwnStarsList = (url: URL | HTMLAnchorElement | Location = location): boolean => isOwnStars(url) && getCleanPathname(url).split('/')[2] === 'lists'; - export const isUserTheOrganizationOwner = (): boolean => isOrganizationProfile() && exists('[aria-label="Organization"] [data-tab-item="org-header-settings-tab"]'); export const canUserAdminRepo = (): boolean => isRepo() && exists('.reponav-item[href$="/settings"], [data-tab-item$="settings-tab"]'); From ccbc165021df4367082f0d7c8d1c4d082b2c897f Mon Sep 17 00:00:00 2001 From: Lucas Estienne Date: Sun, 23 Nov 2025 05:06:29 -0500 Subject: [PATCH 4/5] fix compile issues --- index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/index.ts b/index.ts index c1d908f..3f39860 100644 --- a/index.ts +++ b/index.ts @@ -814,11 +814,12 @@ TEST: addTests('isRepositoryActions', [ const isStars = (url: URL | HTMLAnchorElement | Location = location): boolean => { const patharr = getCleanPathname(url).split('/'); - const [stars, user, subpath, ...extra] = patharr; - return stars === 'stars' + const [stars, , subpath, ] = patharr; // only get the elements we're only to check from destructuring to avoid compile error + return Boolean(stars === 'stars' && ([1, 2, 4].includes(patharr.length) || (subpath === 'lists' && patharr.length !== 3) - || (['repositories', 'topics'].includes(subpath) && patharr.length === 3)); + || (subpath && ['repositories', 'topics'].includes(subpath) && patharr.length === 3)) + ); }; TEST: addTests('isStars', [ From cb97270bb3c030957304aa4cf2eaf41f64b3e49a Mon Sep 17 00:00:00 2001 From: Lucas Estienne Date: Sun, 23 Nov 2025 05:17:40 -0500 Subject: [PATCH 5/5] fix npm xo lint I missed --- index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.ts b/index.ts index 3f39860..350ce10 100644 --- a/index.ts +++ b/index.ts @@ -814,11 +814,11 @@ TEST: addTests('isRepositoryActions', [ const isStars = (url: URL | HTMLAnchorElement | Location = location): boolean => { const patharr = getCleanPathname(url).split('/'); - const [stars, , subpath, ] = patharr; // only get the elements we're only to check from destructuring to avoid compile error + const [stars, , subpath] = patharr; // Only get the elements we're only to check from destructuring to avoid compile error return Boolean(stars === 'stars' && ([1, 2, 4].includes(patharr.length) || (subpath === 'lists' && patharr.length !== 3) - || (subpath && ['repositories', 'topics'].includes(subpath) && patharr.length === 3)) + || (subpath && ['repositories', 'topics'].includes(subpath) && patharr.length === 3)), ); };