From ff5b14a47e4d2709ffbaa675f8fbea0d2fe57f8e Mon Sep 17 00:00:00 2001 From: Guy Sandler Date: Sun, 18 Jan 2026 21:19:54 -0800 Subject: [PATCH] scheduled reminders --- css/popup.css | 2 +- html/popup.html | 12 ++++++--- js/content.js | 72 +++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 79 insertions(+), 7 deletions(-) diff --git a/css/popup.css b/css/popup.css index 59a413e..4a23f65 100644 --- a/css/popup.css +++ b/css/popup.css @@ -28,7 +28,7 @@ a.option-container {display: block;color:#5ca5f6;font-size: 14px;} a.option-container:hover {background: #333} #customDomain {font-size: 12px; background: var(--inputbg); border: none;padding:8px;color: #e2e2e2;margin-top: 6px;border-radius: 7px; font-family: inherit;} #customDomain {width: 100%; box-sizing: border-box} -#auto_dark_start, #auto_dark_end {padding: 3px 5px; font-size:12px;background: var(--inputbg);color:#e2e2e2;border:none;border-radius: 7px;} +#auto_dark_start, #auto_dark_end, #scheduledReminderTime {padding: 3px 5px; font-size:12px;background: var(--inputbg);color:#e2e2e2;border:none;border-radius: 7px;} .options-left {margin-right: 8px;} .options-left, .options-right {width: 50%;} .customDomain {font-weight:600} diff --git a/html/popup.html b/html/popup.html index 883511e..d05dded 100644 --- a/html/popup.html +++ b/html/popup.html @@ -179,14 +179,18 @@ Todo Reminders - diff --git a/js/content.js b/js/content.js index fc34686..b3d6643 100644 --- a/js/content.js +++ b/js/content.js @@ -5,9 +5,10 @@ let grades = null; let announcements = []; let options = {}; let timeCheck = null; +let reminderCheck = null; //let assignmentData = null; -/* +/* Start */ @@ -185,10 +186,38 @@ function showExampleReminder() { example.querySelector(".bettercanvas-reminder-due").textContent = "This notification will pop up in other pages to remind you of incomplete assignments that are due in less than 6 hours." /*It will notify again at 2 hours if the 'Remind 2x' option is on."*/; } +async function ScheduledReminderCheck() { + let date = new Date(); + let currentHour = date.getHours(); + let currentMinute = date.getMinutes(); + if (options.scheduledReminderTime) { + let [hour, minute] = options.scheduledReminderTime.split(":"); + if (parseInt(hour) == currentHour && parseInt(minute) == currentMinute) { + const container = document.getElementById("bettercanvas-reminders") || makeElement("div", document.body, { "id": "bettercanvas-reminders" }); + container.style.display = "flex"; + container.textContent = ""; + const storage = await chrome.storage.sync.get("reminders"); + const now = (new Date()).getTime(); + storage["reminders"].forEach(reminder => { + if (reminder.d >= now) { + createReminder(reminder, container); + } + }); + } + } +} + +function toggleScheduledReminders() { + clearInterval(reminderCheck); + if (options.scheduledReminder !== true) return; + ScheduledReminderCheck(); + reminderCheck = setInterval(ScheduledReminderCheck, 60000); +} + isDomainCanvasPage(); function isDomainCanvasPage() { - chrome.storage.sync.get(['custom_domain', 'dark_mode', 'dark_preset', 'device_dark', 'remind'], result => { + chrome.storage.sync.get(['custom_domain', 'dark_mode', 'dark_preset', 'device_dark', 'remind', 'scheduledReminder', 'scheduledReminderTime'], result => { options = result; if (result.custom_domain.length && result.custom_domain[0] !== "") { for (let i = 0; i < result.custom_domain.length; i++) { @@ -201,10 +230,15 @@ function isDomainCanvasPage() { // if the code reaches this point, its not a canvas page so run the reminders setTimeout(reminderWatch, 2000); setInterval(reminderWatch, 60000); + toggleScheduledReminders(); // turn the reminders on/off if the option is changed chrome.storage.onChanged.addListener((changes) => { Object.keys(changes).forEach(key => { if (key === "remind") reminderWatch(); + if (key === "scheduledReminder" || key === "scheduledReminderTime") { + options[key] = changes[key].newValue; + toggleScheduledReminders(); + } }) }) } else { @@ -219,6 +253,7 @@ function startExtension() { chrome.storage.sync.get(null, result => { options = { ...options, ...result }; toggleAutoDarkMode(); + toggleScheduledReminders(); getApiData(); checkDashboardReady(); loadCustomFont(); @@ -326,6 +361,10 @@ function applyOptionsChanges(changes) { case ("remind"): showExampleReminder(); break; + case ("scheduledReminder"): + case ("scheduledReminderTime"): + toggleScheduledReminders(); + break; } }); } @@ -1260,6 +1299,28 @@ function autoDarkModeCheck() { } } +async function ScheduledReminderCheck() { + let date = new Date(); + let currentHour = date.getHours(); + let currentMinute = date.getMinutes(); + if (options.scheduledReminderTime) { + let [hour, minute] = options.scheduledReminderTime.split(":"); + if (parseInt(hour) == currentHour && parseInt(minute) == currentMinute) { + const container = document.getElementById("bettercanvas-reminders") || makeElement("div", document.body, { "id": "bettercanvas-reminders" }); + container.style.display = "flex"; + container.textContent = ""; + const storage = await chrome.storage.sync.get("reminders"); + const now = (new Date()).getTime(); + storage["reminders"].forEach(reminder => { + if (reminder.d >= now) { + createReminder(reminder, container); + } + }); + } + } + +} + function toggleAutoDarkMode() { clearInterval(timeCheck); if (options.auto_dark && options.auto_dark === false) return; @@ -1267,6 +1328,13 @@ function toggleAutoDarkMode() { timeCheck = setInterval(autoDarkModeCheck, 60000); } +function toggleScheduledReminders() { + clearInterval(reminderCheck); + if (options.scheduled_reminders === false) return; //TODO: add it to the options thing + ScheduledReminderCheck(); + reminderCheck = setInterval(ScheduledReminderCheck, 60000); +} + let iframeObserver; function runiframeChecker() { if (current_page === "/" || current_page === "") return;