From 17f785e5c48853d006ef527b09677082462f39ba Mon Sep 17 00:00:00 2001 From: EnixCoda Date: Fri, 17 Jul 2020 12:01:20 +0800 Subject: [PATCH] fix: resolve new GitHub DOM --- src/platforms/GitHub/DOMHelper.ts | 8 ++++++++ src/platforms/GitHub/URLHelper.ts | 5 ----- src/platforms/GitHub/index.ts | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/platforms/GitHub/DOMHelper.ts b/src/platforms/GitHub/DOMHelper.ts index 6919671..1c5c014 100644 --- a/src/platforms/GitHub/DOMHelper.ts +++ b/src/platforms/GitHub/DOMHelper.ts @@ -5,6 +5,14 @@ import { $ } from 'utils/DOMHelper' import { renderReact } from 'utils/general' import { CopyFileButton, copyFileButtonClassName } from './CopyFileButton' +export function isInRepoPage() { + const repoHeadSelector = '.repohead' // legacy + const authorNameSelector = '.author[itemprop="author"]' + return Boolean( + document.querySelector(repoHeadSelector) || document.querySelector(authorNameSelector), + ) +} + export function isInCodePage() { const branchListSelector = ['#branch-select-menu', '.branch-select-menu'].join() return Boolean($(branchListSelector)) diff --git a/src/platforms/GitHub/URLHelper.ts b/src/platforms/GitHub/URLHelper.ts index 7cc1062..fcdc3d5 100644 --- a/src/platforms/GitHub/URLHelper.ts +++ b/src/platforms/GitHub/URLHelper.ts @@ -24,11 +24,6 @@ export function parseSHA() { return type === 'blob' || type === 'tree' ? path[0] : undefined } -export function isInRepoPage() { - const repoHeaderSelector = '.repohead' - return Boolean(document.querySelector(repoHeaderSelector)) -} - export function isInPullPage() { const { type, path } = parse() return type === 'pull' ? path[0] : false diff --git a/src/platforms/GitHub/index.ts b/src/platforms/GitHub/index.ts index 57a770e..a4e81e0 100644 --- a/src/platforms/GitHub/index.ts +++ b/src/platforms/GitHub/index.ts @@ -69,7 +69,7 @@ export function isEnterprise() { export const GitHub: Platform = { isEnterprise, resolveMeta() { - if (!URLHelper.isInRepoPage()) { + if (!DOMHelper.isInRepoPage()) { return null }