Skip to content

Commit 7f9941d

Browse files
authored
fix: always update button href to support SPA navigations (#2)
1 parent f38192d commit 7f9941d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@
2727
style.innerHTML = css
2828
document.head.appendChild(style)
2929

30+
function updateButtonHref(button) {
31+
button.href = location.href.replace('https://github.com/', 'https://pr.new/')
32+
}
33+
3034
function createButton() {
3135
const a = document.createElement('a')
32-
a.href = location.href.replace('https://github.com/', 'https://pr.new/')
36+
updateButtonHref(a)
3337
a.target = '_blank'
3438
a.classList.add('btn')
3539
a.classList.add('btn-sm')
@@ -49,8 +53,12 @@
4953
}
5054

5155
function run() {
52-
if (document.querySelector(`#${id}`))
56+
const button = document.querySelector(`#${id}`)
57+
if (button) {
58+
// Always update the link to support GitHub SPA navigations
59+
updateButtonHref(button)
5360
return
61+
}
5462

5563
const repoActions = document.querySelector('#repository-details-container ul')
5664
if (repoActions) {

0 commit comments

Comments
 (0)