Files
rebloor 82217a05bc Replace var with let in examples (#484)
* Replace var with let in examples

store-collected-images/webextension-plain/deps/uuidv4.js

* Reverted third–party code
2022-08-11 04:27:28 +12:00

28 lines
834 B
JavaScript

/* Retrieve any previously set cookie and send to content script */
function getActiveTab() {
return browser.tabs.query({active: true, currentWindow: true});
}
function cookieUpdate() {
getActiveTab().then((tabs) => {
// get any previously set cookie for the current tab
let gettingCookies = browser.cookies.get({
url: tabs[0].url,
name: "bgpicker"
});
gettingCookies.then((cookie) => {
if (cookie) {
let cookieVal = JSON.parse(cookie.value);
browser.tabs.sendMessage(tabs[0].id, {image: cookieVal.image});
browser.tabs.sendMessage(tabs[0].id, {color: cookieVal.color});
}
});
});
}
// update when the tab is updated
browser.tabs.onUpdated.addListener(cookieUpdate);
// update when the tab is activated
browser.tabs.onActivated.addListener(cookieUpdate);