@@ -81,6 +81,7 @@ addTests('isDashboard', [
81
81
'https://github.com/?tab=followers' , // Gotcha for `isUserProfileFollowersTab`
82
82
'https://github.com/?tab=following' , // Gotcha for `isUserProfileFollowingTab`
83
83
'https://github.com/?tab=overview' , // Gotcha for `isUserProfileMainTab`
84
+ 'https://github.com?search=1' , // Gotcha for `isRepoTree`
84
85
] ) ;
85
86
86
87
export const isEnterprise = ( url : URL | HTMLAnchorElement | Location = location ) : boolean => url . hostname !== 'github.com' && url . hostname !== 'gist.github.com' ;
@@ -412,7 +413,10 @@ addTests('isRepoIssueList', [
412
413
'https://github.com/sindresorhus/refined-github/labels/%3Adollar%3A%20Funded%20on%20Issuehunt' ,
413
414
] ) ;
414
415
415
- export const isRepoHome = ( url : URL | HTMLAnchorElement | Location = location ) : boolean => getRepo ( url ) ?. path === '' ;
416
+ const hasSearchParameter = ( url : URL | HTMLAnchorElement | Location ) : boolean => new URLSearchParams ( url . search ) . get ( 'search' ) === '1' ;
417
+
418
+ export const isRepoHome = ( url : URL | HTMLAnchorElement | Location = location ) : boolean => getRepo ( url ) ?. path === ''
419
+ && ! hasSearchParameter ( url ) ;
416
420
addTests ( 'isRepoHome' , [
417
421
// Some tests are here only as "gotchas" for other tests that may misidentify their pages
418
422
'https://github.com/sindresorhus/refined-github' ,
@@ -425,7 +429,7 @@ addTests('isRepoHome', [
425
429
'https://github.com/sindresorhus/refined-github?files=1' ,
426
430
] ) ;
427
431
428
- export const isRepoRoot = ( url ?: URL | HTMLAnchorElement | Location ) : boolean => {
432
+ const _isRepoRoot = ( url ?: URL | HTMLAnchorElement | Location ) : boolean => {
429
433
const repository = getRepo ( url ?? location ) ;
430
434
431
435
if ( ! repository ) {
@@ -446,6 +450,9 @@ export const isRepoRoot = (url?: URL | HTMLAnchorElement | Location): boolean =>
446
450
return repository . path . startsWith ( 'tree/' ) && document . title . startsWith ( repository . nameWithOwner ) && ! document . title . endsWith ( repository . nameWithOwner ) ;
447
451
} ;
448
452
453
+ // `_isRepoRoot` logic depends on whether a URL was passed, so don't use a `url` default parameter
454
+ export const isRepoRoot = ( url ?: URL | HTMLAnchorElement | Location ) : boolean => ! hasSearchParameter ( url ?? location ) && _isRepoRoot ( url ) ;
455
+
449
456
addTests ( 'isRepoRoot' , [
450
457
'isRepoHome' ,
451
458
'https://github.com/sindresorhus/refined-github/tree/native-copy-buttons' ,
@@ -486,12 +493,13 @@ addTests('isUserSettings', [
486
493
'isRepliesSettings' ,
487
494
] ) ;
488
495
489
- export const isRepoTree = ( url : URL | HTMLAnchorElement | Location = location ) : boolean => isRepoRoot ( url ) || Boolean ( getRepo ( url ) ?. path . startsWith ( 'tree/' ) ) ;
496
+ export const isRepoTree = ( url : URL | HTMLAnchorElement | Location = location ) : boolean => _isRepoRoot ( url ) || Boolean ( getRepo ( url ) ?. path . startsWith ( 'tree/' ) ) ;
490
497
addTests ( 'isRepoTree' , [
491
498
'isRepoRoot' ,
492
- 'https://github.com/sindresorhus/refined-github/tree/master/distribution' ,
493
- 'https://github.com/sindresorhus/refined-github/tree/0.13.0/distribution' ,
494
- 'https://github.com/sindresorhus/refined-github/tree/57bf435ee12d14b482df0bbd88013a2814c7512e/distribution' ,
499
+ 'https://github.com/sindresorhus/refined-github/tree/main/source' ,
500
+ 'https://github.com/sindresorhus/refined-github/tree/0.13.0/extension' ,
501
+ 'https://github.com/sindresorhus/refined-github/tree/57bf435ee12d14b482df0bbd88013a2814c7512e/extension' ,
502
+ 'https://github.com/sindresorhus/refined-github?search=1' ,
495
503
] ) ;
496
504
497
505
export const isRepoWiki = ( url : URL | HTMLAnchorElement | Location = location ) : boolean => Boolean ( getRepo ( url ) ?. path . startsWith ( 'wiki' ) ) ;
0 commit comments