diff --git a/src/entrypoints/episodeList.content/index.ts b/src/entrypoints/episodeList.content/index.ts index ad764a5..2a08bd4 100644 --- a/src/entrypoints/episodeList.content/index.ts +++ b/src/entrypoints/episodeList.content/index.ts @@ -148,33 +148,52 @@ function formatEpisodeTitles() { export default defineContentScript({ matches: ['*://*.la.utexas.edu/player'], + runAt: 'document_start', async main() { - injectStylesheets(); - removeElements('h2', 'p', '#lo_logo', 'hr'); + const style = document.createElement('style'); + style.id = 'hide-original'; + style.textContent = ` + html { + visibility: hidden !important; + } + `; + document.documentElement.appendChild(style); + if (document.readyState === 'loading') { + await new Promise(resolve => + document.addEventListener('DOMContentLoaded', () => resolve(), { once: true }) + ); + } + try { + injectStylesheets(); + removeElements('h2', 'p', '#lo_logo', 'hr'); - const body = document.querySelector('body'); - if (body) body.style.padding = '65px 65px 130px 65px'; + const body = document.querySelector('body'); + if (body) body.style.padding = '65px 65px 130px 65px'; - styleHeader(); - styleCourseBlock(); - buildHeaderRow(); + styleHeader(); + styleCourseBlock(); + buildHeaderRow(); - const faq_link = document.querySelector( - 'a[href="https://sites.la.utexas.edu/lecturesonline/students/faq"]' - ); - if (faq_link) faq_link.style.fontFamily = 'Roboto Flex'; + const faq_link = document.querySelector( + 'a[href="https://sites.la.utexas.edu/lecturesonline/students/faq"]' + ); + if (faq_link) faq_link.style.fontFamily = 'Roboto Flex'; - formatEpisodeTitles(); + formatEpisodeTitles(); - if (!document.getElementById('utlp-view-toolbar')) { - const h2 = document.querySelector('h2'); - if (h2) { - h2.insertAdjacentElement('afterend', buildViewToggle()); + if (!document.getElementById('utlp-view-toolbar')) { + const h2 = document.querySelector('h2'); + if (h2) { + h2.insertAdjacentElement('afterend', buildViewToggle()); + } } - } - saveOriginalPositions(); - applyViewMode(getCurrentMode()); + saveOriginalPositions(); + applyViewMode(getCurrentMode()); + } finally { + // Always reveal the page, even if setup threw + style.remove(); + } const observer = new MutationObserver(() => { const mode = getCurrentMode();