File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -292,7 +292,9 @@ collect.set('isRepoHome', [
292
292
'https://github.com/sindresorhus/refined-github?files=1' ,
293
293
] ) ;
294
294
295
- export const isRepoRoot = ( url : URL | Location = location ) : boolean => / ^ ( t r e e \/ [ ^ / ] + ) ? $ / . test ( getRepoPath ( url ) ! ) ;
295
+ export const isRepoRoot = ( url ?: URL | Location ) : boolean =>
296
+ / ^ ( t r e e \/ [ ^ / ] + ) ? $ / . test ( getRepoPath ( url ?? location ) ! ) ||
297
+ ( ! url && document . title . startsWith ( getRepoURL ( ) ) && ! document . title . endsWith ( getRepoURL ( ) ) ) ; // #15
296
298
collect . set ( 'isRepoRoot' , [
297
299
...collect . get ( 'isRepoHome' ) as string [ ] ,
298
300
'https://github.com/sindresorhus/refined-github/tree/native-copy-buttons' ,
@@ -442,7 +444,7 @@ const getCleanPathname = (url: URL | Location = location): string => url.pathnam
442
444
/** Parses a repo's subpage
443
445
@example '/user/repo/issues/' -> 'issues'
444
446
@example '/user/repo/' -> ''
445
- @exampke '/settings/token/' -> undefined
447
+ @example '/settings/token/' -> undefined
446
448
*/
447
449
const getRepoPath = ( url : URL | Location = location ) : string | undefined => {
448
450
if ( isRepo ( url ) ) {
@@ -452,8 +454,12 @@ const getRepoPath = (url: URL | Location = location): string | undefined => {
452
454
return undefined ;
453
455
} ;
454
456
457
+ /** Get the 'user/repo' part from an URL */
458
+ const getRepoURL = ( url : URL | Location = location ) : string => url . pathname . slice ( 1 ) . split ( '/' , 2 ) . join ( '/' ) ;
459
+
455
460
export const utils = {
456
461
getUsername,
457
462
getCleanPathname,
458
463
getRepoPath,
464
+ getRepoURL,
459
465
} ;
You can’t perform that action at this time.
0 commit comments