Skip to content

Commit

Permalink
Fix crash on Firefox (#1074)
Browse files Browse the repository at this point in the history
  • Loading branch information
the1812 committed Nov 12, 2020
1 parent 0d105ee commit 6ac20a4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/client/bilibili-evolved.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ import { store } from './store'
const style = document.createElement('style')
style.innerHTML = cache.darkStyle
style.id = 'dark-style'
document.head.insertAdjacentElement('afterbegin', style)
document.documentElement.insertAdjacentElement('afterbegin', style)
}
} else {
const style = document.createElement('style')
style.innerHTML = Object.entries(offlineData).find(([key]) => {
return key.includes('/dark.min.css')
})[1]
style.id = 'dark-style'
document.head.insertAdjacentElement('afterbegin', style)
document.documentElement.insertAdjacentElement('afterbegin', style)
}
}
console.log(`Skipped <iframe> loading for ${document.URL}`)
Expand Down Expand Up @@ -228,7 +228,7 @@ import { store } from './store'
const prefetchLink = document.createElement('link')
prefetchLink.rel = 'dns-prefetch'
prefetchLink.href = 'https://api.bilibili.com'
document.head.insertAdjacentElement('afterbegin', prefetchLink)
document.documentElement.insertAdjacentElement('afterbegin', prefetchLink)

Object.assign(unsafeWindow.bilibiliEvolved, {
SpinQuery,
Expand Down
2 changes: 1 addition & 1 deletion src/client/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class Resource {
if (important) {
document.body.insertAdjacentElement('beforeend', style)
} else {
document.head.insertAdjacentElement('afterbegin', style)
document.documentElement.insertAdjacentElement('afterbegin', style)
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/client/script-blocker.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,24 @@ export const getScriptBlocker = async () => {
super()
this.started = false
}
start () {
async start () {
if (this.started) {
return
}
this.started = true
const blockEvent = node => this.dispatchEvent(new CustomEvent('block', {
detail: node
}))
const blocker = Observer.childList(document.head, records => {
const head = await SpinQuery.select('head')
if (!head) {
return
}
const blocker = Observer.childList(head, records => {
records.forEach(r => {
removeNodes(r.addedNodes, blockEvent)
})
})
removeNodes(document.head.childNodes, blockEvent)
removeNodes(head.childNodes, blockEvent)
const bodyObserver = Observer.childList(document.documentElement, records => {
records.forEach(r => {
r.addedNodes.forEach(node => {
Expand Down
4 changes: 2 additions & 2 deletions src/client/style-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ export class StyleManager {
}
applyStyleFromText (text, id) {
if (!id) {
document.head.insertAdjacentHTML('afterbegin', text)
document.documentElement.insertAdjacentHTML('afterbegin', text)
} else {
const style = document.createElement('style')
style.id = id
style.innerHTML = text
document.head.insertAdjacentElement('afterbegin', style)
document.documentElement.insertAdjacentElement('afterbegin', style)
}
}
applyImportantStyleFromText (text, id) {
Expand Down

0 comments on commit 6ac20a4

Please sign in to comment.