Update to work with Chrome
This commit is contained in:
parent
e977862e44
commit
26d9434b28
|
|
@ -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() {
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
})()
|
})()
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue