Skip to content

Commit

Permalink
Add button to discard remaining time (proginosko#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
proginosko committed Feb 28, 2023
1 parent ec2b897 commit 4d23350
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
31 changes: 29 additions & 2 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,7 @@ function applyOverride(endTime) {
updateIcon();
}

// Reset rollover time for all sets applicable to active tab
// Reset rollover time for set applicable to active tab
//
function resetRolloverTime() {
//log("resetRolloverTime");
Expand All @@ -1266,11 +1266,33 @@ function resetRolloverTime() {
// Get block set for currently active time limit
let set = gTabs[gActiveTabId].secsLeftSet;
if (set) {
// Reset rollover time
// Reset rollover time for current period
gOptions[`timedata${set}`][5] = 0;
}
}

// Discard remaining time for set applicable to active tab
//
function discardRemainingTime() {
//log("discardRemainingTime");

if (!gGotOptions || !gActiveTabId) {
return;
}

// Get block set for currently active time limit
let set = gTabs[gActiveTabId].secsLeftSet;
if (set) {
// Set used time to time limit
let limitMins = gOptions[`limitMins${set}`];
gOptions[`timedata${set}`][3] = (limitMins * 60);
// Reset rollover time for current period
gOptions[`timedata${set}`][5] = 0;
// Reset rollover time for next period
gOptions[`timedata${set}`][6] = 0;
}
}

// Open extension page (either create new tab or activate existing tab)
//
function openExtensionPage(url) {
Expand Down Expand Up @@ -1413,6 +1435,11 @@ function handleMessage(message, sender, sendResponse) {
openDelayedPage(sender.tab.id, url, set, autoLoad);
break;

case "discard-time":
// Discard remaining time
discardRemainingTime();
break;

case "loaded":
// Register that content script has been loaded
gTabs[sender.tab.id].loaded = true;
Expand Down
2 changes: 1 addition & 1 deletion popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ body {

#button-container {
display: inline-block;
width: 150px;
width: 180px;
}

button {
Expand Down
1 change: 1 addition & 0 deletions popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<br><br>
<button id="cancelOverride" type="button">Cancel Override</button>
<button id="resetRollover" type="button">Reset Rollover Time</button>
<button id="discardTime" type="button">Discard Remaining Time</button>
</div>
<script src="/popup.js"></script>
</body>
Expand Down
14 changes: 13 additions & 1 deletion popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function cancelOverride() {
window.close();
}

// Reset rollover
// Reset rollover time
//
function resetRollover() {
let message = {
Expand All @@ -94,11 +94,23 @@ function resetRollover() {
window.close();
}

// Discard remaining time
//
function discardTime() {
let message = {
type: "discard-time",
};
browser.runtime.sendMessage(message);

window.close();
}

document.querySelector("#options").addEventListener("click", openOptions);
document.querySelector("#lockdown").addEventListener("click", openLockdown);
document.querySelector("#override").addEventListener("click", openOverride);
document.querySelector("#stats").addEventListener("click", openStats);
document.querySelector("#cancelOverride").addEventListener("click", cancelOverride);
document.querySelector("#resetRollover").addEventListener("click", resetRollover);
document.querySelector("#discardTime").addEventListener("click", discardTime);

document.addEventListener("DOMContentLoaded", initializePage);

0 comments on commit 4d23350

Please sign in to comment.