initial draft

This commit is contained in:
Tobias Miesel
2018-10-14 13:47:59 +02:00
committed by Manuel Bouza
parent 8ff93423af
commit c163c23e7e
20 changed files with 25116 additions and 4370 deletions

21
src/js/background.js Normal file
View 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")
})
})
})
})

View File

@@ -0,0 +1,11 @@
import React from 'react'
function Modal() {
const onClick = (e) => {
alert("clicked")
}
return <div onClick={onClick}>REACT</div>
}
export default Modal

View File

@@ -1 +0,0 @@
alert("ok")

1
src/js/options.js Normal file
View File

@@ -0,0 +1 @@
console.log("okish from options.js")

8
src/js/popup.js Normal file
View File

@@ -0,0 +1,8 @@
console.log("okish from popup.js")
import React, { createElement } from 'react'
import ReactDOM from 'react-dom'
import Modal from './components/Modal'
const domContainer = document.querySelector('#moco')
ReactDOM.render(createElement(Modal), domContainer)

View File

@@ -0,0 +1,11 @@
class DomainCheck {
constructor(url) {
this.url = url
}
get hasMatch() {
return this.url.match(/github/)
}
}
export default DomainCheck