Skip to content

Commit f5de492

Browse files
committed
Slight performance improvements
1 parent 0ed11b3 commit f5de492

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ collect.set('isRepoRoot', [
330330

331331
// This can't use `getRepoPath` to avoid infinite recursion.
332332
// `getRepoPath` depends on `isRepo` and `isRepo` depends on `isRepoSearch`
333-
export const isRepoSearch = (url: URL | HTMLAnchorElement | Location = location): boolean => url.pathname.slice(1).split('/')[2] === 'search';
333+
export const isRepoSearch = (url: URL | HTMLAnchorElement | Location = location): boolean => url.pathname.split('/')[3] === 'search';
334334
collect.set('isRepoSearch', [
335335
'https://github.com/sindresorhus/refined-github/search?q=diff',
336336
'https://github.com/sindresorhus/refined-github/search?q=diff&unscoped_q=diff&type=Issues',
@@ -491,7 +491,7 @@ collect.set('isNewRepo', [
491491
const getUsername = () => document.querySelector('meta[name="user-login"]')!.getAttribute('content')!;
492492

493493
/** Drop leading and trailing slashes */
494-
const getCleanPathname = (url: URL | HTMLAnchorElement | Location = location): string => url.pathname.replace(/^\/|\/$/g, '');
494+
const getCleanPathname = (url: URL | HTMLAnchorElement | Location = location): string => url.pathname.slice(1, url.pathname.endsWith('/') ? -1 : undefined);
495495

496496
/** Parses a repo's subpage
497497
@example '/user/repo/issues/' -> 'issues'
@@ -507,7 +507,7 @@ const getRepoPath = (url: URL | HTMLAnchorElement | Location = location): string
507507
};
508508

509509
/** Get the 'user/repo' part from an URL. Tries using the canonical URL to avoid capitalization errors in the `location` URL */
510-
const getRepoURL = (url?: URL | Location): string => {
510+
const getRepoURL = (url?: URL | HTMLAnchorElement | Location): string => {
511511
if (!url) {
512512
const canonical = document.querySelector<HTMLMetaElement>('[property="og:url"]'); // `rel=canonical` doesn't appear on every page
513513
url = canonical ? new URL(canonical.content, location.origin) : location;

0 commit comments

Comments
 (0)