replaces hardcoded values with env var

This commit is contained in:
2026-01-12 21:02:19 -05:00
parent b167041ce2
commit a3d5d2cbfa
3 changed files with 76 additions and 13 deletions

View File

@@ -25,14 +25,34 @@
<div class="percent weekly-percent" id="weeklyPercent">0%</div>
</div>
<script>
const WORK_START_HOUR = 7;
const WORK_START_MINUTE = 0;
const WORK_END_HOUR = 17;
const WORK_END_MINUTE = 30;
<!-- App configuration -->
<script id="app-config" type="application/json">
{{ {
"workStart": work_start,
"workEnd": work_end,
"workDays": work_days,
"updateInterval": update_interval
} | tojson }}
</script>
<!-- Application logic -->
<script>
const config = JSON.parse(
document.getElementById("app-config").textContent
);
const WORK_START_HOUR = config.workStart.hour;
const WORK_START_MINUTE = config.workStart.minute;
const WORK_END_HOUR = config.workEnd.hour;
const WORK_END_MINUTE = config.workEnd.minute;
const WORK_DAYS = config.workDays;
const UPDATE_INTERVAL = config.updateInterval;
const TOTAL_WORK_MINUTES =
(WORK_END_HOUR * 60 + WORK_END_MINUTE) -
(WORK_START_HOUR * 60 + WORK_START_MINUTE);
const TOTAL_WORK_MINUTES = 630; // 10.5 hours
const WORK_DAYS = [0, 1, 2, 3]; // Sunday → Wednesday
const WEEKLY_DAY_WEIGHT = 100 / WORK_DAYS.length;
function updateProgress() {
@@ -64,16 +84,19 @@
statusText.textContent = "Workday complete 🎉";
} else {
const elapsedMinutes = Math.floor((now - start) / 60000);
dailyPercent = Math.min((elapsedMinutes / TOTAL_WORK_MINUTES) * 100, 100);
dailyPercent = Math.min(
(elapsedMinutes / TOTAL_WORK_MINUTES) * 100,
100
);
statusText.textContent = "Grinding…";
}
// Apply daily progress
// Daily progress
dailyFill.style.width = dailyPercent + "%";
dailyPercentText.textContent = dailyPercent.toFixed(1) + "%";
// Weekly progress
let completedDays = WORK_DAYS.filter(d => d < day).length;
const completedDays = WORK_DAYS.filter(d => d < day).length;
let weeklyPercent =
(completedDays * WEEKLY_DAY_WEIGHT) +
(isWorkday ? (dailyPercent / 100) * WEEKLY_DAY_WEIGHT : 0);
@@ -85,7 +108,7 @@
}
updateProgress();
setInterval(updateProgress, 30 * 1000);
setInterval(updateProgress, UPDATE_INTERVAL);
</script>
</body>
</html>