Skip to content

Commit

Permalink
fix: fix dom observer
Browse files Browse the repository at this point in the history
  • Loading branch information
holazz committed Jun 28, 2022
1 parent 48d09e1 commit 6cf979a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/content-scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Button from './views/Button.vue'

function isRepoPage() {
return document.body.contains(
document.querySelector('#repo-content-pjax-container'),
document.querySelector('#js-repo-pjax-container'),
)
}

Expand All @@ -14,16 +14,16 @@ async function init() {
if (document.querySelector('#gh1s-btn')) return
createElement()
})
observer.observe(document.querySelector('#js-repo-pjax-container')!, {
observer.observe(document, {
childList: true,
subtree: true,
})
}

async function createElement() {
// [.d-none .d-md-block] didn't exist when not login
const refNode = document.querySelector(
// [.d-none .d-md-block] didn't exist when not login
'#repo-content-pjax-container a.btn[data-hotkey="t"]',
'#js-repo-pjax-container a.btn[data-hotkey="t"]',
)
if (!refNode) return

Expand Down

0 comments on commit 6cf979a

Please sign in to comment.