diff --git a/src/platforms/GitHub/API.ts b/src/platforms/GitHub/API.ts index 6048cb5..8a23e0c 100644 --- a/src/platforms/GitHub/API.ts +++ b/src/platforms/GitHub/API.ts @@ -151,7 +151,7 @@ export async function getPullPageDocuments( document?: Document, ) { if (document) { - return continuousLoadFragmentedPages(document) + return continuousLoadFragmentedPages(window.location.href, document) } // Response of this contains view of few files but is not complete. return continuousLoadFragmentedPagesFromUrl(`/${userName}/${repoName}/pull/${pullId}/files`) @@ -162,7 +162,7 @@ export async function getCommitPageDocuments() { repoName: string, commitId: string, */ // arguments are not used because info are collected from DOM directly - return continuousLoadFragmentedPages(document) + return continuousLoadFragmentedPages(window.location.href, document) } export async function getBlobData( diff --git a/src/platforms/GitHub/DOMHelper.ts b/src/platforms/GitHub/DOMHelper.ts index e1dcae8..e25e2f1 100644 --- a/src/platforms/GitHub/DOMHelper.ts +++ b/src/platforms/GitHub/DOMHelper.ts @@ -151,7 +151,13 @@ export function isInPullFilesPage() { } export function getIssueTitle() { - const title = $('.gh-header-title')?.textContent + const title = $( + [ + '.gh-header-title .markdown-title', // exclude issue ID from title + '.gh-header-title', + '[data-component="TitleArea"] [data-component="PH_Title"]', // PR new experience title + ].join(), + )?.textContent return title?.trim().replace(/\n/g, '') } diff --git a/src/platforms/GitHub/utils.ts b/src/platforms/GitHub/utils.ts index f83ff58..b3c0158 100644 --- a/src/platforms/GitHub/utils.ts +++ b/src/platforms/GitHub/utils.ts @@ -76,13 +76,14 @@ export function resolveHeaderLink(raw: string) { } } -export async function getDOM(url: string) { +async function getDOM(url: string) { const res = await fetch(url) const content = await res.text() - return new DOMParser().parseFromString(content, 'text/html') + return [res.url, new DOMParser().parseFromString(content, 'text/html')] as const } export async function continuousLoadFragmentedPages( + url: string, doc: Document, docs: Document[] = [], ): Promise<[string, Document[]]> { @@ -108,17 +109,15 @@ export async function continuousLoadFragmentedPages( const src = fragment.getAttribute('src') if (src) { // Using `src` without origin below would fail in Firefox if the src is an absolute path - await continuousLoadFragmentedPagesFromUrl(src, docs) + return await continuousLoadFragmentedPagesFromUrl(src, docs) } } - return [new URL(doc.baseURI).pathname, docs] + return [new URL(url).pathname, docs] } export async function continuousLoadFragmentedPagesFromUrl(url: string, docs: Document[] = []) { - return continuousLoadFragmentedPages( - await getDOM(new URL(url, window.location.origin).href), - docs, - ) + const [finalUrl, dom] = await getDOM(new URL(url, window.location.origin).href) + return continuousLoadFragmentedPages(finalUrl, dom, docs) } export function getCommentsMap(commentData: GitHubAPI.PullComments) {