diff --git a/src/platforms/GitHub/DOMHelper.ts b/src/platforms/GitHub/DOMHelper.ts index dc42fce..adb2a81 100644 --- a/src/platforms/GitHub/DOMHelper.ts +++ b/src/platforms/GitHub/DOMHelper.ts @@ -7,8 +7,8 @@ import { CopyFileButton, copyFileButtonClassName } from './CopyFileButton' export function resolveMeta(): Partial { const metaData = { - userName: $('[itemprop="author"] > a[rel="author"]', e => e.textContent?.trim()), - repoName: $('[itemprop="name"] > a[href]', e => e.textContent?.trim()), + userName: $('[itemprop="author"] > a[rel="author"]', e => e.textContent?.trim()) || undefined, + repoName: $('[itemprop="name"] > a[href]', e => e.textContent?.trim()) || undefined, branchName: getCurrentBranch(true), } if (!metaData.userName || !metaData.repoName) { @@ -65,7 +65,7 @@ export function getCurrentBranch(passive = false) { const findFileButtonSelector = '#js-repo-pjax-container .repository-content .file-navigation a[data-hotkey="t"]' - const urlFromFindFileButton: string | undefined = $( + const urlFromFindFileButton = $( findFileButtonSelector, element => (element as HTMLAnchorElement).href, ) diff --git a/src/utils/DOMHelper.ts b/src/utils/DOMHelper.ts index 301560a..be14b24 100644 --- a/src/utils/DOMHelper.ts +++ b/src/utils/DOMHelper.ts @@ -38,17 +38,17 @@ export function setBodyIndent(shouldShowGitako: boolean) { } export function $(selector: string): HTMLElement | null -export function $(selector: string, existCallback: (element: HTMLElement) => T1): T1 +export function $(selector: string, existCallback: (element: HTMLElement) => T1): T1 | null export function $( selector: string, existCallback: (element: HTMLElement) => T1, otherwise: () => T2, -): T1 | T2 +): T1 | T2 | null export function $( selector: string, existCallback: undefined | null, otherwise: () => T2, -): HTMLElement | null | T2 +): HTMLElement | T2 | null // eslint-disable-next-line @typescript-eslint/no-explicit-any export function $(selector: string, existCallback?: any, otherwise?: any) { const element = document.querySelector(selector)