Skip to content

Commit

Permalink
Add badge timer option
Browse files Browse the repository at this point in the history
  • Loading branch information
proginosko committed Jan 25, 2018
1 parent 6ec2c88 commit 822bb3c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
11 changes: 11 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,17 @@ function updateTimer(id) {
message.text = formatTime(secsLeft); // show timer with time left
}
browser.tabs.sendMessage(id, message).catch(function (error) {});

// Set badge timer (if option selected)
if (gOptions["timerBadge"] && secsLeft < 600) {
let m = Math.floor(secsLeft / 60);
let s = Math.floor(secsLeft) % 60;
let text = m + ":" + ((s < 10) ? "0" + s : s);
browser.browserAction.setBadgeBackgroundColor({ color: "#666" });
browser.browserAction.setBadgeText({ text: text, tabId: id });
} else {
browser.browserAction.setBadgeText({ text: "", tabId: id });
}
}

// Create info for blocking/delaying page
Expand Down
3 changes: 3 additions & 0 deletions common.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ function cleanOptions(options) {
if (typeof options["timerLocation"] !== "string") {
options["timerLocation"] = "0"; // default: top left
}
if (typeof options["timerBadge"] !== "boolean") {
options["timerBadge"] = false; // default: disabled
}
if (typeof options["warnSecs"] !== "string") {
options["warnSecs"] = ""; // default: no warning
}
Expand Down
10 changes: 7 additions & 3 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -215,24 +215,28 @@
<legend>Countdown Timer</legend>
<p>
<input id="timerVisible" type="checkbox">
<label for="timerVisible">Show timer</label>
<label for="timerVisible">Show timer over page</label>
&nbsp;&nbsp;&nbsp;&nbsp;
<label>Timer size:</label>
<label>Size:</label>
<select id="timerSize">
<option value="0">small</option>
<option value="1">medium</option>
<option value="2">large</option>
<option value="3">extra large</option>
</select>
&nbsp;&nbsp;&nbsp;&nbsp;
<label>Timer location:</label>
<label>Location:</label>
<select id="timerLocation">
<option value="0">top left</option>
<option value="1">top right</option>
<option value="2">bottom right</option>
<option value="3">bottom left</option>
</select>
</p>
<p>
<input id="timerBadge" type="checkbox">
<label for="timerBadge">Show timer as icon badge (if time left is less than 10 minutes)</label>
</p>
</fieldset>
<fieldset>
<legend>Miscellaneous</legend>
Expand Down
7 changes: 7 additions & 0 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ function saveOptions() {
options["timerVisible"] = getElement("timerVisible").checked;
options["timerSize"] = getElement("timerSize").value;
options["timerLocation"] = getElement("timerLocation").value;
options["timerBadge"] = getElement("timerBadge").checked;
options["warnSecs"] = getElement("warnSecs").value;
options["contextMenu"] = getElement("contextMenu").checked;

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

Expand Down Expand Up @@ -414,6 +416,7 @@ function exportOptions() {
options["timerVisible"] = getElement("timerVisible").checked;
options["timerSize"] = getElement("timerSize").value;
options["timerLocation"] = getElement("timerLocation").value;
options["timerBadge"] = getElement("timerBadge").checked;
options["warnSecs"] = getElement("warnSecs").value;
options["contextMenu"] = getElement("contextMenu").checked;

Expand Down Expand Up @@ -617,6 +620,7 @@ function importOptions() {
let timerVisible = options["timerVisible"];
let timerSize = options["timerSize"];
let timerLocation = options["timerLocation"];
let timerBadge= options["timerBadge"];
let warnSecs = options["warnSecs"];
let contextMenu = options["contextMenu"];
if (oa != undefined) {
Expand All @@ -637,6 +641,9 @@ function importOptions() {
if (timerLocation != undefined) {
getElement("timerLocation").value = timerLocation;
}
if (timerBadge != undefined) {
getElement("timerBadge").checked = timerBadge;
}
if (warnSecs != undefined) {
getElement("warnSecs").value = warnSecs;
}
Expand Down

0 comments on commit 822bb3c

Please sign in to comment.