initial draft
This commit is contained in:
committed by
Manuel Bouza
parent
8ff93423af
commit
c163c23e7e
21
src/js/background.js
Normal file
21
src/js/background.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import DomainCheck from './services/DomainCheck'
|
||||
|
||||
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
|
||||
// inject files only after the page is fully loaded
|
||||
if (changeInfo.status != 'complete') return
|
||||
|
||||
// inject files only for supported websites
|
||||
const domainCheck = new DomainCheck(tab.url)
|
||||
if (!domainCheck.hasMatch) return
|
||||
|
||||
// inject css + js
|
||||
chrome.tabs.insertCSS(tabId, {file: "/styles.css"}, () => {
|
||||
chrome.tabs.executeScript(tabId, {
|
||||
code: "const div = document.createElement('div'); div.setAttribute('id', 'moco'); document.body.appendChild(div)"
|
||||
}, () => {
|
||||
chrome.tabs.executeScript(tabId, {file: "/popup.js"}, () => {
|
||||
console.log("inejected /popup.js")
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user