diff options
-rw-r--r-- | source/features/action-used-by-link.tsx | 12 | ||||
-rw-r--r-- | source/features/comments-time-machine-links.tsx | 2 | ||||
-rw-r--r-- | source/features/deep-reblame.tsx | 2 | ||||
-rw-r--r-- | source/features/default-branch-button.tsx | 2 | ||||
-rw-r--r-- | source/features/edit-readme.tsx | 2 | ||||
-rw-r--r-- | source/features/enable-file-links-in-compare-view.tsx | 6 | ||||
-rw-r--r-- | source/features/follow-file-renames.tsx | 2 | ||||
-rw-r--r-- | source/features/global-conversation-list-filters.tsx | 2 | ||||
-rw-r--r-- | source/features/latest-tag-button.tsx | 2 | ||||
-rw-r--r-- | source/features/linkify-labels-on-dashboard.tsx | 2 | ||||
-rw-r--r-- | source/features/next-scheduled-github-action.tsx | 2 | ||||
-rw-r--r-- | source/features/quick-file-edit.tsx | 2 | ||||
-rw-r--r-- | source/features/show-user-top-repositories.tsx | 14 | ||||
-rw-r--r-- | source/features/useful-not-found-page.tsx | 6 | ||||
-rw-r--r-- | source/github-helpers/github-url.ts | 4 | ||||
-rw-r--r-- | source/github-helpers/index.ts | 1 | ||||
-rw-r--r-- | source/helpers/fetch-dom.ts | 2 |
17 files changed, 31 insertions, 34 deletions
diff --git a/source/features/action-used-by-link.tsx b/source/features/action-used-by-link.tsx index bd8364f8..0a1ed320 100644 --- a/source/features/action-used-by-link.tsx +++ b/source/features/action-used-by-link.tsx @@ -12,13 +12,15 @@ function init(): void { .slice(1); const actionURL = new URL('search', location.origin); - actionURL.searchParams.set('q', `${actionRepo} path:.github/workflows/ language:YAML`); - actionURL.searchParams.set('type', 'Code'); - actionURL.searchParams.set('s', 'indexed'); - actionURL.searchParams.set('o', 'desc'); + actionURL.search = new URLSearchParams({ + q: `${actionRepo} path:.github/workflows/ language:YAML`, + type: 'Code', + s: 'indexed', + o: 'desc', + }).toString(); select('.d-block.mb-2[href^="/contact"]')!.after( - <a href={String(actionURL)} className="d-block mb-2"> + <a href={actionURL.href} className="d-block mb-2"> <SearchIcon width={14} className="color-text-primary mr-2"/>Usage examples </a>, ); diff --git a/source/features/comments-time-machine-links.tsx b/source/features/comments-time-machine-links.tsx index 4ad610f7..e3c5e3fc 100644 --- a/source/features/comments-time-machine-links.tsx +++ b/source/features/comments-time-machine-links.tsx @@ -102,7 +102,7 @@ async function showTimeMachineBar(): Promise<void | false> { } const link = ( - <a className="rgh-link-date" href={String(url)} data-pjax="#repo-content-pjax-container"> + <a className="rgh-link-date" href={url.href} data-pjax="#repo-content-pjax-container"> view this object as it appeared at the time of the comment </a> ); diff --git a/source/features/deep-reblame.tsx b/source/features/deep-reblame.tsx index f59e6dfd..bf5a82f7 100644 --- a/source/features/deep-reblame.tsx +++ b/source/features/deep-reblame.tsx @@ -73,7 +73,7 @@ async function redirectToBlameCommit(event: delegate.Event<MouseEvent, HTMLAncho try { blameUrl.branch = await getPullRequestBlameCommit(prCommit, prNumbers, blameUrl.filePath); blameUrl.hash = 'L' + select('.js-line-number', blameHunk)!.textContent!; - location.href = String(blameUrl); + location.href = blameUrl.href; } catch (error: unknown) { spinner.replaceWith(<VersionsIcon/>); alert((error as Error).message); diff --git a/source/features/default-branch-button.tsx b/source/features/default-branch-button.tsx index c8bcac9f..3256b530 100644 --- a/source/features/default-branch-button.tsx +++ b/source/features/default-branch-button.tsx @@ -36,7 +36,7 @@ async function init(): Promise<false | void> { const defaultLink = ( <a className="btn tooltipped tooltipped-ne rgh-default-branch-button" - href={String(url)} + href={url.href} data-pjax="#repo-content-pjax-container" aria-label="See this view on the default branch" > diff --git a/source/features/edit-readme.tsx b/source/features/edit-readme.tsx index 2c1bc829..a4553035 100644 --- a/source/features/edit-readme.tsx +++ b/source/features/edit-readme.tsx @@ -31,7 +31,7 @@ async function init(): Promise<void | false> { readmeHeader.append( <a - href={String(url)} + href={url.href} className={`${readmeHeader.matches('.js-sticky') ? 'p-2' : 'Box-btn-octicon'} btn-octicon`} aria-label="Edit this file" > diff --git a/source/features/enable-file-links-in-compare-view.tsx b/source/features/enable-file-links-in-compare-view.tsx index 85df3a7a..74f251ac 100644 --- a/source/features/enable-file-links-in-compare-view.tsx +++ b/source/features/enable-file-links-in-compare-view.tsx @@ -31,20 +31,20 @@ function handleCompareMenuOpening({delegateTarget: dropdown}: delegate.Event): v ); const url = new GitHubURL(viewFile.href); - viewFile.href = url.assign({branch}).toString(); + viewFile.href = url.assign({branch}).href; // Fix the edit link const editFile = viewFile.cloneNode(true); editFile.textContent = 'Edit file'; editFile.removeAttribute('data-ga-click'); - editFile.href = url.assign({route: 'edit'}).toString(); + editFile.href = url.assign({route: 'edit'}).href; select('[aria-label$="to make changes."]', dropdown)!.replaceWith(editFile); // Fix the delete link const deleteFile = editFile.cloneNode(true); deleteFile.textContent = 'Delete file'; deleteFile.classList.add('menu-item-danger'); - deleteFile.href = url.assign({route: 'delete'}).toString(); + deleteFile.href = url.assign({route: 'delete'}).href; select('[aria-label$="delete this file."]', dropdown)!.replaceWith(deleteFile); } diff --git a/source/features/follow-file-renames.tsx b/source/features/follow-file-renames.tsx index 598ae5fc..0621701f 100644 --- a/source/features/follow-file-renames.tsx +++ b/source/features/follow-file-renames.tsx @@ -61,7 +61,7 @@ async function linkify(button: HTMLButtonElement, filePath: string): Promise<voi if (fileChanges.file[fromKey] === filePath) { button.replaceWith( <a - href={String(linkifiedURL)} + href={linkifiedURL.href} aria-label={`Renamed ${isNewer ? 'to' : 'from'} ${fileChanges.file[toKey]!}`} className="btn btn-outline BtnGroup-item tooltipped tooltipped-n tooltipped-no-delay" > diff --git a/source/features/global-conversation-list-filters.tsx b/source/features/global-conversation-list-filters.tsx index e8193708..c31763f7 100644 --- a/source/features/global-conversation-list-filters.tsx +++ b/source/features/global-conversation-list-filters.tsx @@ -24,7 +24,7 @@ function init(): void { // Create link const url = new URL(isIssues ? '/issues' : '/pulls', location.origin); url.searchParams.set('q', `${typeQuery} ${defaultQuery} ${query}`); - const link = <a href={String(url)} title={title} className="subnav-item">{label}</a>; + const link = <a href={url.href} title={title} className="subnav-item">{label}</a>; const isCurrentPage = new SearchQuery(location.search).includes(query); diff --git a/source/features/latest-tag-button.tsx b/source/features/latest-tag-button.tsx index a0843091..b240375a 100644 --- a/source/features/latest-tag-button.tsx +++ b/source/features/latest-tag-button.tsx @@ -102,7 +102,7 @@ async function init(): Promise<false | void> { const link = ( <a className="btn btn-sm ml-0 flex-self-center css-truncate rgh-latest-tag-button" - href={String(url)} + href={url.href} data-pjax="#repo-content-pjax-container" > <TagIcon/> diff --git a/source/features/linkify-labels-on-dashboard.tsx b/source/features/linkify-labels-on-dashboard.tsx index 04711ff4..cc94efb0 100644 --- a/source/features/linkify-labels-on-dashboard.tsx +++ b/source/features/linkify-labels-on-dashboard.tsx @@ -17,7 +17,7 @@ function init(): void { const url = new URL(`${repository.href}/${isPR ? 'pulls' : 'issues'}`); const labelName = label.textContent!.trim(); url.searchParams.set('q', `is:${isPR ? 'pr' : 'issue'} is:open sort:updated-desc label:"${labelName}"`); - wrap(label, <a href={String(url)}/>); + wrap(label, <a href={url.href}/>); }, }); } diff --git a/source/features/next-scheduled-github-action.tsx b/source/features/next-scheduled-github-action.tsx index b1a08f9c..5b6d37d2 100644 --- a/source/features/next-scheduled-github-action.tsx +++ b/source/features/next-scheduled-github-action.tsx @@ -76,7 +76,7 @@ async function init(): Promise<false | void> { workflowListItem.append(<em>(next {relativeTime})</em>); setTimeout(() => { // The content of `relative-time` might not be immediately available workflowListItem.parentElement!.classList.add('tooltipped', 'tooltipped-e'); - workflowListItem.parentElement!.setAttribute('aria-label', 'Next ' + relativeTime.textContent!.toString()); + workflowListItem.parentElement!.setAttribute('aria-label', 'Next ' + relativeTime.textContent!); }, 500); } } diff --git a/source/features/quick-file-edit.tsx b/source/features/quick-file-edit.tsx index 4857473d..c764d65e 100644 --- a/source/features/quick-file-edit.tsx +++ b/source/features/quick-file-edit.tsx @@ -24,7 +24,7 @@ async function init(): Promise<void> { url.branch = await getDefaultBranch(); // Permalinks can't be edited } - wrap(fileIcon, <a href={String(url)} className="rgh-quick-file-edit"/>); + wrap(fileIcon, <a href={url.href} className="rgh-quick-file-edit"/>); fileIcon.after(<PencilIcon/>); } } diff --git a/source/features/show-user-top-repositories.tsx b/source/features/show-user-top-repositories.tsx index 2e129802..34453c8b 100644 --- a/source/features/show-user-top-repositories.tsx +++ b/source/features/show-user-top-repositories.tsx @@ -4,18 +4,18 @@ import * as pageDetect from 'github-url-detection'; import features from '.'; -function buildUrl(): URL { +function init(): void { const url = new URL(location.pathname, location.href); - url.searchParams.set('tab', 'repositories'); - url.searchParams.set('sort', 'stargazers'); - return url; -} + // DO NOT add type: 'source' since forks could also have many stars + url.search = new URLSearchParams({ + tab: 'repositories', + sort: 'stargazers', + }).toString(); -function init(): void { // Showcase title select('.js-pinned-items-reorder-container .text-normal')!.firstChild!.after( ' / ', - <a href={String(buildUrl())}>Top repositories</a>, + <a href={url.href}>Top repositories</a>, ); } diff --git a/source/features/useful-not-found-page.tsx b/source/features/useful-not-found-page.tsx index a48800e5..7a9a9232 100644 --- a/source/features/useful-not-found-page.tsx +++ b/source/features/useful-not-found-page.tsx @@ -64,7 +64,7 @@ async function getUrlToFileOnDefaultBranch(): Promise<string | void> { } parsedUrl.assign({branch: await getDefaultBranch()}); - const urlOnDefault = parsedUrl.toString(); + const urlOnDefault = parsedUrl.href; if (urlOnDefault !== location.href && !await is404(urlOnDefault)) { return urlOnDefault; } @@ -127,9 +127,9 @@ async function showAlternateLink(): Promise<void> { } url.assign({route: 'commits'}); - const commitHistory = <a href={url.toString()}>Commit history</a>; + const commitHistory = <a href={url.href}>Commit history</a>; url.assign({route: 'blob', branch: fileChanges.commit.parentSha, filePath: url.filePath}); - const lastVersionUrl = fileChanges.file.status === 'removed' ? fileChanges.file.blob_url : url.toString(); + const lastVersionUrl = fileChanges.file.status === 'removed' ? fileChanges.file.blob_url : url.href; const lastVersion = <a href={lastVersionUrl}>This {getType()}</a>; const permalink = <a href={fileChanges.commit.url}><relative-time datetime={fileChanges.commit.date}/></a>; const verb = fileChanges.file.status === 'removed' diff --git a/source/github-helpers/github-url.ts b/source/github-helpers/github-url.ts index e8acd411..21f1368e 100644 --- a/source/github-helpers/github-url.ts +++ b/source/github-helpers/github-url.ts @@ -24,10 +24,6 @@ export default class GitHubURL { return this.href; } - toJSON(): string { - return this.href; - } - assign(...replacements: Array<Partial<GitHubURL>>): this { Object.assign(this, ...replacements); return this; diff --git a/source/github-helpers/index.ts b/source/github-helpers/index.ts index d768b867..aae1b402 100644 --- a/source/github-helpers/index.ts +++ b/source/github-helpers/index.ts @@ -37,7 +37,6 @@ export const getCurrentCommittish = (pathname = location.pathname, title = docum return unslashedCommittish; }; -export const isFirefox = navigator.userAgent.includes('Firefox/'); export const isMac = navigator.userAgent.includes('Macintosh'); // The type requires at least one parameter https://stackoverflow.com/a/49910890 diff --git a/source/helpers/fetch-dom.ts b/source/helpers/fetch-dom.ts index ccf63476..42649b6f 100644 --- a/source/helpers/fetch-dom.ts +++ b/source/helpers/fetch-dom.ts @@ -8,7 +8,7 @@ async function fetchDom(url: string): Promise<DocumentFragment>; async function fetchDom<Selector extends string, TElement extends HTMLElement = ParseSelector<Selector, HTMLElement>>(url: string, selector: Selector): Promise<TElement | undefined>; async function fetchDom(url: string, selector?: string): Promise<Node | undefined> { features.log.http(url); - const absoluteURL = new URL(url, location.origin).toString(); // Firefox `fetch`es from the content script, so relative URLs fail + const absoluteURL = new URL(url, location.origin).href; // Firefox `fetch`es from the content script, so relative URLs fail const response = await fetch(absoluteURL); const dom = domify(await response.text()); if (selector) { |