Skip to content

Commit

Permalink
fix: Content script sometimes gets injected after DOMContentLoaded event
Browse files Browse the repository at this point in the history
  • Loading branch information
A-K-O-R-A committed Jan 20, 2025
1 parent a40b226 commit 4ae1e7a
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/contentScripts/other/selma/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ async function createCreditsBanner() {
const credits = document.createElement('p')

credits.style.margin = 'auto'
credits.style.marginLeft = '10px'
credits.style.marginRight = '0'
credits.style.color = '#002557' // Selma theme color
credits.id = 'TUfastCredits'
Expand Down Expand Up @@ -237,24 +238,25 @@ async function createCreditsBanner() {
return credits
}

// Apply all custom changes once documentd loaded
;(async () => {
const { improveSelma } = await chrome.storage.local.get(['improveSelma'])

// Apply all custom changes
document.addEventListener('DOMContentLoaded', async () => {
// Add Credit banner with toggle button
const creditElm = await createCreditsBanner()
document.querySelector('.semesterChoice')!.appendChild(creditElm)

if (!improveSelma) return

eventListener()
})
if (document.readyState !== 'loading') {
await eventListener()
} else {
document.addEventListener('DOMContentLoaded', eventListener)
}
})()

async function eventListener() {
document.removeEventListener('DOMContentLoaded', eventListener)

// Add Credit banner with toggle button
const creditElm = await createCreditsBanner()
document.querySelector('.semesterChoice')!.appendChild(creditElm)

const { improveSelma } = await chrome.storage.local.get(['improveSelma'])
if (!improveSelma) return

// Inject css
injectCSS('base')
if (currentView.startsWith('/APP/EXAMRESULTS/') || currentView.startsWith('/APP/COURSERESULTS/')) {
Expand Down

0 comments on commit 4ae1e7a

Please sign in to comment.