Skip to content

Commit 4ff46aa

Browse files
authored
Detect isRepoRoot on branches with slashes (#16)
1 parent 1ceb204 commit 4ff46aa

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff 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 => /^(tree\/[^/]+)?$/.test(getRepoPath(url)!);
295+
export const isRepoRoot = (url?: URL | Location): boolean =>
296+
/^(tree\/[^/]+)?$/.test(getRepoPath(url ?? location)!) ||
297+
(!url && document.title.startsWith(getRepoURL()) && !document.title.endsWith(getRepoURL())); // #15
296298
collect.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
*/
447449
const 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+
455460
export const utils = {
456461
getUsername,
457462
getCleanPathname,
458463
getRepoPath,
464+
getRepoURL,
459465
};

0 commit comments

Comments
 (0)