diff --git a/apply-css/background.js b/apply-css/background.js index 8c76e1d..7e936a0 100644 --- a/apply-css/background.js +++ b/apply-css/background.js @@ -11,17 +11,18 @@ function toggleCSS(tab) { function gotTitle(title) { if (title === TITLE_APPLY) { - chrome.pageAction.setIcon({tabId: tab.id, path: "icons/on.svg"}); - chrome.pageAction.setTitle({tabId: tab.id, title: TITLE_REMOVE}); - chrome.tabs.insertCSS({code: CSS}); + browser.pageAction.setIcon({tabId: tab.id, path: "icons/on.svg"}); + browser.pageAction.setTitle({tabId: tab.id, title: TITLE_REMOVE}); + browser.tabs.insertCSS({code: CSS}); } else { - chrome.pageAction.setIcon({tabId: tab.id, path: "icons/off.svg"}); - chrome.pageAction.setTitle({tabId: tab.id, title: TITLE_APPLY}); - chrome.tabs.removeCSS({code: CSS}); + browser.pageAction.setIcon({tabId: tab.id, path: "icons/off.svg"}); + browser.pageAction.setTitle({tabId: tab.id, title: TITLE_APPLY}); + browser.tabs.removeCSS({code: CSS}); } } - chrome.pageAction.getTitle({tabId: tab.id}, gotTitle) + var gettingTitle = browser.pageAction.getTitle({tabId: tab.id}); + gettingTitle.then(gotTitle); } /* @@ -39,16 +40,17 @@ Only operates on tabs whose URL's protocol is applicable. */ function initializePageAction(tab) { if (protocolIsApplicable(tab.url)) { - chrome.pageAction.setIcon({tabId: tab.id, path: "icons/off.svg"}); - chrome.pageAction.setTitle({tabId: tab.id, title: TITLE_APPLY}); - chrome.pageAction.show(tab.id); + browser.pageAction.setIcon({tabId: tab.id, path: "icons/off.svg"}); + browser.pageAction.setTitle({tabId: tab.id, title: TITLE_APPLY}); + browser.pageAction.show(tab.id); } } /* When first loaded, initialize the page action for all tabs. */ -chrome.tabs.query({}, (tabs) => { +var gettingAllTabs = browser.tabs.query({}); +gettingAllTabs.then((tabs) => { for (tab of tabs) { initializePageAction(tab); } @@ -57,11 +59,11 @@ chrome.tabs.query({}, (tabs) => { /* Each time a tab is updated, reset the page action for that tab. */ -chrome.tabs.onUpdated.addListener((id, changeInfo, tab) => { +browser.tabs.onUpdated.addListener((id, changeInfo, tab) => { initializePageAction(tab); }); /* Toggle CSS when the page action is clicked. */ -chrome.pageAction.onClicked.addListener(toggleCSS); +browser.pageAction.onClicked.addListener(toggleCSS); diff --git a/beastify/content_scripts/beastify.js b/beastify/content_scripts/beastify.js index d10cca0..88f3f71 100644 --- a/beastify/content_scripts/beastify.js +++ b/beastify/content_scripts/beastify.js @@ -7,7 +7,7 @@ beastify(): function beastify(request, sender, sendResponse) { removeEverything(); insertBeast(request.beastURL); - chrome.runtime.onMessage.removeListener(beastify); + browser.runtime.onMessage.removeListener(beastify); } /* @@ -34,4 +34,4 @@ function insertBeast(beastURL) { /* Assign beastify() as a listener for messages from the extension. */ -chrome.runtime.onMessage.addListener(beastify); +browser.runtime.onMessage.addListener(beastify); diff --git a/beastify/popup/choose_beast.js b/beastify/popup/choose_beast.js index c7dcb7b..d70225c 100644 --- a/beastify/popup/choose_beast.js +++ b/beastify/popup/choose_beast.js @@ -4,11 +4,11 @@ Given the name of a beast, get the URL to the corresponding image. function beastNameToURL(beastName) { switch (beastName) { case "Frog": - return chrome.extension.getURL("beasts/frog.jpg"); + return browser.extension.getURL("beasts/frog.jpg"); case "Snake": - return chrome.extension.getURL("beasts/snake.jpg"); + return browser.extension.getURL("beasts/snake.jpg"); case "Turtle": - return chrome.extension.getURL("beasts/turtle.jpg"); + return browser.extension.getURL("beasts/turtle.jpg"); } } @@ -25,23 +25,22 @@ If it's on a button wich contains class "clear": Reload the page. Close the popup. This is needed, as the content script malfunctions after page reloads. */ -document.addEventListener("click", function(e) { +document.addEventListener("click", (e) => { if (e.target.classList.contains("beast")) { var chosenBeast = e.target.textContent; var chosenBeastURL = beastNameToURL(chosenBeast); - chrome.tabs.executeScript(null, { + browser.tabs.executeScript(null, { file: "/content_scripts/beastify.js" }); - chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { - chrome.tabs.sendMessage(tabs[0].id, {beastURL: chosenBeastURL}); + var gettingActiveTab = browser.tabs.query({active: true, currentWindow: true}); + gettingActiveTab.then((tabs) => { + browser.tabs.sendMessage(tabs[0].id, {beastURL: chosenBeastURL}); }); - - return; } else if (e.target.classList.contains("clear")) { - chrome.tabs.reload(); + browser.tabs.reload(); window.close(); return; diff --git a/bookmark-it/background.js b/bookmark-it/background.js index 6b07a58..171beaf 100644 --- a/bookmark-it/background.js +++ b/bookmark-it/background.js @@ -6,7 +6,7 @@ var currentBookmark; * is already bookmarked. */ function updateIcon() { - chrome.browserAction.setIcon({ + browser.browserAction.setIcon({ path: currentBookmark ? { 19: "icons/star-filled-19.png", 38: "icons/star-filled-38.png" @@ -23,42 +23,47 @@ function updateIcon() { */ function toggleBookmark() { if (currentBookmark) { - chrome.bookmarks.remove(currentBookmark.id); + browser.bookmarks.remove(currentBookmark.id); currentBookmark = null; updateIcon(); } else { - chrome.bookmarks.create({title: currentTab.title, url: currentTab.url}, function(bookmark) { + var creating = browser.bookmarks.create({title: currentTab.title, url: currentTab.url}); + creating.then(function(bookmark) { currentBookmark = bookmark; updateIcon(); }); } } -chrome.browserAction.onClicked.addListener(toggleBookmark); +browser.browserAction.onClicked.addListener(toggleBookmark); /* * Switches currentTab and currentBookmark to reflect the currently active tab */ -function updateTab() { - chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { +function updateActiveTab(tabs) { + + function updateTab(tabs) { if (tabs[0]) { currentTab = tabs[0]; - - chrome.bookmarks.search({url: currentTab.url}, (bookmarks) => { + var searching = browser.bookmarks.search({url: currentTab.url}); + searching.then((bookmarks) => { currentBookmark = bookmarks[0]; updateIcon(); }); } - }); + } + + var gettingActiveTab = browser.tabs.query({active: true, currentWindow: true}); + gettingActiveTab.then(updateTab); } // TODO listen for bookmarks.onCreated and bookmarks.onRemoved once Bug 1221764 lands // listen to tab URL changes -chrome.tabs.onUpdated.addListener(updateTab); +browser.tabs.onUpdated.addListener(updateActiveTab); // listen to tab switching -chrome.tabs.onActivated.addListener(updateTab); +browser.tabs.onActivated.addListener(updateActiveTab); // update when the extension loads initially -updateTab(); +updateActiveTab(); diff --git a/chill-out/background.js b/chill-out/background.js index 696a76c..bbf453f 100644 --- a/chill-out/background.js +++ b/chill-out/background.js @@ -14,18 +14,20 @@ var CATGIFS = "http://chilloutandwatchsomecatgifs.com/"; /* Restart alarm for the currently active tab, whenever background.js is run. */ -chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { +var gettingActiveTab = browser.tabs.query({active: true, currentWindow: true}); +gettingActiveTab.then((tabs) => { restartAlarm(tabs[0].id); }); /* Restart alarm for the currently active tab, whenever the user navigates. */ -chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) { +browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { if (!changeInfo.url) { return; } - chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { + var gettingActiveTab = browser.tabs.query({active: true, currentWindow: true}); + gettingActiveTab.then((tabs) => { if (tabId == tabs[0].id) { restartAlarm(tabId); } @@ -35,7 +37,7 @@ chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) { /* Restart alarm for the currently active tab, whenever a new tab becomes active. */ -chrome.tabs.onActivated.addListener(function (activeInfo) { +browser.tabs.onActivated.addListener((activeInfo) => { restartAlarm(activeInfo.tabId); }); @@ -44,11 +46,12 @@ restartAlarm: clear all alarms, then set a new alarm for the given tab. */ function restartAlarm(tabId) { - chrome.pageAction.hide(tabId); - chrome.alarms.clearAll(); - chrome.tabs.get(tabId, function(tab) { + browser.pageAction.hide(tabId); + browser.alarms.clearAll(); + var gettingTab = browser.tabs.get(tabId); + gettingTab.then((tab) => { if (tab.url != CATGIFS) { - chrome.alarms.create("", {delayInMinutes: DELAY}); + browser.alarms.create("", {delayInMinutes: DELAY}); } }); } @@ -56,15 +59,16 @@ function restartAlarm(tabId) { /* On alarm, show the page action. */ -chrome.alarms.onAlarm.addListener(function(alarm) { - chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { - chrome.pageAction.show(tabs[0].id); +browser.alarms.onAlarm.addListener((alarm) => { + var gettingActiveTab = browser.tabs.query({active: true, currentWindow: true}); + gettingActiveTab.then((tabs) => { + browser.pageAction.show(tabs[0].id); }); }); /* On page action click, navigate the corresponding tab to the cat gifs. */ -chrome.pageAction.onClicked.addListener(function () { - chrome.tabs.update({url: CATGIFS}); +browser.pageAction.onClicked.addListener(function () { + browser.tabs.update({url: CATGIFS}); }); diff --git a/commands/background.js b/commands/background.js index f4d0b33..825c559 100644 --- a/commands/background.js +++ b/commands/background.js @@ -10,10 +10,11 @@ * shortcut: "Ctrl+Shift+U" * }] */ -chrome.commands.getAll(function(commands) { - commands.forEach(function(command) { +var gettingAllCommands = browser.commands.getAll(); +gettingAllCommands.then((commands) => { + for (command of commands) { console.log(command); - }); + } }); /** @@ -22,6 +23,6 @@ chrome.commands.getAll(function(commands) { * In this sample extension, there is only one registered command: "Ctrl+Shift+U". * On Mac, this command will automatically be converted to "Command+Shift+U". */ -chrome.commands.onCommand.addListener(function(command) { +browser.commands.onCommand.addListener((command) => { console.log("onCommand event received for message: ", command); }); diff --git a/context-menu-demo/background.js b/context-menu-demo/background.js index cac9325..a52e33c 100644 --- a/context-menu-demo/background.js +++ b/context-menu-demo/background.js @@ -3,63 +3,67 @@ Called when the item has been created, or when creation failed due to an error. We'll just log success/failure here. */ function onCreated(n) { - if (chrome.runtime.lastError) { - console.log("error creating item:" + chrome.runtime.lastError); + if (browser.runtime.lastError) { + console.log(`Error: ${browser.runtime.lastError}`); } else { - console.log("item created successfully"); + console.log("Item created successfully"); } } /* -Called when the item has been removed, or when there was an error. -We'll just log success or failure here. +Called when the item has been removed. +We'll just log success here. */ function onRemoved() { - if (chrome.runtime.lastError) { - console.log("error removing item:" + chrome.runtime.lastError); - } else { - console.log("item removed successfully"); - } + console.log("Item removed successfully"); +} + +/* +Called when there was an error. +We'll just log the error here. +*/ +function onError(error) { + console.log(`Error: ${error}`); } /* Create all the context menu items. */ -chrome.contextMenus.create({ +browser.contextMenus.create({ id: "log-selection", - title: chrome.i18n.getMessage("contextMenuItemSelectionLogger"), + title: browser.i18n.getMessage("contextMenuItemSelectionLogger"), contexts: ["selection"] }, onCreated); -chrome.contextMenus.create({ +browser.contextMenus.create({ id: "remove-me", - title: chrome.i18n.getMessage("contextMenuItemRemoveMe"), + title: browser.i18n.getMessage("contextMenuItemRemoveMe"), contexts: ["all"] }, onCreated); -chrome.contextMenus.create({ +browser.contextMenus.create({ id: "separator-1", type: "separator", contexts: ["all"] }, onCreated); -chrome.contextMenus.create({ +browser.contextMenus.create({ id: "greenify", type: "radio", - title: chrome.i18n.getMessage("contextMenuItemGreenify"), + title: browser.i18n.getMessage("contextMenuItemGreenify"), contexts: ["all"], checked: true }, onCreated); -chrome.contextMenus.create({ +browser.contextMenus.create({ id: "bluify", type: "radio", - title: chrome.i18n.getMessage("contextMenuItemBluify"), + title: browser.i18n.getMessage("contextMenuItemBluify"), contexts: ["all"], checked: false }, onCreated); -chrome.contextMenus.create({ +browser.contextMenus.create({ id: "separator-2", type: "separator", contexts: ["all"] @@ -67,10 +71,10 @@ chrome.contextMenus.create({ var checkedState = true; -chrome.contextMenus.create({ +browser.contextMenus.create({ id: "check-uncheck", type: "checkbox", - title: chrome.i18n.getMessage("contextMenuItemUncheckMe"), + title: browser.i18n.getMessage("contextMenuItemUncheckMe"), contexts: ["all"], checked: checkedState }, onCreated); @@ -85,7 +89,7 @@ var blue = 'document.body.style.border = "5px solid blue"'; var green = 'document.body.style.border = "5px solid green"'; function borderify(tabId, color) { - chrome.tabs.executeScript(tabId, { + browser.tabs.executeScript(tabId, { code: color }); } @@ -101,12 +105,12 @@ property into the event listener. function updateCheckUncheck() { checkedState = !checkedState; if (checkedState) { - chrome.contextMenus.update("check-uncheck", { - title: chrome.i18n.getMessage("contextMenuItemUncheckMe"), + browser.contextMenus.update("check-uncheck", { + title: browser.i18n.getMessage("contextMenuItemUncheckMe"), }); } else { - chrome.contextMenus.update("check-uncheck", { - title: chrome.i18n.getMessage("contextMenuItemCheckMe"), + browser.contextMenus.update("check-uncheck", { + title: browser.i18n.getMessage("contextMenuItemCheckMe"), }); } } @@ -115,13 +119,14 @@ function updateCheckUncheck() { The click event listener, where we perform the appropriate action given the ID of the menu item that was clicked. */ -chrome.contextMenus.onClicked.addListener(function(info, tab) { +browser.contextMenus.onClicked.addListener(function(info, tab) { switch (info.menuItemId) { case "log-selection": console.log(info.selectionText); break; case "remove-me": - chrome.contextMenus.remove(info.menuItemId, onRemoved); + var removing = browser.contextMenus.remove(info.menuItemId); + removing.then(onRemoved, onError); break; case "bluify": borderify(tab.id, blue); diff --git a/cookie-bg-picker/background_scripts/background.js b/cookie-bg-picker/background_scripts/background.js index 8a728ab..fb0640a 100644 --- a/cookie-bg-picker/background_scripts/background.js +++ b/cookie-bg-picker/background_scripts/background.js @@ -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}); } }); }); -} \ No newline at end of file +} diff --git a/cookie-bg-picker/content_scripts/updatebg.js b/cookie-bg-picker/content_scripts/updatebg.js index 045a1e4..f3bd6be 100644 --- a/cookie-bg-picker/content_scripts/updatebg.js +++ b/cookie-bg-picker/content_scripts/updatebg.js @@ -1,7 +1,7 @@ var html = document.querySelector('html'); var body = document.querySelector('body'); -chrome.runtime.onMessage.addListener(updateBg); +browser.runtime.onMessage.addListener(updateBg); function updateBg(request, sender, sendResponse) { if(request.image) { @@ -16,4 +16,4 @@ function updateBg(request, sender, sendResponse) { body.style.backgroundImage = ''; body.style.backgroundColor = ''; } -} \ No newline at end of file +} diff --git a/cookie-bg-picker/popup/bgpicker.js b/cookie-bg-picker/popup/bgpicker.js index af9699f..987c61f 100644 --- a/cookie-bg-picker/popup/bgpicker.js +++ b/cookie-bg-picker/popup/bgpicker.js @@ -6,6 +6,10 @@ var reset = document.querySelector('.color-reset button'); var cookieVal = { image : '', color : '' }; +function getActiveTab() { + return browser.tabs.query({active: true, currentWindow: true}); +} + /* apply backgrounds to buttons */ /* add listener so that when clicked, button applies background to page HTML */ @@ -15,13 +19,13 @@ for(var i = 0; i < bgBtns.length; i++) { bgBtns[i].style.backgroundImage = bgImg; bgBtns[i].onclick = function(e) { - chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { + getActiveTab().then((tabs) => { var imgName = e.target.getAttribute('class'); - var fullURL = chrome.extension.getURL('popup/images/'+ imgName + '.png'); - chrome.tabs.sendMessage(tabs[0].id, {image: fullURL}); + var fullURL = browser.extension.getURL('popup/images/'+ imgName + '.png'); + browser.tabs.sendMessage(tabs[0].id, {image: fullURL}); cookieVal.image = fullURL; - chrome.cookies.set({ + browser.cookies.set({ url: tabs[0].url, name: "bgpicker", value: JSON.stringify(cookieVal) @@ -33,12 +37,12 @@ for(var i = 0; i < bgBtns.length; i++) { /* apply chosen color to HTML background */ colorPick.onchange = function(e) { - chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { + getActiveTab().then((tabs) => { var currColor = e.target.value; - chrome.tabs.sendMessage(tabs[0].id, {color: currColor}); + browser.tabs.sendMessage(tabs[0].id, {color: currColor}); cookieVal.color = currColor; - chrome.cookies.set({ + browser.cookies.set({ url: tabs[0].url, name: "bgpicker", value: JSON.stringify(cookieVal) @@ -49,12 +53,12 @@ colorPick.onchange = function(e) { /* reset background */ reset.onclick = function() { - chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { - chrome.tabs.sendMessage(tabs[0].id, {reset: true}); + getActiveTab().then((tabs) => { + browser.tabs.sendMessage(tabs[0].id, {reset: true}); cookieVal = { image : '', color : '' }; - chrome.cookies.remove({ + browser.cookies.remove({ url: tabs[0].url, name: "bgpicker" }) @@ -63,6 +67,9 @@ reset.onclick = function() { /* Report cookie changes to the console */ -chrome.cookies.onChanged.addListener(function(changeInfo) { - console.log('Cookie changed:\n* Cookie: ' + JSON.stringify(changeInfo.cookie) + '\n* Cause: ' + changeInfo.cause + '\n* Removed: ' + changeInfo.removed); -}) \ No newline at end of file +browser.cookies.onChanged.addListener((changeInfo) => { + console.log(`Cookie changed:\n + * Cookie: ${JSON.stringify(changeInfo.cookie)}\n + * Cause: ${changeInfo.cause}\n + * Removed: ${changeInfo.removed}`); +}); diff --git a/embedded-webextension-bootstrapped/step1-hybrid-addon/webextension/popup.js b/embedded-webextension-bootstrapped/step1-hybrid-addon/webextension/popup.js index 2392196..ab5360d 100644 --- a/embedded-webextension-bootstrapped/step1-hybrid-addon/webextension/popup.js +++ b/embedded-webextension-bootstrapped/step1-hybrid-addon/webextension/popup.js @@ -1,7 +1,7 @@ "use strict"; -browser.storage.local.get("super-important-user-setting", results => { +var gettingItem = browser.storage.local.get("super-important-user-setting"); +gettingItem.then(results => { const panelContent = results["super-important-user-setting"] || "No settings saved."; - document.querySelector("#panel-content").textContent = panelContent; }); diff --git a/embedded-webextension-bootstrapped/step2-pure-webextension/popup.js b/embedded-webextension-bootstrapped/step2-pure-webextension/popup.js index 9d60c21..ab5360d 100644 --- a/embedded-webextension-bootstrapped/step2-pure-webextension/popup.js +++ b/embedded-webextension-bootstrapped/step2-pure-webextension/popup.js @@ -1,7 +1,7 @@ "use strict"; -browser.storage.local.set("super-important-user-setting", results => { +var gettingItem = browser.storage.local.get("super-important-user-setting"); +gettingItem.then(results => { const panelContent = results["super-important-user-setting"] || "No settings saved."; - document.querySelector("#panel-content").textContent = panelContent; }); diff --git a/embedded-webextension-sdk/step1-hybrid-addon/webextension/popup.js b/embedded-webextension-sdk/step1-hybrid-addon/webextension/popup.js index 4ece87b..a58ece8 100644 --- a/embedded-webextension-sdk/step1-hybrid-addon/webextension/popup.js +++ b/embedded-webextension-sdk/step1-hybrid-addon/webextension/popup.js @@ -1,3 +1,4 @@ -browser.storage.local.get((results) => { +const gettingItem = browser.storage.local.get(); +gettingItem.then((results) => { document.querySelector("#panel-content").textContent = JSON.stringify(results, null, 2); }); diff --git a/embedded-webextension-sdk/step2-pure-webextension/options.js b/embedded-webextension-sdk/step2-pure-webextension/options.js index 1bc4f2c..22a840e 100644 --- a/embedded-webextension-sdk/step2-pure-webextension/options.js +++ b/embedded-webextension-sdk/step2-pure-webextension/options.js @@ -1,4 +1,5 @@ -browser.storage.local.get("prefs", results => { +const gettingItem = browser.storage.local.get("prefs"); +gettingItem.then(results => { const {prefs} = results || { prefs: { superImportantUserPref: "default value" diff --git a/embedded-webextension-sdk/step2-pure-webextension/popup.js b/embedded-webextension-sdk/step2-pure-webextension/popup.js index 4ece87b..a58ece8 100644 --- a/embedded-webextension-sdk/step2-pure-webextension/popup.js +++ b/embedded-webextension-sdk/step2-pure-webextension/popup.js @@ -1,3 +1,4 @@ -browser.storage.local.get((results) => { +const gettingItem = browser.storage.local.get(); +gettingItem.then((results) => { document.querySelector("#panel-content").textContent = JSON.stringify(results, null, 2); }); diff --git a/favourite-colour/background.js b/favourite-colour/background.js index 86fa4ad..be08803 100644 --- a/favourite-colour/background.js +++ b/favourite-colour/background.js @@ -1,5 +1,5 @@ function handleClick() { - chrome.runtime.openOptionsPage(); + browser.runtime.openOptionsPage(); } -chrome.browserAction.onClicked.addListener(handleClick); +browser.browserAction.onClicked.addListener(handleClick); diff --git a/favourite-colour/options.js b/favourite-colour/options.js index 5693865..caa9695 100644 --- a/favourite-colour/options.js +++ b/favourite-colour/options.js @@ -1,11 +1,12 @@ function saveOptions(e) { - chrome.storage.local.set({ + browser.storage.local.set({ colour: document.querySelector("#colour").value }); } function restoreOptions() { - chrome.storage.local.get('colour', (res) => { + var gettingItem = browser.storage.local.get('colour'); + gettingItem.then((res) => { document.querySelector("#colour").value = res.colour || 'Firefox red'; }); } diff --git a/history-deleter/background.js b/history-deleter/background.js index db6433c..dd9f375 100644 --- a/history-deleter/background.js +++ b/history-deleter/background.js @@ -1,5 +1,5 @@ -chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { +browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { if (!tab.url.match(/^about:/)) { - chrome.pageAction.show(tab.id); + browser.pageAction.show(tab.id); } }); diff --git a/history-deleter/history.js b/history-deleter/history.js index c9d1949..11a1dff 100644 --- a/history-deleter/history.js +++ b/history-deleter/history.js @@ -8,7 +8,7 @@ function get_hostname(url) { function set_domain(domain) { spans = document.getElementsByClassName('domain'); - [].slice.call(spans).forEach(function(span) { + [].slice.call(spans).forEach((span) => { span.textContent = domain; }); } @@ -20,52 +20,53 @@ function no_history(hostname) { history_text.textContent = `No history for ${hostname}.`; } +function getActiveTab() { + return browser.tabs.query({active: true, currentWindow: true}); +} + // When the page is loaded find the current tab and then use that to query // the history. -chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { +getActiveTab().then((tabs) => { var list = document.getElementById('history'); var hostname = get_hostname(tabs[0].url); - chrome.history.search( - // Search for all history entries for the current windows domain. - // Because this could be a lot of entries, lets limit it to 5. - {text: hostname, maxResults: 5}, - function(results) { - // What to show if there are no results. - if (results.length < 1) { - no_history(hostname); - } else { - for (var k in results) { - var history = results[k]; - var li = document.createElement('p'); - var a = document.createElement('a'); - var url = document.createTextNode(history.url); - a.href = history.url; - a.target = '_blank'; - a.appendChild(url); - li.appendChild(a); - list.appendChild(li); - } + // Search for all history entries for the current windows domain. + // Because this could be a lot of entries, lets limit it to 5. + var searchingHistory = browser.history.search({text: hostname, maxResults: 5}); + searchingHistory.then((results) => { + // What to show if there are no results. + if (results.length < 1) { + no_history(hostname); + } else { + for (var k in results) { + var history = results[k]; + var li = document.createElement('p'); + var a = document.createElement('a'); + var url = document.createTextNode(history.url); + a.href = history.url; + a.target = '_blank'; + a.appendChild(url); + li.appendChild(a); + list.appendChild(li); } } - ); + }); }); function clearAll(e) { - chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { + getActiveTab().then((tabs) => { var hostname = get_hostname(tabs[0].url); if (!hostname) { // Don't try and delete history when there's no hostname. return; } - chrome.history.search( - {text: hostname}, - // Search will return us a list of histories for this domain. - // Loop through them and delete them one by one. - function(results) { + // Search will return us a list of histories for this domain. + // Loop through them and delete them one by one. + var searchingHistory = browser.history.search({text: hostname}) + searchingHistory.then((results) => { for (k = 0; k < results.length; k++) { - chrome.history.deleteUrl({url: results[k].url}); + browser.history.deleteUrl({url: results[k].url}); } // Clear out the UI. no_history(hostname); diff --git a/latest-download/popup/latest_download.js b/latest-download/popup/latest_download.js index 5423681..5619131 100644 --- a/latest-download/popup/latest_download.js +++ b/latest-download/popup/latest_download.js @@ -3,22 +3,17 @@ var latestDownloadId; /* Callback from getFileIcon. -Log an error, or initialize the displayed icon. +Initialize the displayed icon. */ function updateIconUrl(iconUrl) { - /* - If there was an error getting the icon URL, - then lastError will be set. So check lastError - and handle it. - */ - if (chrome.runtime.lastError) { - console.error(chrome.runtime.lastError); - iconUrl = ""; - } var downloadIcon = document.querySelector("#icon"); downloadIcon.setAttribute("src", iconUrl); } +function onError(error) { + console.log(`Error: ${error}`); +} + /* If there was a download item, - remember its ID as latestDownloadId @@ -30,7 +25,8 @@ function initializeLatestDownload(downloadItems) { var downloadUrl = document.querySelector("#url"); if (downloadItems.length > 0) { latestDownloadId = downloadItems[0].id; - chrome.downloads.getFileIcon(latestDownloadId, updateIconUrl); + var gettingIconUrl = browser.downloads.getFileIcon(latestDownloadId); + gettingIconUrl.then(updateIconUrl, onError); downloadUrl.textContent = downloadItems[0].url; document.querySelector("#open").classList.remove("disabled"); document.querySelector("#remove").classList.remove("disabled"); @@ -44,17 +40,18 @@ function initializeLatestDownload(downloadItems) { /* Search for the most recent download, and pass it to initializeLatestDownload() */ -chrome.downloads.search({ +var searching = browser.downloads.search({ limit: 1, orderBy: ["-startTime"] -}, initializeLatestDownload); +}); +searching.then(initializeLatestDownload); /* Open the item using the associated application. */ function openItem() { if (!document.querySelector("#open").classList.contains("disabled")) { - chrome.downloads.open(latestDownloadId); + browser.downloads.open(latestDownloadId); } } @@ -63,8 +60,8 @@ Remove item from disk (removeFile) and from the download history (erase) */ function removeItem() { if (!document.querySelector("#remove").classList.contains("disabled")) { - chrome.downloads.removeFile(latestDownloadId); - chrome.downloads.erase({id: latestDownloadId}); + browser.downloads.removeFile(latestDownloadId); + browser.downloads.erase({id: latestDownloadId}); window.close(); } } diff --git a/list-cookies/README.md b/list-cookies/README.md new file mode 100644 index 0000000..877c00e --- /dev/null +++ b/list-cookies/README.md @@ -0,0 +1,9 @@ +# list-cookies + +## What it does + +This extensions list the cookies in the active tab. + +# What it shows + +Demonstration of the getAll() function in the cookie API diff --git a/list-cookies/cookies.css b/list-cookies/cookies.css new file mode 100644 index 0000000..95af25c --- /dev/null +++ b/list-cookies/cookies.css @@ -0,0 +1,11 @@ +html, body { + width: 500px; +} + +.panel { + padding: 5px; +} + +li { + margin-bottom: 5px; +} diff --git a/list-cookies/cookies.html b/list-cookies/cookies.html new file mode 100644 index 0000000..a15ad76 --- /dev/null +++ b/list-cookies/cookies.html @@ -0,0 +1,19 @@ + + + +
+ + + + + +