Minor code cleanup.
This commit is contained in:
parent
d3beec3440
commit
482d4eb91d
|
@ -28,15 +28,15 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let popupURL = browser.runtime.getURL("/ui/popup.html");
|
const popupURL = browser.runtime.getURL("/ui/popup.html");
|
||||||
let popupFor = tabId => `${popupURL}#tab${tabId}`;
|
const popupFor = tabId => `${popupURL}#tab${tabId}`;
|
||||||
|
|
||||||
let ctxMenuId = "noscript-ctx-menu";
|
const ctxMenuId = "noscript-ctx-menu";
|
||||||
let menuShowing = false;
|
let menuShowing = false;
|
||||||
const menuUpdater = async (tabId) => {
|
const menuUpdater = async (tabId) => {
|
||||||
if (!menuShowing) return;
|
if (!menuShowing) return;
|
||||||
try {
|
try {
|
||||||
let badgeText = await browser.browserAction.getBadgeText({tabId});
|
const badgeText = await browser.browserAction.getBadgeText({tabId});
|
||||||
let title = "NoScript";
|
let title = "NoScript";
|
||||||
if (badgeText) title = `${title} [${badgeText}]`;
|
if (badgeText) title = `${title} [${badgeText}]`;
|
||||||
await browser.contextMenus.update(ctxMenuId, {title});
|
await browser.contextMenus.update(ctxMenuId, {title});
|
||||||
|
@ -46,7 +46,7 @@
|
||||||
}
|
}
|
||||||
async function toggleCtxMenuItem(show = ns.local.showCtxMenuItem) {
|
async function toggleCtxMenuItem(show = ns.local.showCtxMenuItem) {
|
||||||
if (!("contextMenus" in browser)) return;
|
if (!("contextMenus" in browser)) return;
|
||||||
let id = ctxMenuId;
|
const id = ctxMenuId;
|
||||||
try {
|
try {
|
||||||
await browser.contextMenus.remove(id);
|
await browser.contextMenus.remove(id);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
@ -68,7 +68,7 @@
|
||||||
await Defaults.init();
|
await Defaults.init();
|
||||||
|
|
||||||
if (!ns.policy) { // it could have been already retrieved by LifeCycle
|
if (!ns.policy) { // it could have been already retrieved by LifeCycle
|
||||||
let policyData = (await Storage.get("sync", "policy")).policy;
|
const policyData = (await Storage.get("sync", "policy")).policy;
|
||||||
if (policyData && policyData.DEFAULT) {
|
if (policyData && policyData.DEFAULT) {
|
||||||
ns.policy = new Policy(policyData);
|
ns.policy = new Policy(policyData);
|
||||||
if (ns.local.enforceOnRestart && !ns.policy.enforced) {
|
if (ns.local.enforceOnRestart && !ns.policy.enforced) {
|
||||||
|
@ -81,7 +81,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let {isTorBrowser} = ns.local;
|
const {isTorBrowser} = ns.local;
|
||||||
Sites.onionSecure = isTorBrowser;
|
Sites.onionSecure = isTorBrowser;
|
||||||
|
|
||||||
if (!isTorBrowser) {
|
if (!isTorBrowser) {
|
||||||
|
@ -105,18 +105,18 @@
|
||||||
await include("/bg/popupHandler.js");
|
await include("/bg/popupHandler.js");
|
||||||
};
|
};
|
||||||
|
|
||||||
let Commands = {
|
const Commands = {
|
||||||
openPageUI() {
|
openPageUI() {
|
||||||
messageHandler.openStandalonePopup();
|
messageHandler.openStandalonePopup();
|
||||||
},
|
},
|
||||||
|
|
||||||
async toggleEnforcementForTab() {
|
async toggleEnforcementForTab() {
|
||||||
let [tab] = (await browser.tabs.query({
|
const [tab] = (await browser.tabs.query({
|
||||||
currentWindow: true,
|
currentWindow: true,
|
||||||
active: true
|
active: true
|
||||||
}));
|
}));
|
||||||
if (tab) {
|
if (tab) {
|
||||||
let toggle = ns.unrestrictedTabs.has(tab.id) ? "delete" : "add";
|
const toggle = ns.unrestrictedTabs.has(tab.id) ? "delete" : "add";
|
||||||
ns.unrestrictedTabs[toggle](tab.id);
|
ns.unrestrictedTabs[toggle](tab.id);
|
||||||
browser.tabs.reload(tab.id);
|
browser.tabs.reload(tab.id);
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// wiring main UI
|
// wiring main UI
|
||||||
let ba = browser.browserAction;
|
const ba = browser.browserAction;
|
||||||
if ("setIcon" in ba) {
|
if ("setIcon" in ba) {
|
||||||
//desktop or Fenix
|
//desktop or Fenix
|
||||||
ba.setPopup({
|
ba.setPopup({
|
||||||
|
@ -163,7 +163,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let messageHandler = {
|
const messageHandler = {
|
||||||
async updateSettings(settings, sender) {
|
async updateSettings(settings, sender) {
|
||||||
if (settings.command === "tg-forget") {
|
if (settings.command === "tg-forget") {
|
||||||
TabGuard.forget();
|
TabGuard.forget();
|
||||||
|
@ -176,10 +176,9 @@
|
||||||
async broadcastSettings({
|
async broadcastSettings({
|
||||||
tabId = -1
|
tabId = -1
|
||||||
}) {
|
}) {
|
||||||
let policy = ns.policy.dry(true);
|
const policy = ns.policy.dry(true);
|
||||||
let seen = tabId !== -1 ? await ns.collectSeen(tabId) : null;
|
const seen = tabId !== -1 ? await ns.collectSeen(tabId) : null;
|
||||||
let xssUserChoices = await XSS.getUserChoices();
|
const xssUserChoices = await XSS.getUserChoices();
|
||||||
let anonymyzedTabInfo =
|
|
||||||
await Messages.send("settings", {
|
await Messages.send("settings", {
|
||||||
policy,
|
policy,
|
||||||
seen,
|
seen,
|
||||||
|
@ -216,8 +215,8 @@
|
||||||
log("No tab found to open the UI for");
|
log("No tab found to open the UI for");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let win = await browser.windows.get(tab.windowId);
|
const win = await browser.windows.get(tab.windowId);
|
||||||
let width = 610, height = 400;
|
const width = 610, height = 400;
|
||||||
browser.windows.create({
|
browser.windows.create({
|
||||||
url: popupFor(tab.id),
|
url: popupFor(tab.id),
|
||||||
width,
|
width,
|
||||||
|
@ -296,9 +295,9 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
computeChildPolicy({url, contextUrl}, sender) {
|
computeChildPolicy({url, contextUrl}, sender) {
|
||||||
let {tab, frameId} = sender;
|
const {tab, frameId} = sender;
|
||||||
let policy = ns.policy;
|
let policy = ns.policy;
|
||||||
let {isTorBrowser} = ns.local;
|
const {isTorBrowser} = ns.local;
|
||||||
if (!policy) {
|
if (!policy) {
|
||||||
console.log("Policy is null, initializing: %o, sending fallback.", ns.initializing);
|
console.log("Policy is null, initializing: %o, sending fallback.", ns.initializing);
|
||||||
return {
|
return {
|
||||||
|
@ -310,7 +309,7 @@
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let tabId = tab ? tab.id : -1;
|
const tabId = tab ? tab.id : -1;
|
||||||
let topUrl;
|
let topUrl;
|
||||||
if (frameId === 0) {
|
if (frameId === 0) {
|
||||||
topUrl = url;
|
topUrl = url;
|
||||||
|
@ -373,8 +372,8 @@
|
||||||
|
|
||||||
async testIC(callbackOrUrl) {
|
async testIC(callbackOrUrl) {
|
||||||
await include("xss/InjectionChecker.js");
|
await include("xss/InjectionChecker.js");
|
||||||
let IC = await XSS.InjectionChecker;
|
const IC = await XSS.InjectionChecker;
|
||||||
let ic = new IC();
|
const ic = new IC();
|
||||||
ic.logEnabled = true;
|
ic.logEnabled = true;
|
||||||
return (typeof callbackOrUrl === "function")
|
return (typeof callbackOrUrl === "function")
|
||||||
? await callbackOrUrl(ic)
|
? await callbackOrUrl(ic)
|
||||||
|
@ -392,11 +391,11 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
openOptionsPage({tab, focus, hilite}) {
|
openOptionsPage({tab, focus, hilite}) {
|
||||||
let url = new URL(browser.runtime.getManifest().options_ui.page);
|
const url = new URL(browser.runtime.getManifest().options_ui.page);
|
||||||
if (tab !== undefined) {
|
if (tab !== undefined) {
|
||||||
url.hash += `;tab-main-tabs=${tab}`;
|
url.hash += `;tab-main-tabs=${tab}`;
|
||||||
}
|
}
|
||||||
let search = new URLSearchParams(url.search);
|
const search = new URLSearchParams(url.search);
|
||||||
if (focus) search.set("focus", focus);
|
if (focus) search.set("focus", focus);
|
||||||
if (hilite) search.set("hilite", hilite);
|
if (hilite) search.set("hilite", hilite);
|
||||||
url.search = search;
|
url.search = search;
|
||||||
|
@ -405,7 +404,7 @@
|
||||||
|
|
||||||
async save(obj) {
|
async save(obj) {
|
||||||
if (obj && obj.storage) {
|
if (obj && obj.storage) {
|
||||||
let toBeSaved = {
|
const toBeSaved = {
|
||||||
[obj.storage]: obj
|
[obj.storage]: obj
|
||||||
};
|
};
|
||||||
await Storage.set(obj.storage, toBeSaved);
|
await Storage.set(obj.storage, toBeSaved);
|
||||||
|
@ -416,7 +415,7 @@
|
||||||
async collectSeen(tabId) {
|
async collectSeen(tabId) {
|
||||||
await this.initializing;
|
await this.initializing;
|
||||||
try {
|
try {
|
||||||
let seen = Array.from(await Messages.send("collect", {uuid: ns.local.uuid}, {tabId, frameId: 0}));
|
const seen = Array.from(await Messages.send("collect", {uuid: ns.local.uuid}, {tabId, frameId: 0}));
|
||||||
debug("Collected seen", seen); // DEV_ONLY
|
debug("Collected seen", seen); // DEV_ONLY
|
||||||
return seen;
|
return seen;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in New Issue