Skip to content

Commit

Permalink
Add option to show/hide tools menu
Browse files Browse the repository at this point in the history
  • Loading branch information
proginosko committed Feb 14, 2018
1 parent cccfc52 commit faf0774
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
13 changes: 7 additions & 6 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,39 @@ function refreshMenus() {
browser.menus.removeAll();

let context = gOptions["contextMenu"] ? "all" : "browser_action";
let contexts = gOptions["toolsMenu"] ? [context, "tools_menu"] : [context];

// Options
browser.menus.create({
id: "options",
title: "Options",
contexts: [context, "tools_menu"]
contexts: contexts
});

// Lockdown
browser.menus.create({
id: "lockdown",
title: "Lockdown",
contexts: [context, "tools_menu"]
contexts: contexts
});

// Statistics
browser.menus.create({
id: "stats",
title: "Statistics",
contexts: [context, "tools_menu"]
contexts: contexts
});

browser.menus.create({
type: "separator",
contexts: [context]
contexts: [context] // never in tools menu
});

// Add Site
browser.menus.create({
id: "addSite",
title: "Add Site",
contexts: [context]
contexts: [context] // never in tools menu
});

// Add Site submenu
Expand All @@ -68,7 +69,7 @@ function refreshMenus() {
id: `addSite-${set}`,
parentId: "addSite",
title: title,
contexts: [context, "tools_menu"]
contexts: contexts
});
}
}
Expand Down
5 changes: 4 additions & 1 deletion common.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,14 @@ function cleanOptions(options) {
options["warnSecs"] = ""; // default: no warning
}
if (typeof options["warnImmediate"] !== "boolean") {
options["warnImmediate"] = true; // default: warn only when for immediate block
options["warnImmediate"] = true; // default: warn only for immediate block
}
if (typeof options["contextMenu"] !== "boolean") {
options["contextMenu"] = true; // default: enabled
}
if (typeof options["toolsMenu"] !== "boolean") {
options["toolsMenu"] = true; // default: enabled
}
if (typeof options["matchSubdomains"] !== "boolean") {
options["matchSubdomains"] = false; // default: disabled for backwards compatibility
}
Expand Down
3 changes: 3 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@
<p>
<input id="contextMenu" type="checkbox">
<label for="contextMenu">Show context menu</label>
&nbsp;&nbsp;&nbsp;&nbsp;
<input id="toolsMenu" type="checkbox">
<label for="toolsMenu">Show tools menu</label>
</p>
<p>
<input id="matchSubdomains" type="checkbox">
Expand Down
7 changes: 7 additions & 0 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ function saveOptions() {
options["warnSecs"] = getElement("warnSecs").value;
options["warnImmediate"] = getElement("warnImmediate").checked;
options["contextMenu"] = getElement("contextMenu").checked;
options["toolsMenu"] = getElement("toolsMenu").checked;
options["matchSubdomains"] = getElement("matchSubdomains").checked;

for (let set = 1; set <= NUM_SETS; set++) {
Expand Down Expand Up @@ -305,6 +306,7 @@ function retrieveOptions() {
getElement("warnSecs").value = options["warnSecs"];
getElement("warnImmediate").checked = options["warnImmediate"];
getElement("contextMenu").checked = options["contextMenu"];
getElement("toolsMenu").checked = options["toolsMenu"];
getElement("matchSubdomains").checked = options["matchSubdomains"];

confirmAccess(options);
Expand Down Expand Up @@ -430,6 +432,7 @@ function exportOptions() {
options["warnSecs"] = getElement("warnSecs").value;
options["warnImmediate"] = getElement("warnImmediate").checked;
options["contextMenu"] = getElement("contextMenu").checked;
options["toolsMenu"] = getElement("toolsMenu").checked;
options["matchSubdomins"] = getElement("matchSubdomains").checked;

// Convert options to text lines
Expand Down Expand Up @@ -643,6 +646,7 @@ function importOptions() {
let warnSecs = options["warnSecs"];
let warnImmediate = options["warnImmediate"];
let contextMenu = options["contextMenu"];
let toolsMenu = options["toolsMenu"];
let matchSubdomains = options["matchSubdomains"]
if (oa != undefined) {
getElement("optionsAccess").value = oa;
Expand Down Expand Up @@ -674,6 +678,9 @@ function importOptions() {
if (contextMenu != undefined) {
getElement("contextMenu").checked = contextMenu;
}
if (toolsMenu != undefined) {
getElement("toolsMenu").checked = toolsMenu;
}
if (matchSubdomains != undefined) {
getElement("matchSubdomains").checked = matchSubdomains;
}
Expand Down

0 comments on commit faf0774

Please sign in to comment.