Merge pull request #1 from rainyeveryday/master

Update to work with Chrome
This commit is contained in:
Kamil Tomala 2018-06-03 13:22:37 +02:00 committed by GitHub
commit f33e5642c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 16 deletions

View File

@ -5,10 +5,10 @@ let listeningTabs = []
let timer = null let timer = null
let options = defaultOptions let options = defaultOptions
browser.storage.local.get(defaultOptions) chrome.storage.local.get(defaultOptions,
.then(o => options = o) o => options = o)
browser.storage.onChanged.addListener((changes, area) => { chrome.storage.onChanged.addListener((changes, area) => {
if(area === "local") { if(area === "local") {
const optionKeys = Object.keys(options) const optionKeys = Object.keys(options)
for(key of Object.keys(changes)) { for(key of Object.keys(changes)) {
@ -20,9 +20,9 @@ browser.storage.onChanged.addListener((changes, area) => {
} }
}) })
browser.browserAction.onClicked.addListener(() => { chrome.browserAction.onClicked.addListener(() => {
browser.tabs.query({ active: true, currentWindow: true }) chrome.tabs.query({ active: true, currentWindow: true },
.then(([t]) => toggleTab(t.id)) ([t]) => toggleTab(t.id))
}) })
window.onload = () => { window.onload = () => {
@ -39,24 +39,24 @@ function toggleTab(id) {
uninject(id) uninject(id)
listeningTabs.splice(index, 1) listeningTabs.splice(index, 1)
updateTimer() updateTimer()
browser.browserAction.setBadgeText({ text: "", tabId: id }) chrome.browserAction.setBadgeText({ text: "", tabId: id })
} else { } else {
browser.tabs.executeScript({file: "/fg/insert.js"}) chrome.tabs.executeScript({file: "/fg/insert.js"})
listeningTabs.push(id) listeningTabs.push(id)
updateTimer() updateTimer()
browser.browserAction.setBadgeBackgroundColor({ color: "green", tabId: id }) chrome.browserAction.setBadgeBackgroundColor({ color: "green", tabId: id })
browser.browserAction.setBadgeText({ text: "ON", tabId: id }) chrome.browserAction.setBadgeText({ text: "ON", tabId: id })
} }
} }
function notifyForeground(id, text) { function notifyForeground(id, text) {
browser.tabs.sendMessage(id, { chrome.tabs.sendMessage(id, {
action: "insert", text, options action: "insert", text, options
}) })
} }
function uninject(id) { function uninject(id) {
browser.tabs.sendMessage(id, { action: "uninject" }) chrome.tabs.sendMessage(id, { action: "uninject" })
} }
function checkClipboard() { function checkClipboard() {

View File

@ -7,10 +7,10 @@
document.querySelector(msg.options.containerSelector).appendChild(elem) document.querySelector(msg.options.containerSelector).appendChild(elem)
break break
case "uninject": case "uninject":
browser.runtime.onMessage.removeListener(processMessage) chrome.runtime.onMessage.removeListener(processMessage)
break break
} }
} }
browser.runtime.onMessage.addListener(processMessage) chrome.runtime.onMessage.addListener(processMessage)
})() })()

View File

@ -3,9 +3,9 @@ document.addEventListener("DOMContentLoaded", () => {
containerSelector = document.querySelector("#container-selector"), containerSelector = document.querySelector("#container-selector"),
monitorInterval = document.querySelector("#monitor-interval") monitorInterval = document.querySelector("#monitor-interval")
const storage = browser.storage.local const storage = chrome.storage.local
storage.get(defaultOptions).then(o => { storage.get(defaultOptions, o => {
elemName.value = o.elemName elemName.value = o.elemName
containerSelector.value = o.containerSelector containerSelector.value = o.containerSelector
monitorInterval.value = o.monitorInterval monitorInterval.value = o.monitorInterval