Add support for css in content_scripts
This commit is contained in:
parent
6bf2ec4188
commit
e1a232e7c8
2 changed files with 22 additions and 9 deletions
|
@ -239,7 +239,8 @@ const injectContentScripts = function (manifest) {
|
|||
const contentScriptToEntry = function (script) {
|
||||
return {
|
||||
matches: script.matches,
|
||||
js: script.js.map(readArrayOfFiles),
|
||||
js: script.js ? script.js.map(readArrayOfFiles) : [],
|
||||
css: script.css ? script.css.map(readArrayOfFiles) : [],
|
||||
runAt: script.run_at || 'document_idle'
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,14 +28,26 @@ const runContentScript = function (extensionId, url, code) {
|
|||
const injectContentScript = function (extensionId, script) {
|
||||
if (!script.matches.some(matchesPattern)) return
|
||||
|
||||
for (const {url, code} of script.js) {
|
||||
const fire = runContentScript.bind(window, extensionId, url, code)
|
||||
if (script.runAt === 'document_start') {
|
||||
process.once('document-start', fire)
|
||||
} else if (script.runAt === 'document_end') {
|
||||
process.once('document-end', fire)
|
||||
} else if (script.runAt === 'document_idle') {
|
||||
document.addEventListener('DOMContentLoaded', fire)
|
||||
if (script.js) {
|
||||
for (const {url, code} of script.js) {
|
||||
const fire = runContentScript.bind(window, extensionId, url, code)
|
||||
if (script.runAt === 'document_start') {
|
||||
process.once('document-start', fire)
|
||||
} else if (script.runAt === 'document_end') {
|
||||
process.once('document-end', fire)
|
||||
} else if (script.runAt === 'document_idle') {
|
||||
document.addEventListener('DOMContentLoaded', fire)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (script.css) {
|
||||
for (const {code} of script.css) {
|
||||
process.once('document-end', () => {
|
||||
var node = document.createElement('style')
|
||||
node.innerHTML = code
|
||||
window.document.body.appendChild(node)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue