Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude special search URLs from isRepoRoot and isRepoHome #178

26 changes: 21 additions & 5 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,8 @@ addTests('isRepoIssueList', [
'https://github.com/sindresorhus/refined-github/labels/%3Adollar%3A%20Funded%20on%20Issuehunt',
]);

export const isRepoHome = (url: URL | HTMLAnchorElement | Location = location): boolean => getRepo(url)?.path === '';
export const isRepoHome = (url: URL | HTMLAnchorElement | Location = location): boolean => getRepo(url)?.path === ''
&& !isRepoTreeFileFinder(url);
kang8 marked this conversation as resolved.
Show resolved Hide resolved
addTests('isRepoHome', [
// Some tests are here only as "gotchas" for other tests that may misidentify their pages
'https://github.com/sindresorhus/refined-github',
Expand All @@ -425,6 +426,10 @@ export const isRepoRoot = (url?: URL | HTMLAnchorElement | Location): boolean =>
return false;
}

if (isRepoTreeFileFinder(url ?? location)) {
return false;
}

if (!repository.path) {
// Absolute repo root: `isRepoHome`
return true;
Expand Down Expand Up @@ -479,12 +484,23 @@ addTests('isUserSettings', [
'isRepliesSettings',
]);

export const isRepoTree = (url: URL | HTMLAnchorElement | Location = location): boolean => isRepoRoot(url) || Boolean(getRepo(url)?.path.startsWith('tree/'));
export const isRepoTree = (url: URL | HTMLAnchorElement | Location = location): boolean => isRepoRoot(url)
|| Boolean(getRepo(url)?.path.startsWith('tree/'))
|| isRepoTreeFileFinder(url);
kang8 marked this conversation as resolved.
Show resolved Hide resolved
addTests('isRepoTree', [
'isRepoRoot',
'https://github.com/sindresorhus/refined-github/tree/master/distribution',
'https://github.com/sindresorhus/refined-github/tree/0.13.0/distribution',
'https://github.com/sindresorhus/refined-github/tree/57bf435ee12d14b482df0bbd88013a2814c7512e/distribution',
'isRepoTreeFileFinder',
'https://github.com/sindresorhus/refined-github/tree/main/source',
'https://github.com/sindresorhus/refined-github/tree/0.13.0/extension',
'https://github.com/sindresorhus/refined-github/tree/57bf435ee12d14b482df0bbd88013a2814c7512e/extension',
]);

export const isRepoTreeFileFinder = (url: URL | HTMLAnchorElement | Location = location): boolean => new URLSearchParams(url.search).get('search') === '1';
addTests('isRepoTreeFileFinder', [
'https://github.com/sindresorhus/refined-github?search=1',
'https://github.com/sindresorhus/refined-github/tree/main/source?search=1',
'https://github.com/sindresorhus/refined-github/tree/0.13.0/extension?search=1',
'https://github.com/sindresorhus/refined-github/tree/57bf435ee12d14b482df0bbd88013a2814c7512e/extension?search=1',
]);

export const isRepoWiki = (url: URL | HTMLAnchorElement | Location = location): boolean => Boolean(getRepo(url)?.path.startsWith('wiki'));
Expand Down