Skip to content

Commit 70085fb

Browse files
committed
Save lockdown options
1 parent b49b5ca commit 70085fb

File tree

3 files changed

+44
-11
lines changed

3 files changed

+44
-11
lines changed

common.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ function cleanOptions(options) {
7878
if (typeof options[`keywordRE${set}`] !== "string") {
7979
options[`keywordRE${set}`] = "";
8080
}
81+
if (typeof options[`lockdown${set}`] !== "boolean") {
82+
options[`lockdown${set}`] = false;
83+
}
8184

8285
// Update legacy values
8386
if (options[`blockURL${set}`] == LEGACY_DEFAULT_BLOCK_URL) {
@@ -110,6 +113,12 @@ function cleanOptions(options) {
110113
if (typeof options["warnSecs"] !== "string") {
111114
options["warnSecs"] = ""; // default: no warning
112115
}
116+
if (typeof options["lockdownHours"] !== "string") {
117+
options["lockdownHours"] = ""; // default: blank
118+
}
119+
if (typeof options["lockdownMins"] !== "string") {
120+
options["lockdownMins"] = ""; // default: blank
121+
}
113122
}
114123

115124
// Clean time data

lockdown.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
<div>
2525
<input id="hours" type="text" size="2" list="hours-list">
2626
<datalist id="hours-list">
27-
<option value="0">
2827
<option value="1">
2928
<option value="2">
3029
<option value="3">
@@ -36,9 +35,9 @@
3635
<option value="24">
3736
</datalist>
3837
<label for="hours">hour(s)</label>
38+
&nbsp;&nbsp;&nbsp;&nbsp;
3939
<input id="mins" type="text" size="2" list="mins-list">
4040
<datalist id="mins-list">
41-
<option value="0">
4241
<option value="5">
4342
<option value="10">
4443
<option value="15">
@@ -57,9 +56,10 @@
5756
<hr>
5857
<p>
5958
<label>Select the sites to block during the lockdown:</label><br>
60-
<div id="sites">
59+
<div id="blockSets">
6160
<p>
62-
<input id="site1" type="checkbox"><label id="siteLabel1" for="site1">Sites specified in Block Set 1</label>
61+
<input id="blockSet1" type="checkbox">
62+
<label id="blockSetLabel1" for="blockSet1">Sites specified in Block Set 1</label>
6363
</p>
6464
</div>
6565
</p>
@@ -76,7 +76,7 @@
7676

7777
<div id="alerts" style="display: none;">
7878
<div id="alertNoDuration" title="LeechBlock Lockdown">
79-
<p>Please enter the duration of the lockdown.</p>
79+
<p>Please enter a non-zero duration for the lockdown.</p>
8080
</div>
8181
<div id="alertNoSets" title="LeechBlock Lockdown">
8282
<p>Please select the sites to lockdown.</p>

lockdown.js

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,26 @@ function initializeForm() {
1313
browser.storage.local.get().then(onGot, onError);
1414

1515
function onGot(options) {
16+
let lockdownHours = options["lockdownHours"];
17+
if (lockdownHours > 0) {
18+
document.querySelector("#hours").value = lockdownHours;
19+
}
20+
21+
let lockdownMins = options["lockdownMins"];
22+
if (lockdownMins > 0) {
23+
document.querySelector("#mins").value = lockdownMins;
24+
}
25+
1626
for (let set = 1; set <= NUM_SETS; set++) {
27+
let lockdown = options[`lockdown${set}`];
28+
if (lockdown) {
29+
document.querySelector(`#blockSet${set}`).checked = lockdown;
30+
}
31+
1732
// Append custom set name to check box label (if specified)
1833
let setName = options[`setName${set}`];
1934
if (setName) {
20-
document.querySelector(`#siteLabel${set}`).innerText += ` (${setName})`;
35+
document.querySelector(`#blockSetLabel${set}`).innerText += ` (${setName})`;
2136
}
2237
}
2338
}
@@ -37,7 +52,7 @@ function onActivate() {
3752
let mins = document.querySelector("#mins").value;
3853
let duration = hours * 3600 + mins * 60;
3954

40-
if (!duration) {
55+
if (!duration || duration < 0) {
4156
$("#alertNoDuration").dialog("open");
4257
return;
4358
}
@@ -48,7 +63,7 @@ function onActivate() {
4863
// Request lockdown for each selected set
4964
let noneSelected = true;
5065
for (let set = 1; set <= NUM_SETS; set++) {
51-
let selected = document.querySelector(`#site${set}`).checked;
66+
let selected = document.querySelector(`#blockSet${set}`).checked;
5267
if (selected) {
5368
noneSelected = false;
5469
let message = {
@@ -66,6 +81,15 @@ function onActivate() {
6681
return;
6782
}
6883

84+
// Save options for next time
85+
let options = {};
86+
options["lockdownHours"] = hours;
87+
options["lockdownMins"] = mins;
88+
for (let set = 1; set <= NUM_SETS; set++) {
89+
options[`lockdown${set}`] = document.querySelector(`#blockSet${set}`).checked;
90+
}
91+
browser.storage.local.set(options);
92+
6993
// Request tab close
7094
browser.runtime.sendMessage({ type: "close" });
7195
}
@@ -82,12 +106,12 @@ function onCancel() {
82106
/*** STARTUP CODE BEGINS HERE ***/
83107

84108
// Use HTML for first check box to create other check boxes
85-
let siteHTML = $("#sites").html();
109+
let blockSetHTML = $("#blockSets").html();
86110
for (let set = 2; set <= NUM_SETS; set++) {
87-
let nextSiteHTML = siteHTML
111+
let nextSetHTML = blockSetHTML
88112
.replace(/Block Set 1/g, `Block Set ${set}`)
89113
.replace(/(id|for)="(\w+)1"/g, `$1="$2${set}"`);
90-
$("#sites").append(nextSiteHTML);
114+
$("#blockSets").append(nextSetHTML);
91115
}
92116

93117
// Set up JQuery UI widgets

0 commit comments

Comments
 (0)