mirror of
https://github.com/BewlyBewly/BewlyBewly.git
synced 2025-04-14 13:15:29 +00:00
perf: improve styles load performance
This commit is contained in:
@@ -112,24 +112,13 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
originalPageContent.innerHTML = ''
|
||||
}
|
||||
|
||||
document.documentElement.removeChild(beforeLoadedStyleEl)
|
||||
// Then inject the app
|
||||
injectApp()
|
||||
}
|
||||
})
|
||||
|
||||
function injectApp() {
|
||||
// Inject style first
|
||||
const newStyleEl = document.createElement('link')
|
||||
newStyleEl.setAttribute('rel', 'stylesheet')
|
||||
newStyleEl.setAttribute('href', browser.runtime.getURL('dist/contentScripts/style.css'))
|
||||
document.documentElement.appendChild(newStyleEl)
|
||||
newStyleEl.onload = () => {
|
||||
// To prevent abrupt style transitions caused by sudden style changes
|
||||
setTimeout(() => {
|
||||
document.documentElement.removeChild(beforeLoadedStyleEl)
|
||||
}, 500)
|
||||
}
|
||||
|
||||
// Inject app when idle
|
||||
runWhenIdle(async () => {
|
||||
// mount component to context window
|
||||
|
||||
Reference in New Issue
Block a user