mirror of
https://github.com/GuySandler/CanvasRefined.git
synced 2026-06-21 01:49:54 +02:00
scheduled reminders
This commit is contained in:
parent
00b7f70eef
commit
ff5b14a47e
@ -28,7 +28,7 @@ a.option-container {display: block;color:#5ca5f6;font-size: 14px;}
|
|||||||
a.option-container:hover {background: #333}
|
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 {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}
|
#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 {margin-right: 8px;}
|
||||||
.options-left, .options-right {width: 50%;}
|
.options-left, .options-right {width: 50%;}
|
||||||
.customDomain {font-weight:600}
|
.customDomain {font-weight:600}
|
||||||
|
|||||||
@ -179,14 +179,18 @@
|
|||||||
</div>
|
</div>
|
||||||
<span class="option-name" data-i18n="todo_remind">Todo Reminders</span>
|
<span class="option-name" data-i18n="todo_remind">Todo Reminders</span>
|
||||||
</div>
|
</div>
|
||||||
<!--
|
|
||||||
<div class="sub-options">
|
<div class="sub-options">
|
||||||
<div class="sub-option" style="margin-top:5px">
|
<div class="sub-option" style="margin-top:5px">
|
||||||
<input type="checkbox" id="multi_remind" name="multi_remind">
|
<input type="checkbox" id="scheduledReminder" name="scheduledReminder">
|
||||||
<label for="multi_remind" class="sub-text" /*data-i18n="move_top"*/>Remind 2x</label>
|
<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>
|
||||||
-->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,7 @@ let grades = null;
|
|||||||
let announcements = [];
|
let announcements = [];
|
||||||
let options = {};
|
let options = {};
|
||||||
let timeCheck = null;
|
let timeCheck = null;
|
||||||
|
let reminderCheck = null;
|
||||||
//let assignmentData = null;
|
//let assignmentData = null;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -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."*/;
|
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();
|
isDomainCanvasPage();
|
||||||
|
|
||||||
function 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;
|
options = result;
|
||||||
if (result.custom_domain.length && result.custom_domain[0] !== "") {
|
if (result.custom_domain.length && result.custom_domain[0] !== "") {
|
||||||
for (let i = 0; i < result.custom_domain.length; i++) {
|
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
|
// if the code reaches this point, its not a canvas page so run the reminders
|
||||||
setTimeout(reminderWatch, 2000);
|
setTimeout(reminderWatch, 2000);
|
||||||
setInterval(reminderWatch, 60000);
|
setInterval(reminderWatch, 60000);
|
||||||
|
toggleScheduledReminders();
|
||||||
// turn the reminders on/off if the option is changed
|
// turn the reminders on/off if the option is changed
|
||||||
chrome.storage.onChanged.addListener((changes) => {
|
chrome.storage.onChanged.addListener((changes) => {
|
||||||
Object.keys(changes).forEach(key => {
|
Object.keys(changes).forEach(key => {
|
||||||
if (key === "remind") reminderWatch();
|
if (key === "remind") reminderWatch();
|
||||||
|
if (key === "scheduledReminder" || key === "scheduledReminderTime") {
|
||||||
|
options[key] = changes[key].newValue;
|
||||||
|
toggleScheduledReminders();
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
@ -219,6 +253,7 @@ function startExtension() {
|
|||||||
chrome.storage.sync.get(null, result => {
|
chrome.storage.sync.get(null, result => {
|
||||||
options = { ...options, ...result };
|
options = { ...options, ...result };
|
||||||
toggleAutoDarkMode();
|
toggleAutoDarkMode();
|
||||||
|
toggleScheduledReminders();
|
||||||
getApiData();
|
getApiData();
|
||||||
checkDashboardReady();
|
checkDashboardReady();
|
||||||
loadCustomFont();
|
loadCustomFont();
|
||||||
@ -326,6 +361,10 @@ function applyOptionsChanges(changes) {
|
|||||||
case ("remind"):
|
case ("remind"):
|
||||||
showExampleReminder();
|
showExampleReminder();
|
||||||
break;
|
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() {
|
function toggleAutoDarkMode() {
|
||||||
clearInterval(timeCheck);
|
clearInterval(timeCheck);
|
||||||
if (options.auto_dark && options.auto_dark === false) return;
|
if (options.auto_dark && options.auto_dark === false) return;
|
||||||
@ -1267,6 +1328,13 @@ function toggleAutoDarkMode() {
|
|||||||
timeCheck = setInterval(autoDarkModeCheck, 60000);
|
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;
|
let iframeObserver;
|
||||||
function runiframeChecker() {
|
function runiframeChecker() {
|
||||||
if (current_page === "/" || current_page === "") return;
|
if (current_page === "/" || current_page === "") return;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user