Skip to content

Commit

Permalink
Add option to show/hide context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
proginosko committed Dec 12, 2017
1 parent f7eba39 commit 2666169
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
12 changes: 7 additions & 5 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,32 @@ function refreshMenus() {

browser.menus.removeAll();

let context = gOptions["contextMenu"] ? "all" : "browser_action";

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

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

browser.menus.create({
type: "separator",
contexts: ["all"]
contexts: [context]
});

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

// Add Site submenu
Expand All @@ -59,7 +61,7 @@ function refreshMenus() {
id: `addSite-${set}`,
parentId: "addSite",
title: title,
contexts: ["all", "tools_menu"]
contexts: [context, "tools_menu"]
});
}
}
Expand Down
3 changes: 3 additions & 0 deletions common.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ function cleanOptions(options) {
if (typeof options["warnSecs"] !== "string") {
options["warnSecs"] = ""; // default: no warning
}
if (typeof options["contextMenu"] !== "boolean") {
options["contextMenu"] = true; // default: enabled
}
if (typeof options["lockdownHours"] !== "string") {
options["lockdownHours"] = ""; // default: blank
}
Expand Down
4 changes: 4 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@
<p>
Display warning message <input id="warnSecs" type="text" size="2" title="Leave blank for no warning"> seconds before site is blocked
</p>
<p>
<input id="contextMenu" type="checkbox">
<label for="contextMenu">Show context menu</label>
</p>
</fieldset>
<fieldset>
<legend>Export / Import</legend>
Expand Down
7 changes: 7 additions & 0 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ function saveOptions() {
options["timerSize"] = getElement("timerSize").value;
options["timerLocation"] = getElement("timerLocation").value;
options["warnSecs"] = getElement("warnSecs").value;
options["contextMenu"] = getElement("contextMenu").checked;

browser.storage.local.set(options);

Expand Down Expand Up @@ -284,6 +285,7 @@ function retrieveOptions() {
getElement("timerSize").value = options["timerSize"];
getElement("timerLocation").value = options["timerLocation"];
getElement("warnSecs").value = options["warnSecs"];
getElement("contextMenu").checked = options["contextMenu"];

confirmAccess(options);
}
Expand Down Expand Up @@ -399,6 +401,7 @@ function exportOptions() {
options["timerSize"] = getElement("timerSize").value;
options["timerLocation"] = getElement("timerLocation").value;
options["warnSecs"] = getElement("warnSecs").value;
options["contextMenu"] = getElement("contextMenu").checked;

// Convert options to text lines
let lines = [];
Expand Down Expand Up @@ -580,6 +583,7 @@ function importOptions() {
let timerSize = options["timerSize"];
let timerLocation = options["timerLocation"];
let warnSecs = options["warnSecs"];
let contextMenu = options["contextMenu"];
if (oa != undefined) {
getElement("optionsAccess").value = oa;
}
Expand All @@ -601,6 +605,9 @@ function importOptions() {
if (warnSecs != undefined) {
getElement("warnSecs").value = warnSecs;
}
if (contextMenu != undefined) {
getElement("contextMenu").checked = contextMenu;
}
}
}

Expand Down

0 comments on commit 2666169

Please sign in to comment.