Skip to content

Commit

Permalink
Fix formatting, add missing semicolons, and change constant names to …
Browse files Browse the repository at this point in the history
…uppercase
  • Loading branch information
do0ori committed Feb 22, 2024
1 parent 59f4ae9 commit 0660719
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
<input type="number" min="1" id="total-input" placeholder="Total" />
</div>
<div id="context-menu">
<div class="context-menu-item" id="reset-progress">Reset progress to 0</div>
<div class="context-menu-item" id="reset-progress">
Reset progress to 0
</div>
<div class="context-menu-item">
<label for="bar-color-picker">Bar color</label>
<input type="color" id="bar-color-picker">
Expand Down
24 changes: 12 additions & 12 deletions progressbar.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const totalKey = "total";
const progressKey = "progress";
const barColorKey = "barColor";
const TOTAL_KEY = "total";
const PROGRESS_KEY = "progress";
const BAR_COLOR_KEY = "barColor";

document.addEventListener("DOMContentLoaded", function () {
let total = parseInt(localStorage.getItem(totalKey)) || 1;
let progress = parseInt(localStorage.getItem(progressKey)) || 0;
let barColor = localStorage.getItem(barColorKey) || "#4CAF50";
let total = parseInt(localStorage.getItem(TOTAL_KEY)) || 1;
let progress = parseInt(localStorage.getItem(PROGRESS_KEY)) || 0;
let barColor = localStorage.getItem(BAR_COLOR_KEY) || "#4CAF50";
const progressContainer = document.getElementById("progress-container");
const progressBar = document.getElementById("progress-bar");
const countDisplay = document.getElementById("count-display");
Expand Down Expand Up @@ -34,30 +34,30 @@ document.addEventListener("DOMContentLoaded", function () {

if (!isNaN(newTotal) && newTotal > 0 && newTotal !== total) {
total = newTotal;
localStorage.setItem(totalKey, total);
localStorage.setItem(TOTAL_KEY, total);
totalInput.value = total;
resetProgress();
}
};

const resetBarColor = () => {
barColor = barColorPicker.value = "#4CAF50";
localStorage.setItem(barColorKey, barColor);
localStorage.setItem(BAR_COLOR_KEY, barColor);
updateBarColor();
};

const decreaseProgress = () => {
if (progress > 0) {
progress--;
localStorage.setItem(progressKey, progress);
localStorage.setItem(PROGRESS_KEY, progress);
resetProgress();
}
};

const increaseProgress = () => {
if (progress < total) {
progress++;
localStorage.setItem(progressKey, progress);
localStorage.setItem(PROGRESS_KEY, progress);
resetProgress();
}
};
Expand Down Expand Up @@ -88,7 +88,7 @@ document.addEventListener("DOMContentLoaded", function () {

const handlBarColor = () => {
barColor = barColorPicker.value;
localStorage.setItem(barColorKey, barColor);
localStorage.setItem(BAR_COLOR_KEY, barColor);
updateBarColor();
};

Expand All @@ -102,7 +102,7 @@ document.addEventListener("DOMContentLoaded", function () {
});
document.getElementById("reset-progress").addEventListener("click", () => {
progress = 0;
localStorage.setItem(progressKey, progress);
localStorage.setItem(PROGRESS_KEY, progress);
resetProgress();
});
barColorPicker.addEventListener("change", handlBarColor);
Expand Down

0 comments on commit 0660719

Please sign in to comment.