scheduled reminders

This commit is contained in:
Guy Sandler 2026-01-18 21:19:54 -08:00
parent 00b7f70eef
commit ff5b14a47e
3 changed files with 79 additions and 7 deletions

View File

@ -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}

View File

@ -179,14 +179,18 @@
</div>
<span class="option-name" data-i18n="todo_remind">Todo Reminders</span>
</div>
<!--
<div class="sub-options">
<div class="sub-option" style="margin-top:5px">
<input type="checkbox" id="multi_remind" name="multi_remind">
<label for="multi_remind" class="sub-text" /*data-i18n="move_top"*/>Remind 2x</label>
<input type="checkbox" id="scheduledReminder" name="scheduledReminder">
<label for="scheduledReminder" class="sub-text">scheduled reminders</label>
</div>
<div class="timesets">
<div class="timeset">
<input type="time" id="scheduledReminderTime" step="60"></input>
<span class="sub-text" data-i18n="scheduledReminderTime">Show reminders at specific time</span>
</div>
</div>
</div>
-->
</div>
</div>

View File

@ -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;