Skip to content

Commit

Permalink
Allow users to wait for up to 5 minutes, and humanize time.
Browse files Browse the repository at this point in the history
  • Loading branch information
mscavnicky committed Mar 8, 2016
1 parent 677293b commit 1c9ab8b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
21 changes: 17 additions & 4 deletions js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ function restoreOptions() {
$('blocklist').value = items.blocklist;

// Setting value does not trigger click oninput event.
$('waitTimeOutput').value = items.waitTime;
$('blockTimeOutput').value = items.blockTime;
$('waitTimeOutput').value = humanizeTime(items.waitTime);
$('blockTimeOutput').value = humanizeTime(items.blockTime * 60);
});
}

Expand All @@ -28,12 +28,25 @@ function $(id) {
return document.getElementById(id);
}

function humanizeTime(seconds) {
var str = "";
if (seconds > 59) {
str += Math.floor(seconds / 60) + " minutes ";
seconds = seconds % 60;
}
// For 0 seconds we want to display '0 seconds'
if (str == "" || seconds > 0) {
str += seconds + " seconds";
}
return str;
}

$('waitTime').addEventListener('input', function() {
$('waitTimeOutput').value = $('waitTime').value;
$('waitTimeOutput').value = humanizeTime($('waitTime').value);
});

$('blockTime').addEventListener('input', function() {
$('blockTimeOutput').value = $('blockTime').value;
$('blockTimeOutput').value = humanizeTime($('blockTime').value * 60);
});

$('saveOptions').addEventListener('click', saveOptions);
Expand Down
6 changes: 3 additions & 3 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
</div>

<div>
<input type="range" id="waitTime" min="0" max="180" step="1">
<output for="waitTime" id="waitTimeOutput"></output> seconds
<input type="range" id="waitTime" min="0" max="300" step="5">
<output for="waitTime" id="waitTimeOutput"></output>
</div>
</section>

Expand All @@ -47,7 +47,7 @@

<div>
<input type="range" id="blockTime" min="0" max="60" step="1">
<output for="blockTime" id="blockTimeOutput"></output> minutes
<output for="blockTime" id="blockTimeOutput"></output>
</div>
</section>

Expand Down

0 comments on commit 1c9ab8b

Please sign in to comment.