Rewrite examples to use browser.* and promises (#138)

This commit is contained in:
wbamberg
2016-11-15 10:12:55 -08:00
committed by GitHub
parent 664239dac0
commit c5d69d15d6
33 changed files with 290 additions and 244 deletions

View File

@@ -1,26 +1,30 @@
/* Retrieve any previously set cookie and send to content script */
chrome.tabs.onUpdated.addListener(cookieUpdate);
browser.tabs.onUpdated.addListener(cookieUpdate);
function getActiveTab() {
return browser.tabs.query({active: true, currentWindow: true});
}
function cookieUpdate(tabId, changeInfo, tab) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
getActiveTab().then((tabs) => {
/* inject content script into current tab */
chrome.tabs.executeScript(null, {
browser.tabs.executeScript(null, {
file: "/content_scripts/updatebg.js"
});
// get any previously set cookie for the current tab
chrome.cookies.get({
var gettingCookies = browser.cookies.get({
url: tabs[0].url,
name: "bgpicker"
}, function(cookie) {
});
gettingCookies.then((cookie) => {
if(cookie) {
var cookieVal = JSON.parse(cookie.value);
chrome.tabs.sendMessage(tabs[0].id, {image: cookieVal.image});
chrome.tabs.sendMessage(tabs[0].id, {color: cookieVal.color});
browser.tabs.sendMessage(tabs[0].id, {image: cookieVal.image});
browser.tabs.sendMessage(tabs[0].id, {color: cookieVal.color});
}
});
});
}
}