Skip to content

Commit 1325ca8

Browse files
authored
Include Repo Search pages in isRepo; add hasRepoHeader (#131)
1 parent b93c1f1 commit 1325ca8

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ export const isRepo = (url: URL | HTMLAnchorElement | Location = location): bool
339339
&& !reservedNames.includes(url.pathname.split('/', 2)[1]!)
340340
&& !isDashboard(url)
341341
&& !isGist(url)
342-
&& !isRepoSearch(url)
343342
&& !isNewRepoTemplate(url);
344343
addTests('isRepo', [
345344
// Some of these are here simply as "gotchas" to other detections
@@ -353,6 +352,9 @@ addTests('isRepo', [
353352
'https://github.com/sindresorhus/refined-github/issues/templates/edit', // Gotcha for isRepoIssueList
354353
]);
355354

355+
export const hasRepoHeader = (url: URL | HTMLAnchorElement | Location = location): boolean => isRepo(url) && !isRepoSearch(url);
356+
addTests('hasRepoHeader', combinedTestOnly);
357+
356358
// On empty repos, there's only isRepoHome; this element is found in `<head>`
357359
export const isEmptyRepoRoot = (): boolean => isRepoHome() && !exists('link[rel="canonical"]');
358360

@@ -443,9 +445,7 @@ addTests('isRepoRoot', [
443445
'https://github.com/sindresorhus/refined-github/tree/master?files=1',
444446
]);
445447

446-
// This can't use `getRepositoryInfo().path` to avoid infinite recursion:
447-
// `getRepositoryInfo` depends on `isRepo` and `isRepo` depends on `isRepoSearch`
448-
export const isRepoSearch = (url: URL | HTMLAnchorElement | Location = location): boolean => url.pathname.split('/')[3] === 'search';
448+
export const isRepoSearch = (url: URL | HTMLAnchorElement | Location = location): boolean => getRepo(url)?.path === 'search';;
449449
addTests('isRepoSearch', [
450450
'https://github.com/sindresorhus/refined-github/search?q=diff',
451451
'https://github.com/sindresorhus/refined-github/search?q=diff&unscoped_q=diff&type=Issues',
@@ -643,7 +643,8 @@ export const hasRichTextEditor = (url: URL | HTMLAnchorElement | Location = loca
643643
|| isDiscussion(url);
644644

645645
addTests('hasCode', combinedTestOnly);
646-
export const hasCode = (url: URL | HTMLAnchorElement | Location = location): boolean => // Static code, not the editor
646+
/** Static code, not the code editor */
647+
export const hasCode = (url: URL | HTMLAnchorElement | Location = location): boolean =>
647648
hasComments(url)
648649
|| isRepoTree(url) // Readme files
649650
|| isRepoSearch(url)
@@ -655,7 +656,8 @@ export const hasCode = (url: URL | HTMLAnchorElement | Location = location): boo
655656
|| isBlame(url);
656657

657658
addTests('hasFiles', combinedTestOnly);
658-
export const hasFiles = (url: URL | HTMLAnchorElement | Location = location): boolean => // Has a list of files
659+
/** Has a list of files */
660+
export const hasFiles = (url: URL | HTMLAnchorElement | Location = location): boolean =>
659661
isCommit(url)
660662
|| isCompare(url)
661663
|| isPRFiles(url);

0 commit comments

Comments
 (0)