File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed
Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -293,9 +293,24 @@ collect.set('isRepoHome', [
293293 'https://github.com/sindresorhus/refined-github?files=1' ,
294294] ) ;
295295
296- export const isRepoRoot = ( url ?: URL | Location ) : boolean =>
297- / ^ ( t r e e \/ [ ^ / ] + ) ? $ / . test ( getRepoPath ( url ?? location ) ! ) &&
298- ( url ? true : ( document . title . startsWith ( getRepoURL ( ) ) && ! document . title . endsWith ( getRepoURL ( ) ) ) ) ; // #15
296+ export const isRepoRoot = ( url ?: URL | Location ) : boolean => {
297+ const repoPath = getRepoPath ( url ?? location ) ;
298+
299+ if ( repoPath === '' ) {
300+ // Absolute repo root: `isRepoHome`
301+ return true ;
302+ }
303+
304+ if ( url ) {
305+ // Root of a branch/commit/tag
306+ return / ^ t r e e \/ [ ^ / ] + $ / . test ( repoPath ! ) ;
307+ }
308+
309+ // If we're checking the current page, add support for branches with slashes // #15 #24
310+ const repoURL = getRepoURL ( ) ;
311+ return String ( repoPath ) . startsWith ( 'tree/' ) && document . title . startsWith ( repoURL ) && ! document . title . endsWith ( repoURL ) ;
312+ } ;
313+
299314collect . set ( 'isRepoRoot' , [
300315 ...collect . get ( 'isRepoHome' ) as string [ ] ,
301316 'https://github.com/sindresorhus/refined-github/tree/native-copy-buttons' ,
You can’t perform that action at this time.
0 commit comments