Skip to content

Commit 482d4eb

Browse files
committed
Minor code cleanup.
1 parent d3beec3 commit 482d4eb

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

src/bg/main.js

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828
});
2929
}
3030
}
31-
let popupURL = browser.runtime.getURL("/ui/popup.html");
32-
let popupFor = tabId => `${popupURL}#tab${tabId}`;
31+
const popupURL = browser.runtime.getURL("/ui/popup.html");
32+
const popupFor = tabId => `${popupURL}#tab${tabId}`;
3333

34-
let ctxMenuId = "noscript-ctx-menu";
34+
const ctxMenuId = "noscript-ctx-menu";
3535
let menuShowing = false;
3636
const menuUpdater = async (tabId) => {
3737
if (!menuShowing) return;
3838
try {
39-
let badgeText = await browser.browserAction.getBadgeText({tabId});
39+
const badgeText = await browser.browserAction.getBadgeText({tabId});
4040
let title = "NoScript";
4141
if (badgeText) title = `${title} [${badgeText}]`;
4242
await browser.contextMenus.update(ctxMenuId, {title});
@@ -46,7 +46,7 @@
4646
}
4747
async function toggleCtxMenuItem(show = ns.local.showCtxMenuItem) {
4848
if (!("contextMenus" in browser)) return;
49-
let id = ctxMenuId;
49+
const id = ctxMenuId;
5050
try {
5151
await browser.contextMenus.remove(id);
5252
} catch (e) {}
@@ -68,7 +68,7 @@
6868
await Defaults.init();
6969

7070
if (!ns.policy) { // it could have been already retrieved by LifeCycle
71-
let policyData = (await Storage.get("sync", "policy")).policy;
71+
const policyData = (await Storage.get("sync", "policy")).policy;
7272
if (policyData && policyData.DEFAULT) {
7373
ns.policy = new Policy(policyData);
7474
if (ns.local.enforceOnRestart && !ns.policy.enforced) {
@@ -81,7 +81,7 @@
8181
}
8282
}
8383

84-
let {isTorBrowser} = ns.local;
84+
const {isTorBrowser} = ns.local;
8585
Sites.onionSecure = isTorBrowser;
8686

8787
if (!isTorBrowser) {
@@ -105,18 +105,18 @@
105105
await include("/bg/popupHandler.js");
106106
};
107107

108-
let Commands = {
108+
const Commands = {
109109
openPageUI() {
110110
messageHandler.openStandalonePopup();
111111
},
112112

113113
async toggleEnforcementForTab() {
114-
let [tab] = (await browser.tabs.query({
114+
const [tab] = (await browser.tabs.query({
115115
currentWindow: true,
116116
active: true
117117
}));
118118
if (tab) {
119-
let toggle = ns.unrestrictedTabs.has(tab.id) ? "delete" : "add";
119+
const toggle = ns.unrestrictedTabs.has(tab.id) ? "delete" : "add";
120120
ns.unrestrictedTabs[toggle](tab.id);
121121
browser.tabs.reload(tab.id);
122122
}
@@ -141,7 +141,7 @@
141141
}
142142

143143
// wiring main UI
144-
let ba = browser.browserAction;
144+
const ba = browser.browserAction;
145145
if ("setIcon" in ba) {
146146
//desktop or Fenix
147147
ba.setPopup({
@@ -163,7 +163,7 @@
163163
}
164164
}
165165

166-
let messageHandler = {
166+
const messageHandler = {
167167
async updateSettings(settings, sender) {
168168
if (settings.command === "tg-forget") {
169169
TabGuard.forget();
@@ -176,10 +176,9 @@
176176
async broadcastSettings({
177177
tabId = -1
178178
}) {
179-
let policy = ns.policy.dry(true);
180-
let seen = tabId !== -1 ? await ns.collectSeen(tabId) : null;
181-
let xssUserChoices = await XSS.getUserChoices();
182-
let anonymyzedTabInfo =
179+
const policy = ns.policy.dry(true);
180+
const seen = tabId !== -1 ? await ns.collectSeen(tabId) : null;
181+
const xssUserChoices = await XSS.getUserChoices();
183182
await Messages.send("settings", {
184183
policy,
185184
seen,
@@ -216,8 +215,8 @@
216215
log("No tab found to open the UI for");
217216
return;
218217
}
219-
let win = await browser.windows.get(tab.windowId);
220-
let width = 610, height = 400;
218+
const win = await browser.windows.get(tab.windowId);
219+
const width = 610, height = 400;
221220
browser.windows.create({
222221
url: popupFor(tab.id),
223222
width,
@@ -296,9 +295,9 @@
296295
},
297296

298297
computeChildPolicy({url, contextUrl}, sender) {
299-
let {tab, frameId} = sender;
298+
const {tab, frameId} = sender;
300299
let policy = ns.policy;
301-
let {isTorBrowser} = ns.local;
300+
const {isTorBrowser} = ns.local;
302301
if (!policy) {
303302
console.log("Policy is null, initializing: %o, sending fallback.", ns.initializing);
304303
return {
@@ -310,7 +309,7 @@
310309
};
311310
}
312311

313-
let tabId = tab ? tab.id : -1;
312+
const tabId = tab ? tab.id : -1;
314313
let topUrl;
315314
if (frameId === 0) {
316315
topUrl = url;
@@ -373,8 +372,8 @@
373372

374373
async testIC(callbackOrUrl) {
375374
await include("xss/InjectionChecker.js");
376-
let IC = await XSS.InjectionChecker;
377-
let ic = new IC();
375+
const IC = await XSS.InjectionChecker;
376+
const ic = new IC();
378377
ic.logEnabled = true;
379378
return (typeof callbackOrUrl === "function")
380379
? await callbackOrUrl(ic)
@@ -392,11 +391,11 @@
392391
},
393392

394393
openOptionsPage({tab, focus, hilite}) {
395-
let url = new URL(browser.runtime.getManifest().options_ui.page);
394+
const url = new URL(browser.runtime.getManifest().options_ui.page);
396395
if (tab !== undefined) {
397396
url.hash += `;tab-main-tabs=${tab}`;
398397
}
399-
let search = new URLSearchParams(url.search);
398+
const search = new URLSearchParams(url.search);
400399
if (focus) search.set("focus", focus);
401400
if (hilite) search.set("hilite", hilite);
402401
url.search = search;
@@ -405,7 +404,7 @@
405404

406405
async save(obj) {
407406
if (obj && obj.storage) {
408-
let toBeSaved = {
407+
const toBeSaved = {
409408
[obj.storage]: obj
410409
};
411410
await Storage.set(obj.storage, toBeSaved);
@@ -416,7 +415,7 @@
416415
async collectSeen(tabId) {
417416
await this.initializing;
418417
try {
419-
let seen = Array.from(await Messages.send("collect", {uuid: ns.local.uuid}, {tabId, frameId: 0}));
418+
const seen = Array.from(await Messages.send("collect", {uuid: ns.local.uuid}, {tabId, frameId: 0}));
420419
debug("Collected seen", seen); // DEV_ONLY
421420
return seen;
422421
} catch (e) {

0 commit comments

Comments
 (0)