Skip to content

Commit

Permalink
feat(github): highlight following
Browse files Browse the repository at this point in the history
  • Loading branch information
leedom92 committed Jun 29, 2024
1 parent 9fade53 commit 71a90b7
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions extension/scripts/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,40 @@
// }
// }

// 监听是否有新dom插入
document.addEventListener('DOMNodeInserted', function () {
const PAST_SPONSORSHIP = document.getElementsByClassName('Label--secondary')
function getParams(params) {
const search = window.location.search
const urlParams = new URLSearchParams(search)
return urlParams.get(params)
}

function highlightPastSponsorship() {
const search = window.location.search
const PAST_SPONSORSHIP = document.getElementsByClassName('Label--secondary')

if (PAST_SPONSORSHIP?.length && search === '?tab=sponsoring') {
if (PAST_SPONSORSHIP?.length && getParams('tab') === 'sponsoring') {
for (const dom of PAST_SPONSORSHIP) {
dom.style.backgroundColor = '#bf3989'
dom.style.border = '#bf3989'
dom.style.color = '#fff'
}
}
}

function highlightFollowing() {
const search = window.location.search
const elements = document.querySelectorAll('form[hidden="hidden"] input[name="commit"][value="Follow"]')

if (elements?.length && ['following', 'followers'].includes(getParams('tab'))) {
for (const dom of elements) {
const parent = dom.parentElement.closest('div.d-table')
parent.style.backgroundColor = 'wheat'
parent.style.padding = '15px'
}
}
}

// 监听是否有新dom插入
document.addEventListener('DOMNodeInserted', function () {
highlightPastSponsorship()
highlightFollowing()
})

0 comments on commit 71a90b7

Please sign in to comment.