Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace var with let in examples #484

Merged
merged 2 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion annotate-page/sidebar/panel.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var myWindowId;
let myWindowId;
const contentBox = document.querySelector("#content");

/*
Expand Down
4 changes: 2 additions & 2 deletions apply-css/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function toggleCSS(tab) {
}
}

var gettingTitle = browser.pageAction.getTitle({tabId: tab.id});
let gettingTitle = browser.pageAction.getTitle({tabId: tab.id});
gettingTitle.then(gotTitle);
}

Expand Down Expand Up @@ -49,7 +49,7 @@ function initializePageAction(tab) {
/*
When first loaded, initialize the page action for all tabs.
*/
var gettingAllTabs = browser.tabs.query({});
let gettingAllTabs = browser.tabs.query({});
gettingAllTabs.then((tabs) => {
for (let tab of tabs) {
initializePageAction(tab);
Expand Down
12 changes: 6 additions & 6 deletions bookmark-it/background.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var currentTab;
var currentBookmark;
let currentTab;
let currentBookmark;

/*
* Updates the browserAction icon to reflect whether the current page
Expand Down Expand Up @@ -42,8 +42,8 @@ browser.browserAction.onClicked.addListener(toggleBookmark);
function updateActiveTab(tabs) {

function isSupportedProtocol(urlString) {
var supportedProtocols = ["https:", "http:", "ftp:", "file:"];
var url = document.createElement('a');
let supportedProtocols = ["https:", "http:", "ftp:", "file:"];
let url = document.createElement('a');
url.href = urlString;
return supportedProtocols.indexOf(url.protocol) != -1;
}
Expand All @@ -52,7 +52,7 @@ function updateActiveTab(tabs) {
if (tabs[0]) {
currentTab = tabs[0];
if (isSupportedProtocol(currentTab.url)) {
var searching = browser.bookmarks.search({url: currentTab.url});
let searching = browser.bookmarks.search({url: currentTab.url});
searching.then((bookmarks) => {
currentBookmark = bookmarks[0];
updateIcon();
Expand All @@ -63,7 +63,7 @@ function updateActiveTab(tabs) {
}
}

var gettingActiveTab = browser.tabs.query({active: true, currentWindow: true});
let gettingActiveTab = browser.tabs.query({active: true, currentWindow: true});
gettingActiveTab.then(updateTab);
}

Expand Down
12 changes: 6 additions & 6 deletions chill-out/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ in the console, but the alarm will still go off after 6 seconds
* if you package the extension and install it, then the alarm will go off after
a minute.
*/
var DELAY = 0.1;
var CATGIFS = "https://giphy.com/explore/cat";
let DELAY = 0.1;
let CATGIFS = "https://giphy.com/explore/cat";

/*
Restart alarm for the currently active tab, whenever background.js is run.
*/
var gettingActiveTab = browser.tabs.query({active: true, currentWindow: true});
let gettingActiveTab = browser.tabs.query({active: true, currentWindow: true});
gettingActiveTab.then((tabs) => {
restartAlarm(tabs[0].id);
});
Expand All @@ -26,7 +26,7 @@ browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (!changeInfo.url) {
return;
}
var gettingActiveTab = browser.tabs.query({active: true, currentWindow: true});
let gettingActiveTab = browser.tabs.query({active: true, currentWindow: true});
gettingActiveTab.then((tabs) => {
if (tabId == tabs[0].id) {
restartAlarm(tabId);
Expand All @@ -48,7 +48,7 @@ then set a new alarm for the given tab.
function restartAlarm(tabId) {
browser.pageAction.hide(tabId);
browser.alarms.clearAll();
var gettingTab = browser.tabs.get(tabId);
let gettingTab = browser.tabs.get(tabId);
gettingTab.then((tab) => {
if (tab.url != CATGIFS) {
browser.alarms.create("", {delayInMinutes: DELAY});
Expand All @@ -60,7 +60,7 @@ function restartAlarm(tabId) {
On alarm, show the page action.
*/
browser.alarms.onAlarm.addListener((alarm) => {
var gettingActiveTab = browser.tabs.query({active: true, currentWindow: true});
let gettingActiveTab = browser.tabs.query({active: true, currentWindow: true});
gettingActiveTab.then((tabs) => {
browser.pageAction.show(tabs[0].id);
});
Expand Down
2 changes: 1 addition & 1 deletion content-script-register/background.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var registered = null;
let registered = null;

async function registerScript(message) {

Expand Down
2 changes: 1 addition & 1 deletion contextual-identities/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function createOptions(node, identity) {
}
}

var div = document.getElementById('identity-list');
let div = document.getElementById('identity-list');

if (browser.contextualIdentities === undefined) {
div.innerText = 'browser.contextualIdentities not available. Check that the privacy.userContext.enabled pref is set to true, and reload the add-on.';
Expand Down
4 changes: 2 additions & 2 deletions cookie-bg-picker/background_scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ function getActiveTab() {
function cookieUpdate() {
getActiveTab().then((tabs) => {
// get any previously set cookie for the current tab
var gettingCookies = browser.cookies.get({
let gettingCookies = browser.cookies.get({
url: tabs[0].url,
name: "bgpicker"
});
gettingCookies.then((cookie) => {
if (cookie) {
var cookieVal = JSON.parse(cookie.value);
let cookieVal = JSON.parse(cookie.value);
browser.tabs.sendMessage(tabs[0].id, {image: cookieVal.image});
browser.tabs.sendMessage(tabs[0].id, {color: cookieVal.color});
}
Expand Down
4 changes: 2 additions & 2 deletions cookie-bg-picker/content_scripts/updatebg.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
browser.runtime.onMessage.addListener(updateBg);

function updateBg(request, sender, sendResponse) {
var html = document.querySelector('html');
var body = document.querySelector('body');
let html = document.querySelector('html');
let body = document.querySelector('body');
if (request.image) {
html.style.backgroundImage = 'url(' + request.image + ')';
body.style.backgroundImage = 'url(' + request.image + ')';
Expand Down
20 changes: 10 additions & 10 deletions cookie-bg-picker/popup/bgpicker.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* initialise variables */

var bgBtns = document.querySelectorAll('.bg-container button');
var colorPick = document.querySelector('input');
var reset = document.querySelector('.color-reset button');
var cookieVal = { image : '',
let bgBtns = document.querySelectorAll('.bg-container button');
let colorPick = document.querySelector('input');
let reset = document.querySelector('.color-reset button');
let cookieVal = { image : '',
color : '' };

function getActiveTab() {
Expand All @@ -13,15 +13,15 @@ function getActiveTab() {
/* apply backgrounds to buttons */
/* add listener so that when clicked, button applies background to page HTML */

for(var i = 0; i < bgBtns.length; i++) {
var imgName = bgBtns[i].getAttribute('class');
var bgImg = 'url(\'images/' + imgName + '.png\')';
for(let i = 0; i < bgBtns.length; i++) {
let imgName = bgBtns[i].getAttribute('class');
let bgImg = 'url(\'images/' + imgName + '.png\')';
bgBtns[i].style.backgroundImage = bgImg;

bgBtns[i].onclick = function(e) {
getActiveTab().then((tabs) => {
var imgName = e.target.getAttribute('class');
var fullURL = browser.extension.getURL('popup/images/'+ imgName + '.png');
let imgName = e.target.getAttribute('class');
let fullURL = browser.extension.getURL('popup/images/'+ imgName + '.png');
browser.tabs.sendMessage(tabs[0].id, {image: fullURL});

cookieVal.image = fullURL;
Expand All @@ -38,7 +38,7 @@ for(var i = 0; i < bgBtns.length; i++) {

colorPick.onchange = function(e) {
getActiveTab().then((tabs) => {
var currColor = e.target.value;
let currColor = e.target.value;
browser.tabs.sendMessage(tabs[0].id, {color: currColor});

cookieVal.color = currColor;
Expand Down
2 changes: 1 addition & 1 deletion dynamic-theme/background.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var currentTheme = '';
let currentTheme = '';

const themes = {
'day': {
Expand Down
2 changes: 1 addition & 1 deletion eslint-example/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/* global getUsefulContents */
function start() {
getUsefulContents(data => {
var display = document.getElementById('display');
let display = document.getElementById('display');

display.innerHTML = data;
});
Expand Down
2 changes: 1 addition & 1 deletion export-helpers/content_scripts/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exportFunction(notify, window, {defineAs:'notify'});
* Because the object contains functions, the cloneInto call must include
* the `cloneFunctions` option.
*/
var messenger = {
let messenger = {
notify: function(message) {
browser.runtime.sendMessage({content: "Object method call: " + message});
}
Expand Down
4 changes: 2 additions & 2 deletions favourite-colour/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ function saveOptions(e) {
}

function restoreOptions() {
var storageItem = browser.storage.managed.get('colour');
let storageItem = browser.storage.managed.get('colour');
storageItem.then((res) => {
document.querySelector("#managed-colour").innerText = res.colour;
});

var gettingItem = browser.storage.sync.get('colour');
let gettingItem = browser.storage.sync.get('colour');
gettingItem.then((res) => {
document.querySelector("#colour").value = res.colour || 'Firefox red';
});
Expand Down
2 changes: 1 addition & 1 deletion forget-it/background.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Default settings. If there is nothing in storage, use these values.
*/
var defaultSettings = {
let defaultSettings = {
since: "hour",
dataTypes: ["history", "downloads"]
};
Expand Down
24 changes: 12 additions & 12 deletions history-deleter/history.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// A useful way to extract the domain from a url.
function get_hostname(url) {
var a = document.createElement('a');
let a = document.createElement('a');
a.href = url;
set_domain(a.hostname);
return a.hostname;
Expand All @@ -14,7 +14,7 @@ function set_domain(domain) {
}

function no_history(hostname) {
var history_text = document.getElementById('history');
let history_text = document.getElementById('history');
while(history_text.firstChild)
history_text.removeChild(history_text.firstChild);
history_text.textContent = `No history for ${hostname}.`;
Expand All @@ -27,22 +27,22 @@ function getActiveTab() {
// When the page is loaded find the current tab and then use that to query
// the history.
getActiveTab().then((tabs) => {
var list = document.getElementById('history');
var hostname = get_hostname(tabs[0].url);
let list = document.getElementById('history');
let hostname = get_hostname(tabs[0].url);

// 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});
let 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);
for (let k in results) {
let history = results[k];
let li = document.createElement('p');
let a = document.createElement('a');
let url = document.createTextNode(history.url);
a.href = history.url;
a.target = '_blank';
a.appendChild(url);
Expand All @@ -55,15 +55,15 @@ getActiveTab().then((tabs) => {

function clearAll(e) {
getActiveTab().then((tabs) => {
var hostname = get_hostname(tabs[0].url);
let hostname = get_hostname(tabs[0].url);
if (!hostname) {
// Don't try and delete history when there's no hostname.
return;
}

// 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})
let searchingHistory = browser.history.search({text: hostname})
searchingHistory.then((results) => {
for (let k in results) {
browser.history.deleteUrl({url: results[k].url});
Expand Down
10 changes: 5 additions & 5 deletions latest-download/popup/latest_download.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

var latestDownloadId;
let latestDownloadId;

/*
Callback from getFileIcon.
Initialize the displayed icon.
*/
function updateIconUrl(iconUrl) {
var downloadIcon = document.querySelector("#icon");
let downloadIcon = document.querySelector("#icon");
downloadIcon.setAttribute("src", iconUrl);
}

Expand All @@ -22,10 +22,10 @@ If there was a download item,
If there wasn't a download item, disable the "open" and "remove" buttons.
*/
function initializeLatestDownload(downloadItems) {
var downloadUrl = document.querySelector("#url");
let downloadUrl = document.querySelector("#url");
if (downloadItems.length > 0) {
latestDownloadId = downloadItems[0].id;
var gettingIconUrl = browser.downloads.getFileIcon(latestDownloadId);
let gettingIconUrl = browser.downloads.getFileIcon(latestDownloadId);
gettingIconUrl.then(updateIconUrl, onError);
downloadUrl.textContent = downloadItems[0].url;
document.querySelector("#open").classList.remove("disabled");
Expand All @@ -40,7 +40,7 @@ function initializeLatestDownload(downloadItems) {
/*
Search for the most recent download, and pass it to initializeLatestDownload()
*/
var searching = browser.downloads.search({
let searching = browser.downloads.search({
limit: 1,
orderBy: ["-startTime"]
});
Expand Down
8 changes: 4 additions & 4 deletions list-cookies/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ function showCookiesForTab(tabs) {
let tab = tabs.pop();

//get all cookies in the domain
var gettingAllCookies = browser.cookies.getAll({url: tab.url});
let gettingAllCookies = browser.cookies.getAll({url: tab.url});
gettingAllCookies.then((cookies) => {

//set the header of the panel
var activeTabUrl = document.getElementById('header-title');
var text = document.createTextNode("Cookies at: "+tab.title);
var cookieList = document.getElementById('cookie-list');
let activeTabUrl = document.getElementById('header-title');
let text = document.createTextNode("Cookies at: "+tab.title);
let cookieList = document.getElementById('cookie-list');
activeTabUrl.appendChild(text);

if (cookies.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion menu-accesskey-visible/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function detectAccessKeyMenuFeature() {
// on parameter properties.
}

var IS_ACCESS_KEY_SUPPORTED = detectAccessKeyMenuFeature();
let IS_ACCESS_KEY_SUPPORTED = detectAccessKeyMenuFeature();

function formatMenuLabel(menuLabel) {
if (!IS_ACCESS_KEY_SUPPORTED) {
Expand Down
8 changes: 4 additions & 4 deletions menu-demo/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ browser.menus.create({
contexts: ["all"]
}, onCreated);

var checkedState = true;
let checkedState = true;

browser.menus.create({
id: "check-uncheck",
Expand Down Expand Up @@ -106,8 +106,8 @@ Set a colored border on the document in the given tab.
Note that this only work on normal web pages, not special pages
like about:debugging.
*/
var blue = 'document.body.style.border = "5px solid blue"';
var green = 'document.body.style.border = "5px solid green"';
let blue = 'document.body.style.border = "5px solid blue"';
let green = 'document.body.style.border = "5px solid green"';

function borderify(tabId, color) {
browser.tabs.executeScript(tabId, {
Expand Down Expand Up @@ -146,7 +146,7 @@ browser.menus.onClicked.addListener((info, tab) => {
console.log(info.selectionText);
break;
case "remove-me":
var removing = browser.menus.remove(info.menuItemId);
let removing = browser.menus.remove(info.menuItemId);
removing.then(onRemoved, onError);
break;
case "bluify":
Expand Down
Loading