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

View File

@ -7,10 +7,10 @@
document.querySelector(msg.options.containerSelector).appendChild(elem)
break
case "uninject":
browser.runtime.onMessage.removeListener(processMessage)
chrome.runtime.onMessage.removeListener(processMessage)
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"),
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
containerSelector.value = o.containerSelector
monitorInterval.value = o.monitorInterval