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', [
292292 'https://github.com/sindresorhus/refined-github?files=1' ,
293293] ) ;
294294
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
296298collect . set ( 'isRepoRoot' , [
297299 ...collect . get ( 'isRepoHome' ) as string [ ] ,
298300 'https://github.com/sindresorhus/refined-github/tree/native-copy-buttons' ,
@@ -442,7 +444,7 @@ const getCleanPathname = (url: URL | Location = location): string => url.pathnam
442444/** Parses a repo's subpage
443445@example '/user/repo/issues/' -> 'issues'
444446@example '/user/repo/' -> ''
445- @exampke '/settings/token/' -> undefined
447+ @example '/settings/token/' -> undefined
446448*/
447449const getRepoPath = ( url : URL | Location = location ) : string | undefined => {
448450 if ( isRepo ( url ) ) {
@@ -452,8 +454,12 @@ const getRepoPath = (url: URL | Location = location): string | undefined => {
452454 return undefined ;
453455} ;
454456
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+
455460export const utils = {
456461 getUsername,
457462 getCleanPathname,
458463 getRepoPath,
464+ getRepoURL,
459465} ;
You can’t perform that action at this time.
0 commit comments