Skip to content

Commit

Permalink
Add getElement convenience function
Browse files Browse the repository at this point in the history
  • Loading branch information
proginosko committed Dec 10, 2017
1 parent 0cdcc79 commit 7209b61
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 112 deletions.
18 changes: 10 additions & 8 deletions lockdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
function log(message) { console.log("[LBNG] " + message); }
function warn(message) { console.warn("[LBNG] " + message); }

function getElement(id) { return document.getElementById(id); }

// Initialize form
//
function initializeForm() {
Expand All @@ -15,24 +17,24 @@ function initializeForm() {
function onGot(options) {
let lockdownHours = options["lockdownHours"];
if (lockdownHours > 0) {
document.querySelector("#hours").value = lockdownHours;
getElement("hours").value = lockdownHours;
}

let lockdownMins = options["lockdownMins"];
if (lockdownMins > 0) {
document.querySelector("#mins").value = lockdownMins;
getElement("mins").value = lockdownMins;
}

for (let set = 1; set <= NUM_SETS; set++) {
let lockdown = options[`lockdown${set}`];
if (lockdown) {
document.querySelector(`#blockSet${set}`).checked = lockdown;
getElement(`blockSet${set}`).checked = lockdown;
}

// Append custom set name to check box label (if specified)
let setName = options[`setName${set}`];
if (setName) {
document.querySelector(`#blockSetLabel${set}`).innerText += ` (${setName})`;
getElement(`blockSetLabel${set}`).innerText += ` (${setName})`;
}
}
}
Expand All @@ -48,8 +50,8 @@ function onActivate() {
//log("onActivate");

// Get lockdown duration
let hours = document.querySelector("#hours").value;
let mins = document.querySelector("#mins").value;
let hours = getElement("hours").value;
let mins = getElement("mins").value;
let duration = hours * 3600 + mins * 60;

if (!duration || duration < 0) {
Expand All @@ -63,7 +65,7 @@ function onActivate() {
// Request lockdown for each selected set
let noneSelected = true;
for (let set = 1; set <= NUM_SETS; set++) {
let selected = document.querySelector(`#blockSet${set}`).checked;
let selected = getElement(`blockSet${set}`).checked;
if (selected) {
noneSelected = false;
let message = {
Expand All @@ -86,7 +88,7 @@ function onActivate() {
options["lockdownHours"] = hours;
options["lockdownMins"] = mins;
for (let set = 1; set <= NUM_SETS; set++) {
options[`lockdown${set}`] = document.querySelector(`#blockSet${set}`).checked;
options[`lockdown${set}`] = getElement(`blockSet${set}`).checked;
}
browser.storage.local.set(options);

Expand Down
Loading

0 comments on commit 7209b61

Please sign in to comment.