diff --git a/src/contentScripts/other/selma/layout.ts b/src/contentScripts/other/selma/layout.ts index 50e9df2..0f0a03b 100644 --- a/src/contentScripts/other/selma/layout.ts +++ b/src/contentScripts/other/selma/layout.ts @@ -209,7 +209,9 @@ Actual logic // Create a small banner that indicates the user that the site was modified // It also adds a small toggle to disable the table -function createCreditsBanner () { +async function createCreditsBanner() { + const { improveSelma: settingEnabled } = await chrome.storage.local.get(['improveSelma']) + const imgUrl = chrome.runtime.getURL('/assets/images/tufast48.png') const credits = document.createElement('p') @@ -217,7 +219,7 @@ function createCreditsBanner () { credits.style.marginRight = '0' credits.style.color = '#002557' // Selma theme color credits.id = 'TUfastCredits' - credits.innerHTML = `Table powered by + credits.innerHTML = `Table ${settingEnabled ? 'powered by' : 'disabled'} TUfast by AKORA @@ -239,11 +241,11 @@ function createCreditsBanner () { // Tooltip disableButton.title = - 'Disable the "ImproveSelma" feature and reload the page to apply the change.' - disableButton.textContent = 'Disable' + 'Toggle the "ImproveSelma" feature and reload the page to apply the change.' + disableButton.textContent = settingEnabled ? 'Deactivate' : 'Activate' disableButton.onclick = async (event) => { event.preventDefault() - await chrome.storage.local.set({ improveSelma: false }) + await chrome.storage.local.set({ improveSelma: !settingEnabled }) window.location.reload() } credits.appendChild(disableButton) @@ -254,13 +256,19 @@ function createCreditsBanner () { (async () => { const { improveSelma } = await chrome.storage.local.get(['improveSelma']) - if (!improveSelma) return - // Apply all custom changes - document.addEventListener('DOMContentLoaded', eventListener) + document.addEventListener('DOMContentLoaded', async () => { + // Add Credit banner with toggle button + const creditElm = await createCreditsBanner() + document.querySelector('.semesterChoice')!.appendChild(creditElm) + + if (!improveSelma) return + + eventListener(); + }) })() -function eventListener () { +async function eventListener () { document.removeEventListener('DOMContentLoaded', eventListener) // Inject css @@ -275,12 +283,6 @@ function eventListener () { injectCSS('my_exams') } - // Add Credit banner - { - const creditElm = createCreditsBanner() - document.querySelector('.semesterChoice')!.appendChild(creditElm) - } - applyChanges() }