blob: 3b5f2cf33ee63c7e7df0e08348a1ce57d65c4678 [file] [log] [blame]
j7940eec2020-12-28 14:00:41 -06001/**
2 * @file DTPS Core functions and module loader
3 * @author jottocraft
j3043ce72026-10-13 21:28:45 +00004 * @version v3.10.0
j7940eec2020-12-28 14:00:41 -06005 *
j6e1a7bf2026-10-13 03:37:04 +00006 * @copyright Copyright (c) jottocraft 2020
j40db0272022-01-14 15:18:29 -08007 * @license MIT
j7940eec2020-12-28 14:00:41 -06008 */
9
10//Make sure DTPS isn't already loading
j0f3d7db2026-10-13 04:56:55 +000011if (typeof dtps !== "undefined") throw new Error("Error: DTPS is already loading");
j7940eec2020-12-28 14:00:41 -060012
j47ec9482026-10-13 21:04:37 +000013//Handle internal resource URL migration to dtps.jottocraft.com
14if (window.dtpsBaseURL === "https://powerplus.app") {
15 window.dtpsBaseURL = "https://dtps.jottocraft.com";
16}
17
j7940eec2020-12-28 14:00:41 -060018/**
19 * Global DTPS object
20 * All global DTPS functions and variables are stored in this object
21 *
22 * @global
23 * @namespace dtps
24 * @property {number} ver Comparable version number
25 * @property {string} env DTPS enviornment ("prod" or "dev")
26 * @property {string} readableVer Formatted semantic version number
27 * @property {Class[]} classes Array of classes the current user is in
28 * @property {string} baseURL The base URL that DTPS is being loaded from
29 * @property {boolean} unstable This is true if loading an unstable version of DTPS
30 * @property {boolean} gradebookExpanded True if gradebook details (Show more...) is open. Used in the generic gradebook and may be used in custom gradebook implementations.
jdc6ea0e2022-04-26 16:03:27 -070031 * @property {boolean} reloadPending True if the user has made changes that require a reload
j0f3d7db2026-10-13 04:56:55 +000032 * @property {string|undefined} popup Popup to show when loaded. Either undefined (no popup) or "firstrun".
j7940eec2020-12-28 14:00:41 -060033 * @property {User} user Current user, fetched with dtps.init
34 * @property {number|string} selectedClass The selected class number, or "dash" if the dashboard is selected. Set when the first screen is loaded in dtps.init.
35 * @property {string} selectedContent The selected class content/tab. Set when the first class content is loaded. Defaults to "stream".
36 * @property {number|undefined} bgTimeout Background transition timeout when switching between classes
37 * @property {Array<Assignment|Announcement>} updates Array of up to 10 recently graded assignments or announcements.
38 * @property {DashboardItem[]} dashboardItems Array of items that can be shown on the dashboard
39 * @property {DashboardItem[]} leftDashboard Items on the left side of the dashboard based on dtps.dashboardItems and user prefrences. Set in dtps.loadDashboardPrefs.
40 * @property {DashboardItem[]} rightDashboard Items on the right side of the dashboard based on dtps.dashboardItems and user prefrences. Set in dtps.loadDashboardPrefs.
j7940eec2020-12-28 14:00:41 -060041 * @property {boolean} searchScrollListener True if the search scroll listener has been added
42 */
43var dtps = {
j47ec9482026-10-13 21:04:37 +000044 ver: 3_10_0,
45 readableVer: "v3.10.0",
46 env: new URL(window.dtpsBaseURL || "https://dtps.jottocraft.com").hostname == "localhost" ? "dev" : "prod",
j7940eec2020-12-28 14:00:41 -060047 classes: [],
j47ec9482026-10-13 21:04:37 +000048 baseURL: window.dtpsBaseURL || "https://dtps.jottocraft.com",
49 unstable: window.dtpsBaseURL !== "https://dtps.jottocraft.com",
j7940eec2020-12-28 14:00:41 -060050 gradebookExpanded: false,
jdc6ea0e2022-04-26 16:03:27 -070051 reloadPending: false,
j7940eec2020-12-28 14:00:41 -060052 updates: [],
53 dashboardItems: [
54 {
55 name: "Calendar",
56 id: "dtps.calendar",
57 icon: "event",
58 size: 100,
59 defaultSide: "left"
60 }, {
61 name: "Updates",
62 id: "dtps.updates",
63 icon: "calendar_view_day",
64 size: 170,
65 defaultSide: "left"
66 }, {
67 name: "Due Today",
68 id: "dtps.dueToday",
69 icon: "check_circle_outline",
70 size: 20,
71 defaultSide: "right"
72 }, {
73 name: "Upcoming Assignments",
74 id: "dtps.upcoming",
75 icon: "view_stream",
76 size: 250,
77 defaultSide: "right"
78 }
j0f3d7db2026-10-13 04:56:55 +000079 ]
j7940eec2020-12-28 14:00:41 -060080};
81
82//Load jQuery ASAP
j6ca9c7e2026-10-13 20:39:55 +000083jQuery.getScript("https://cdn.jottocraft.com/3rdparty/scripts/jquery.min.js");
j7940eec2020-12-28 14:00:41 -060084
85/**
86 * Debugging shortcut for getting the selected class. This should only be used in the web inspector and not in actual code.
87 *
88 * @return {object|undefined} The selected class
89 */
90dtps.class = function () {
91 return dtps.classes[dtps.selectedClass];
jd80b6e02021-04-19 20:16:38 -070092};
93
94//Detect debug info shortcut
95document.onkeydown = function (event) {
96 if (event.ctrlKey && event.altKey && (event.code == "KeyD")) {
j5bcb1122021-05-25 12:53:21 -070097 var replacer = function (key, value) {
jd80b6e02021-04-19 20:16:38 -070098 //Truncate long properties
99 if (["assignments", "people", "modules", "discussions", "pages", "outcomes"].includes(key)) {
100 if (value instanceof Array) return "[truncated] (array, length " + value.length + ")";
101 if (typeof value == "object") return "[truncated] (object, keys " + Object.keys(value).length + ")";
102 return value;
103 }
104
105 //Remove sensitive properties/PII
106 if (["letter", "number75", "grade", "lowestScore"].includes(key)) return "[redacted] (" + (typeof value) + ")";
107
108 return value;
109 };
110
111 $(".card.details").html(/*html*/`
112 <i onclick="fluid.cards.close('.card.details'); $('.card.details').html('');" class="fluid-icon close">close</i>
113
114 <h4 style="font-weight: bold;">Debug</h4>
115
116 <div style="margin: 40px 0px;">
117 <h5>User</h5>
j6ca9c7e2026-10-13 20:39:55 +0000118 <pre><code class="prettyprint">${DOMPurify.sanitize(JSON.stringify(dtps.user, null, '\t'))}</code></pre>
jd80b6e02021-04-19 20:16:38 -0700119 </div>
120
j5bcb1122021-05-25 12:53:21 -0700121 ${dtps.classes[dtps.selectedClass] ? /*html*/`
jd80b6e02021-04-19 20:16:38 -0700122 <div style="margin: 40px 0px;">
123 <h5>Selected class</h5>
j6ca9c7e2026-10-13 20:39:55 +0000124 <pre><code class="prettyprint">${DOMPurify.sanitize(JSON.stringify(dtps.classes[dtps.selectedClass], replacer, '\t'))}</code></pre>
jd80b6e02021-04-19 20:16:38 -0700125 </div>
126 ` : ``
127 }
128 `);
129
130 if (!window.PR) {
j6ca9c7e2026-10-13 20:39:55 +0000131 $.getScript("https://cdn.jottocraft.com/3rdparty/scripts/run_prettify.js");
jd80b6e02021-04-19 20:16:38 -0700132 } else {
133 PR.prettyPrint();
134 }
135
136 //Close other active cards and open the assignment details card
137 fluid.cards.close(".card.focus");
138 fluid.cards(".card.details");
139 }
j7940eec2020-12-28 14:00:41 -0600140}
141
142/**
j7940eec2020-12-28 14:00:41 -0600143 * Logs debugging messages
144 *
j58471992021-01-17 19:29:37 -0800145 * @param {...*} msg The debugging messages to log
j7940eec2020-12-28 14:00:41 -0600146 */
j58471992021-01-17 19:29:37 -0800147dtps.log = function () {
jdc6ea0e2022-04-26 16:03:27 -0700148 console.log("[DTPS]", ...arguments);
j7940eec2020-12-28 14:00:41 -0600149}
150
j6ca9c7e2026-10-13 20:39:55 +0000151/**
152 * Escapes a string for use inside a quoted HTML attribute value.
153 * DOMPurify.sanitize does not escape quotes, so it can't be used for attribute values.
154 *
155 * @param {*} str The value to escape
156 * @return {string} Escaped string
157 */
158dtps.escapeAttr = function (str) {
159 return String(str).replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/'/g, "&#39;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
160}
161
162/**
163 * Sanitizes rich HTML content from the LMS (assignment bodies, pages, posts, etc.).
164 * Embedded iframes (e.g. videos) and link targets are allowed.
165 *
166 * @param {string} html The HTML to sanitize
167 * @return {string} Sanitized HTML
168 */
169dtps.sanitizeContent = function (html) {
170 return DOMPurify.sanitize(html, { ADD_TAGS: ["iframe"], ADD_ATTR: ["allow", "allowfullscreen", "frameborder", "scrolling", "target"] });
171}
172
173/**
174 * Ensures that a URL is safe
175 *
176 * @param {string} url The URL to check
177 * @returns {string} The URL if it is safe, otherwise "about:blank"
178 */
179dtps.safeURL = function (url) {
180 try {
181 var protocol = new URL(url, window.location.href).protocol;
182 if (["http:", "https:", "mailto:", "tel:"].includes(protocol)) return url;
183 } catch (e) { }
184 return "about:blank";
185}
186
187/**
188 * Shows an error message alert and logs to console, WITHOUT SANITIZING INPUT
189 *
190 * @param {string} msg The error to display
191 * @param {string} [devNotes] Technical error details displayed in a smaller font
192 * @param {Error} [err] An error object to log to the console. If this is null, DTPS will assume the error has been handled elsewhere.
193 */
194dtps.unsafeError = function (msg, devNotes, err) {
195 if (err !== null) {
196 var formattedDevNotes = "";
197 if (devNotes) {
198 formattedDevNotes = '<div style="font-size: 12px; color: var(--secText, gray); margin-top: 10px;">' + devNotes + '</div>';
199 }
200 console.error("[DTPS !!ERROR!!]", devNotes + ": ", err);
201 fluid.alert("Error", msg + formattedDevNotes, "error");
202 }
203}
j7940eec2020-12-28 14:00:41 -0600204
205/**
206 * Shows an error message alert and logs to console
207 *
208 * @param {string} msg The error to display
209 * @param {string} [devNotes] Technical error details displayed in a smaller font
210 * @param {Error} [err] An error object to log to the console. If this is null, DTPS will assume the error has been handled elsewhere.
211 */
212dtps.error = function (msg, devNotes, err) {
j6ca9c7e2026-10-13 20:39:55 +0000213 dtps.unsafeError(
214 DOMPurify.sanitize(msg),
215 DOMPurify.sanitize(devNotes),
216 err
217 );
j7940eec2020-12-28 14:00:41 -0600218}
219
220/**
221 * Renders "Welcome to Project DTPS" screen on the first run
222 */
223dtps.firstrun = function () {
224 //Set latest changelog version to current version
225 window.localStorage.setItem('dtps', dtps.ver);
226
227 //Welcome to DTPS screen HTML
228 jQuery(".card.changelog").html(/*html*/`
229 <h3 style="margin-bottom: 0px;">Welcome to Power+</h3>
230 <h5 style="color: var(--secText); font-weight: bold; font-size: 22px;">${dtps.readableVer}</h5>
231
232 <div class="welcomeSection">
233 <i class="fluid-icon">dashboard</i>
j0f3d7db2026-10-13 04:56:55 +0000234 <h5>Manage your coursework</h5>
j7940eec2020-12-28 14:00:41 -0600235 <p>Power+ organizes all of your coursework so you can easily see what you need to do next. The dashboard shows upcoming assignments, recent grades, and announcements.
j0f3d7db2026-10-13 04:56:55 +0000236 ${dtpsLMS.dtech ? `<p style="color: var(--text);"><b>As of October 2026, all d.tech-specific features, including CBL grade calculation, have been removed from Power+.</b></p>` : ``}
j7940eec2020-12-28 14:00:41 -0600237 </div>
238
239 ${dtpsLMS.isDemoLMS ? /*html*/`
240 <div class="welcomeSection">
241 <i class="fluid-icon">priority_high</i>
242 <h5>This is a demo</h5>
243 <p>Assignment information, grades, and other content displayed is not real and is for demonstration purposes only. This demo does not retrieve or collect any data.</p>
244 </div>
245 ` : /*html*/`
246 <div class="welcomeSection">
247 <i class="fluid-icon">security</i>
248 <h5>Privacy</h5>
j5e67d8e2022-11-08 22:55:04 -0800249 <p>
250 Power+ records your device and network type, Canvas institution, and region when you load Power+.
251 Analytics events are associated with a unique ID generated with a one-way-hash from your Canvas ID and institution.
252 Data is collected directly by Power+ and is never shared with or sold to any third parties.
jb39e6d92021-01-30 20:34:04 -0800253 Power+ does <b>not</b> and will <b>never</b> collect any personal information, such as names, classes, or grades.
j5e67d8e2022-11-08 22:55:04 -0800254 </p>
j7940eec2020-12-28 14:00:41 -0600255 </div>
256 <div class="welcomeSection">
257 <i class="fluid-icon">priority_high</i>
258 <h5>Power+ is not official</h5>
259 <p>Assignment information, grades, and other content displayed in Power+ are not official. Power+ is neither created nor endorsed by ${dtpsLMS.legalName}.
260 Power+ may have bugs that could cause it to display inaccurate information. Use Power+ at your own risk.</p>
261 </div>
262 `}
263
264 <br />
265 <button onclick="window.localStorage.setItem('dtpsInstalled', 'true'); fluid.cards.close('.card.changelog');" class="btn">
266 <i class="fluid-icon">arrow_forward</i> Continue
267 </button>
268 `);
269
270 //Show Welcome to DTPS card
271 fluid.cards.close(".card.focus");
272 fluid.cards(".card.changelog", "stayOpen");
273};
274
275/**
276 * Renders the DTPS loading screen
277 */
278dtps.renderLoadingScreen = function () {
279 if (!window.dtpsPreLoader || dtps.user) {
280 //Only show the loader if the extension hasn't already shown it
281 jQuery("body").append(/*html*/`
282 <div id="dtpsNativeOverlay" style="background-color: #151515; position: fixed; top: 0px; left: 0px; width: 100%; height: 100vh; z-index: 99;text-align: center;z-index: 999;transition: opacity 0.2s;">
283 <img style="height: 100px; margin-top: 132px;" src="https://i.imgur.com/7dDUVh2.png" />
284 <br />
285 <div class="progress"><div class="indeterminate"></div></div>
286 <style>body {background-color: #151515; overflow: hidden;}*,:after,:before{box-sizing:border-box}.progress{position:relative;width:600px;height:5px;overflow:hidden;border-radius:12px;background:#262626;backdrop-filter:opacity(.4);display:inline-block;margin-top:75px}.progress .indeterminate{position:absolute;background:#e3ba4b;height:5px;animation:indeterminate 1.4s infinite;animation-timing-function:linear}@keyframes indeterminate{0%{width:5%;left:-15%}to{width:100%;left:110%}}</style>
287 </div>
288 `);
289 }
290}
291
292/**
293 * Load all external JavaScript libraries
294 *
295 * @param {function} cb Callback function
296 */
jb39e6d92021-01-30 20:34:04 -0800297dtps.JS = function () {
298 return new Promise((resolve, reject) => {
299 //Moment & Fullcalendar are used for the calendar on the dashboard
j6ca9c7e2026-10-13 20:39:55 +0000300 jQuery.getScript("https://cdn.jottocraft.com/3rdparty/scripts/fullcalendar_main.min.js", function () {
301 jQuery.getScript("https://cdn.jottocraft.com/3rdparty/scripts/fullcalendar_locales-all.min.js");
jb39e6d92021-01-30 20:34:04 -0800302 });
j7940eec2020-12-28 14:00:41 -0600303
jb39e6d92021-01-30 20:34:04 -0800304 //Lunr is used for search
j6ca9c7e2026-10-13 20:39:55 +0000305 jQuery.getScript('https://cdn.jottocraft.com/3rdparty/scripts/lunr.min.js');
j7940eec2020-12-28 14:00:41 -0600306
jb39e6d92021-01-30 20:34:04 -0800307 //jQuery UI for dashboard settings page
j6ca9c7e2026-10-13 20:39:55 +0000308 jQuery.getScript('https://cdn.jottocraft.com/3rdparty/scripts/jquery-ui.min.js');
j7940eec2020-12-28 14:00:41 -0600309
jb39e6d92021-01-30 20:34:04 -0800310 //Tinycolor used for better dark mode support
311 jQuery.getScript("https://cdn.jottocraft.com/tinycolor.js");
j7940eec2020-12-28 14:00:41 -0600312
jce0d1cb2022-01-07 11:16:20 -0800313 //dtao/nearest-color is used for finding the nearest class color
314 jQuery.getScript("https://cdn.jottocraft.com/nearest-color.dtao.js", () => {
315 //Fluid UI for core UI elements
j6ca9c7e2026-10-13 20:39:55 +0000316 jQuery.getScript(dtps.baseURL + "/fluid/fluid.js", () => {
317 jQuery.getScript("https://cdn.jottocraft.com/3rdparty/scripts/purify.min.js", resolve);
318 });
j5f5942c2021-02-01 08:38:43 -0800319 });
j7940eec2020-12-28 14:00:41 -0600320 });
321}
322
323/**
324 * Load all DTPS CSS files
325 */
326dtps.CSS = function () {
327 jQuery("<link/>", {
328 rel: "stylesheet",
329 type: "text/css",
jdc6ea0e2022-04-26 16:03:27 -0700330 href: dtps.baseURL + "/fluid/fluid.css",
j7940eec2020-12-28 14:00:41 -0600331 class: "dtpsHeadItem"
332 }).appendTo("head");
333
334 jQuery("<link/>", {
335 rel: "stylesheet",
336 type: "text/css",
337 href: dtps.baseURL + "/dtps.css",
338 class: "dtpsHeadItem"
339 }).appendTo("head");
340
341 jQuery("<link/>", {
342 rel: "stylesheet",
343 type: "text/css",
344 href: "https://fonts.googleapis.com/css?family=Material+Icons+Round",
345 class: "dtpsHeadItem"
346 }).appendTo("head");
347
348 jQuery("<link/>", {
349 rel: "stylesheet",
350 type: "text/css",
351 href: "https://cdn.jsdelivr.net/npm/[email protected]/main.min.css",
352 class: "dtpsHeadItem"
353 }).appendTo("head");
354
355 jQuery("<link/>", {
356 rel: "stylesheet",
357 type: "text/css",
358 href: "https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css",
359 class: "dtpsHeadItem"
360 }).appendTo("head");
361}
362
363/**
j29812c42022-04-27 15:41:40 -0700364 * Gets the amount of minutes elapsed in the day
365 *
366 * @param {date} d The day
367 * @returns The amount of minutes or null if the date is invalid
368 */
369dtps.dayTimeMinutes = function (d) {
370 if (!d) return null;
371
372 d = new Date(d);
373 if (isNaN(d.getTime())) return null;
374
375 return (d.getHours() * 60) + d.getMinutes();
376}
377
378/**
j7940eec2020-12-28 14:00:41 -0600379 * Starts DTPS (entrypoint function)
380 */
381dtps.init = function () {
382 //Initial log
383 dtps.log("Starting DTPS " + dtps.readableVer + "...");
384
jb39e6d92021-01-30 20:34:04 -0800385 //Disable dev version
386 if (window.localStorage.getItem('dtpsLoaderPref') == "dev") {
387 window.localStorage.removeItem('dtpsLoaderPref');
388 }
389
j7940eec2020-12-28 14:00:41 -0600390 //Check for LMS config
391 if (!window.dtpsLMS) {
j0f3d7db2026-10-13 04:56:55 +0000392 throw new Error("No DTPS LMS configuration found");
j7940eec2020-12-28 14:00:41 -0600393 }
394
395 //Determine if this is the first time loading DTPS
396 if (window.localStorage.dtpsInstalled !== "true") {
397 dtps.popup = "firstrun";
398 }
399
400 //Render loading screen
401 dtps.renderLoadingScreen();
402
403 //Get URL parameters
404 var urlParams = new URLSearchParams(window.location.search);
405 if (Array.from(urlParams).length) window.history.replaceState(null, null, window.location.pathname);
406
407 //Fluid UI settings
408 window.fluidConfig = {
409 config: {
410 autoLoad: false,
411 allowThemeMenu: false //This is false because Power+ uses its own theme settings UI
412 }
413 };
414
415 //Set env discovery
416 window.localStorage.setItem("jottocraftEnv", true);
417
418 //Default selected content
419 dtps.selectedContent = "stream";
420
421 //Begin loading CSS
422 dtps.CSS();
423
424 //Begin loading static DTPS HTML
425 dtps.render();
426
j0f3d7db2026-10-13 04:56:55 +0000427 //Fetch JavaScript modules
428 dtps.JS().then(() => {
j7940eec2020-12-28 14:00:41 -0600429 //Fetch user and class data
430 return dtpsLMS.fetchUser();
431 }).then(data => {
432 //Prevent resetting the user if the user is already set (for parent accounts)
433 dtps.user = data;
434
435 //If this is a parent account, show the parent UI
436 if (dtps.user.children && dtps.user.children.length) {
437 dtps.user.parent = true;
438
439 //Fetch classes for all students
440 return new Promise((resolve, reject) => {
441 var allClasses = [];
442 var promises = [];
443
444 dtps.user.children.forEach(child => {
445 promises.push(new Promise(function (resolve, reject) {
446 dtpsLMS.fetchClasses(child.id).then((data) => {
447 //Prepend child ID to class ID
448 data.forEach(course => {
449 course.id = child.id + "-" + course.id;
450 course.group = child.name;
451 });
452
453 allClasses = allClasses.concat(data);
454 resolve();
455 }).catch(reject);
456 }));
457 });
458
459 Promise.all(promises).then(() => {
460 resolve(allClasses);
461 });
462 });
463 } else {
464 return dtpsLMS.fetchClasses(dtps.user.id);
465 }
j7940eec2020-12-28 14:00:41 -0600466 }).then(classData => {
467 //Store classData to dtps.classes
468 dtps.classes = classData;
469
470 //Add course num props
471 dtps.classes.forEach((course, index) => course.num = index);
472
jb39e6d92021-01-30 20:34:04 -0800473 //Define DTPS class color pallete
474 var nearestCourseColor = nearestColor.from({
475 //Primary color shades
476 red: "#cc4747",
477 brown: "#9a4429",
478 orange: "#ce734e",
479 pumpkin: "#c58535",
480 yellow: "#b58f38",
481 yellowGreen: "#7c9630",
482 green: "#439a47",
483 oceanGreen: "#339a70",
484 keppel: "#40b5c3",
485 skyBlue: "#40a4d6",
486 blue: "#2d72a0",
487 purple: "#985cab",
488 magenta: "#bd3e69",
489 pink: "#ec7ca5",
490 gray: "#888888",
491 //Dark color shades
492 gold: "#94652a",
493 darkRed: "#943f3f",
494 darkBlue: "#485182",
495 darkPurple: "#6f4882",
496 darkGreen: "#3d7358",
497 //Light color shades
498 lightOrange: "#ea7a44",
499 lightRed: "#e07f7f",
500 lightBlue: "#76c1e6",
501 lightPurple: "#978fd6",
502 lightGreen: "#7ebb95",
503 lightBrown: "#928871"
504 });
j7940eec2020-12-28 14:00:41 -0600505
j0f3d7db2026-10-13 04:56:55 +0000506 //Loop over each class to update the color
jb39e6d92021-01-30 20:34:04 -0800507 dtps.classes.forEach(course => {
508 course.color = course.color ? nearestCourseColor(course.color).value : "gray";
jb39e6d92021-01-30 20:34:04 -0800509 });
510
511 //Fluid UI screens
512 fluid.defaultScreen = "dashboard";
513 fluid.screens.dashboard = dtps.baseURL + "/scripts/assignments.js";
514 fluid.screens.stream = dtps.baseURL + "/scripts/assignments.js";
515 fluid.screens.moduleStream = dtps.baseURL + "/scripts/assignments.js";
516 fluid.screens.people = dtps.baseURL + "/scripts/people.js";
517 fluid.screens.search = dtps.baseURL + "/scripts/search.js";
518 fluid.screens.pages = dtps.baseURL + "/scripts/pages-discussions.js";
519 fluid.screens.discussions = dtps.baseURL + "/scripts/pages-discussions.js";
jdc6ea0e2022-04-26 16:03:27 -0700520 fluid.screens.gradebook = dtps.baseURL + "/scripts/assignments.js";
jb39e6d92021-01-30 20:34:04 -0800521
522 //Begin fetching class assignments
523 var fetchedAnnouncements = [];
524 dtps.classes.forEach((course, courseIndex) => {
j0f3d7db2026-10-13 04:56:55 +0000525 dtpsLMS.fetchAssignments(course.userID, course.lmsID).then(assignments => {
j29812c42022-04-27 15:41:40 -0700526 //Map due date array
527 const dueDates = assignments.map(a => dtps.dayTimeMinutes(a.dueAt)).filter(d => d !== null).sort((a, b) => a - b);
528
529 if (dueDates && dueDates.length >= 10) {
530 //Get due date IQR
531 var q1 = dueDates[Math.floor((dueDates.length / 5))];
532 var q3 = dueDates[Math.ceil((dueDates.length * (4 / 5)))];
533 var iqr = q3 - q1;
534
535 //Find min and max within reasonable range
536 course.usualDueRange = [(q1 - (iqr * 1.5)) - 120, (q3 + (iqr * 1.5)) + 120];
537 }
538
jb39e6d92021-01-30 20:34:04 -0800539 //Store assignments in the class
540 course.assignments = assignments;
541
542 //Add class props to assignments and add recent assignments to updates array
543 course.assignments.forEach(assignment => {
544 assignment.class = courseIndex;
545
546 if (assignment.gradedAt && assignment.grade) {
547 //Add class number and type to object
548 dtps.updates.push({
549 class: course.num,
550 type: "assignment",
551 ...assignment
552 })
553 }
554 });
555
556 //Sort updates array from newest -> oldest
557 dtps.updates.sort(function (a, b) {
558 //Sort by postedAt (announcements) or gradedAt (assignments)
559 return new Date(b.gradedAt || b.postedAt).getTime() - new Date(a.gradedAt || a.postedAt).getTime()
560 });
561
562 //Keep only the 15 most recent updates
563 if (dtps.updates.length > 15) dtps.updates.length = 15;
564
jb39e6d92021-01-30 20:34:04 -0800565 //Grade history and gradebook
566 if ((course.letter || course.grade) && (course.letter !== "...")) {
567 //Enable gradebook for this class
568 course.hasGradebook = true;
569
jb39e6d92021-01-30 20:34:04 -0800570 //If the class is selected, call dtps.presentClass again to show the grades tab
571 if (courseIndex == dtps.selectedClass) {
572 dtps.presentClass(courseIndex);
573
574 //If the gradebook is selected, reload the gradebook
575 if (dtps.selectedContent == "grades") {
576 fluid.screen('gradebook', dtps.classes[courseIndex].id);
577 }
578 }
579 } else {
580 //This class doesn't have a gradebook, exit gradebook if selected
581 if ((courseIndex == dtps.selectedClass) && (dtps.selectedContent == "grades")) {
582 fluid.screen('stream', dtps.classes[courseIndex].id);
583 }
584 }
585
jb39e6d92021-01-30 20:34:04 -0800586 //Re-render screen if the dashboard or stream is selected
587 if ((dtps.selectedClass == "dash") || ((dtps.selectedContent == "stream") && (dtps.selectedClass == course.num))) {
588 fluid.screen();
j7940eec2020-12-28 14:00:41 -0600589 }
590 });
591
jb39e6d92021-01-30 20:34:04 -0800592 if (!fetchedAnnouncements.includes(course.lmsID)) {
593 //Add lmsID to list of fetched announcements to prevent duplicates
594 fetchedAnnouncements.push(course.lmsID);
j7940eec2020-12-28 14:00:41 -0600595
jb39e6d92021-01-30 20:34:04 -0800596 dtpsLMS.fetchAnnouncements(course.lmsID).then(announcements => {
597 //Add announcements to updates array
598 announcements.forEach(announcement => {
599 //Add class number and type to object
600 dtps.updates.push({
601 class: course.num,
602 type: "announcement",
603 ...announcement
604 });
j7940eec2020-12-28 14:00:41 -0600605 });
606
607 //Sort updates array from newest -> oldest
608 dtps.updates.sort(function (a, b) {
609 //Sort by postedAt (announcements) or gradedAt (assignments)
610 return new Date(b.gradedAt || b.postedAt).getTime() - new Date(a.gradedAt || a.postedAt).getTime()
611 });
612
613 //Keep only the 15 most recent updates
614 if (dtps.updates.length > 15) dtps.updates.length = 15;
615
jb39e6d92021-01-30 20:34:04 -0800616 if (dtps.selectedClass == "dash") {
j7940eec2020-12-28 14:00:41 -0600617 fluid.screen();
618 }
619 });
j7940eec2020-12-28 14:00:41 -0600620 }
621 });
jb39e6d92021-01-30 20:34:04 -0800622
623 //Render remaining HTML
624 dtps.renderLite();
625
626 //Render initial screen
627 fluid.screen();
628
629 //Load popup if needed
630 if (dtps.popup == "firstrun") {
631 dtps.firstrun();
jb39e6d92021-01-30 20:34:04 -0800632 }
j5e67d8e2022-11-08 22:55:04 -0800633
j450fbd42022-09-01 11:13:11 -0700634 //Render inbox
635 if (dtpsLMS.fetchUnreadMessageCount) {
636 dtpsLMS.fetchUnreadMessageCount().then(count => {
637 jQuery("#dtpsUnreadCount span").text(count);
638
639 if (Number(count) > 0) {
640 jQuery("#dtpsUnreadCount").addClass("active");
641 }
642
643 jQuery("#dtpsUnreadCount").show();
644 });
645 }
j7940eec2020-12-28 14:00:41 -0600646 }).catch(function (err) {
647 //Web request error
648 console.error("[DTPS] Error fetching user and classes at dtps.init", err);
649
650 //Check for login redirect
651 if ((err.action == "login") && err.redirectURL) {
652 //Redirect to login page
j6ca9c7e2026-10-13 20:39:55 +0000653 window.location.href = dtps.safeURL(err.redirectURL);
j7940eec2020-12-28 14:00:41 -0600654 } else {
j6ca9c7e2026-10-13 20:39:55 +0000655 dtps.unsafeError("Failed to get user and/or course data", "Exception in promise @ dtps.init");
j7940eec2020-12-28 14:00:41 -0600656 }
657 });
658
659 //Load dashboard prefrences
660 dtps.loadDashboardPrefs();
661}
662
663/**
664 * Formats a date to a readable date string
665 *
666 * @param {Date} date The date to format
667 * @return {string} Formatted date and time string
668 */
669dtps.formatDate = function (date) {
670 if (date) {
671 return new Date(date).toLocaleString("en", { weekday: 'short', month: 'short', day: 'numeric', hour: "numeric", minute: "numeric" });
672 } else {
673 return "";
674 }
675}
676
677/**
678 * Adjusts the height of an iFrame to match its content
679 *
680 * @param {string} iframeID The ID of the iFrame element to adjust
681 */
682dtps.iframeLoad = function (iframeID) {
683 var iFrame = document.getElementById(iframeID);
684 if (iFrame) {
685 iFrame.height = "";
686 iFrame.height = iFrame.contentWindow.document.body.scrollHeight + "px";
687 }
688}
689
690/**
691 * Clears all DTPS data
692 */
693dtps.clearData = function () {
694 if (window.confirm("Clearing Power+ data will clear all local user data stored by Power+. This should be done if it is a new semester / school year or if you are having issues with Power+. Are you sure you want to clear all your Power+ data?")) {
695 window.localStorage.clear()
696 window.alert("Power+ data cleared")
697 }
698}
699
700/**
701 * Renders the class list in the sidebar
702 *
703 * @param {boolean} [override] True if the sidebar should be forcefully re-rendered
704 */
705dtps.showClasses = function (override) {
706 //Array of class HTML for the sidebar
707 dtps.classlist = [];
708
709 var previousClassGroup = null;
710 for (var i = 0; i < dtps.classes.length; i++) {
711 //Determine letter grade HTML
712 var letterGradeHTML = "";
j6ca9c7e2026-10-13 20:39:55 +0000713 if (dtps.classes[i].letter) letterGradeHTML = DOMPurify.sanitize(dtps.classes[i].letter);
j7940eec2020-12-28 14:00:41 -0600714 if (dtps.classes[i].letter == null) letterGradeHTML = "--";
jb39e6d92021-01-30 20:34:04 -0800715 if (dtps.classes[i].letter == "...") letterGradeHTML = `<div class="shimmer" style="vertical-align:middle;display: inline-block;width: 22px;height: 22px;border-radius: 8px;"></div>`; //Show loading indicator for ...
j2566c4e2021-10-01 15:25:49 -0700716 if (dtps.classes[i].letter == "ERROR") letterGradeHTML = `<i class="fluid-icon">error</i>`;
j7940eec2020-12-28 14:00:41 -0600717
718 if (dtps.classes[i].group && (dtps.classes[i].group !== previousClassGroup)) {
719 if (previousClassGroup) dtps.classlist.push(`</div></div>`);
720 dtps.classlist.push(/*html*/`
j6ca9c7e2026-10-13 20:39:55 +0000721 <div id="dtpsClassListGroup-${dtps.escapeAttr(dtps.classes[i].group)}" class="group open">
j7940eec2020-12-28 14:00:41 -0600722 <div class="name item">
j6ca9c7e2026-10-13 20:39:55 +0000723 <i class="fluid-icon"></i> <span class="label">${DOMPurify.sanitize(dtps.classes[i].group)}</span>
j7940eec2020-12-28 14:00:41 -0600724 </div>
725
726 <div class="items">
727 `);
728 } else if (!dtps.classes[i].group && previousClassGroup) {
729 dtps.classlist.push(`</div></div>`);
730 }
731
732 //Add class HTML to array
733 dtps.classlist.push(/*html*/`
734 <div
735 onclick="${'dtps.selectedClass = ' + i}"
736 class="${'class item ' + i + ' ' + (dtps.selectedClass == i ? " active" : "")}"
j6ca9c7e2026-10-13 20:39:55 +0000737 style="${'--classColor: ' + dtps.escapeAttr(dtps.classes[i].color)}"
j7940eec2020-12-28 14:00:41 -0600738 >
jb39e6d92021-01-30 20:34:04 -0800739 ${dtps.classes[i].grade && dtps.classes[i].letter ? /*html*/`
740 <i class="fluid-icon grade">
741 <span class="letter">${letterGradeHTML}</span>
742 <span class="percentage ${Math.round(dtps.classes[i].grade) >= 100 ? "large" : ""}">${Math.round(dtps.classes[i].grade)}<span class="percentSymbol">%</span></span>
743 </i>
744 ` : dtps.classes[i].grade ? /*html*/`
745 <i class="fluid-icon grade percentage ${Math.round(dtps.classes[i].grade) >= 100 ? "large" : ""}">
746 ${Math.round(dtps.classes[i].grade)}<span class="percentSymbol">%</span>
747 </i>
748 ` : /*html*/`
749 <i class="fluid-icon grade letter">
750 ${letterGradeHTML}
751 </i>
752 `}
753
j6ca9c7e2026-10-13 20:39:55 +0000754 <span class="label">${DOMPurify.sanitize(dtps.classes[i].subject)}</span>
j7940eec2020-12-28 14:00:41 -0600755 </div>
756 `);
757
758 previousClassGroup = dtps.classes[i].group;
759 }
760
761 if (previousClassGroup) dtps.classlist.push(`</div></div>`);
762
763 //Only render HTML if the sidebar doesn't already have the classes rendered, or if override is true
764 if (!jQuery(".sidebar .class.dash")[0] || override) {
765 jQuery(".sidebar").html(/*html*/`
766 <div class="title">
767 <img src="${dtps.baseURL + "/icon.svg"}" />
768 <h4>Power+</h4>
769 </div>
770
771 <div class="items">
772 <div onclick="dtps.selectedClass = 'dash';" class="class item main dash ${dtps.selectedClass == "dash" ? "active" : ""}">
773 <i class="fluid-icon">dashboard</i>
774 <span class="label">Dashboard</span>
775 </div>
776
777 <div class="divider"></div>
778
779 ${dtps.classlist.join("")}
780 </div>
781
782 <div class="collapse">
783 <i class="fluid-icon"></i>
784 </div>
785 `);
786 fluid.init();
787
788 //Change view to stream if coming from pages or discussions, since those tabs change the sidebar
789 if ((dtps.selectedContent == "pages") || (dtps.selectedContent == "discuss")) {
790 //Show stream
791 if (dtps.classes[dtps.selectedClass]) fluid.screen('stream', dtps.classes[dtps.selectedClass].id);
792 }
793
794 //Class onclick listener
jb39e6d92021-01-30 20:34:04 -0800795 $(".class").click(function (event) {
j7940eec2020-12-28 14:00:41 -0600796 //Load class content based on what's selected
797 if (((dtps.selectedContent == "stream") || (dtps.selectedContent == "moduleStream")) && dtps.classes[dtps.selectedClass]) {
798 if (dtps.classes[dtps.selectedClass].modules && (window.localStorage.getItem("courseworkPref-" + dtps.classes[dtps.selectedClass].id) == "moduleStream")) {
799 fluid.screen("moduleStream", dtps.classes[dtps.selectedClass].id);
800 } else {
801 fluid.screen("stream", dtps.classes[dtps.selectedClass].id);
802 }
803 }
804
805 if ((dtps.selectedContent == "people") && dtps.classes[dtps.selectedClass]) {
806 fluid.screen("people", dtps.classes[dtps.selectedClass].id);
807 }
808
809 if ((dtps.selectedContent == "grades") && dtps.classes[dtps.selectedClass]) {
810 if (dtps.classes[dtps.selectedClass].hasGradebook) {
811 fluid.screen("gradebook", dtps.classes[dtps.selectedClass].id);
812 } else {
813 fluid.screen("stream", dtps.classes[dtps.selectedClass].id);
814 }
815 }
816
817 if (dtps.selectedClass == "dash") {
818 fluid.screen("dashboard");
819 }
820 });
821 }
822}
823
824/**
825 * Renders the class header (color, name, tabs, etc.) and sets the class as the selected class
826 *
827 * @param {number|string} classNum The class number to load or "dash" if loading the dashboard
828 */
829dtps.presentClass = function (classNum) {
830 //Set classNum as selected class
831 dtps.selectedClass = classNum;
832
833 //Update document title with class name
834 if (dtps.classes[classNum]) {
835 document.title = dtps.classes[classNum].subject + " | Power+";
836 } else {
837 document.title = "Power+";
838 }
839
840 //Set the class image
j4d933ce2022-04-08 21:49:55 +0000841 if ((fluid.get("pref-hideClassImages") != "true") && dtps.classes[classNum] && dtps.classes[classNum].image) {
j7940eec2020-12-28 14:00:41 -0600842 $(".headerArea").addClass("classImage");
843 $(".headerArea img").attr("src", dtps.classes[classNum].image);
844 $(".headerArea img").show();
845 } else {
846 $(".headerArea").removeClass("classImage");
847 $(".headerArea img").hide();
848 }
849
850 //Remove active class from other classes in the sidebar, add the active class to the selected class
851 $(".sidebar .class").removeClass("active");
852 $(".class." + classNum).addClass("active");
853
854 //Update title to show class name
855 //If the dashboard is selected, this is just "Dashboard". Otherwise, this is Class.subject
856 $("#headText span").text(classNum == "dash" ? "Dashboard" : classNum == "search" ? "Search Results" : dtps.classes[classNum] && dtps.classes[classNum].subject);
j0f3d7db2026-10-13 04:56:55 +0000857 var icon = classNum == "dash" ? "dashboard" : classNum == "search" ? "search" : dtps.classes[classNum] && dtps.classes[classNum].icon;
j7940eec2020-12-28 14:00:41 -0600858 if (icon) {
859 $("#headText i").text(icon);
860 $("#headText i").show();
861 } else {
862 $("#headText i").hide();
863 }
864 $("#headText").css("color", (classNum == "dash") || (classNum == "search") ? "var(--text)" : dtps.classes[classNum] && dtps.classes[classNum].color);
865
866 //If the class doesn't exist, hide the tabs
867 //Otherwise, show the tabs
868 if (!dtps.classes[classNum]) {
869 $("#dtpsTabBar").hide();
870 $("#classInfo p").hide();
871 } else {
872 $("#dtpsTabBar").show();
873 }
874
875 //Hide dashboard start date
876 if (classNum !== "search") $(".headerArea .contentLabel").hide();
877
878 //Clear search box if not on the search tab
879 if ((classNum !== "search") && !$("#dtpsMainSearchBox").is(":focus")) {
880 $("#dtpsMainSearchBox").val("");
881 }
882
883 //Set search box content
jd4fc5d82020-12-28 19:38:41 -0600884 dtps.setSearchBox();
j7940eec2020-12-28 14:00:41 -0600885
886 if (dtps.classes[classNum]) {
887 //Show pages tab if the class supports it, otherwise, hide it
888 if (dtps.classes[classNum].pages) {
889 $(".btns .btn.pages").show();
890 } else {
891 $(".btns .btn.pages").hide();
892 }
893
894 //Show people tab if the LMS supports it, otherwise, hide it
895 if (dtps.classes[classNum].people) {
896 $(".btns .btn.people").show();
897 } else {
898 $(".btns .btn.people").hide();
899 }
900
901 //Show pages tab if the class supports it, otherwise, hide it
902 if (dtps.classes[classNum].discussions) {
903 $(".btns .btn.discuss").show();
904 } else {
905 $(".btns .btn.discuss").hide();
906 }
907
908 //Show gradebook if the LMS and the class supports it, otherwise, hide it
j0f3d7db2026-10-13 04:56:55 +0000909 if (dtps.classes[classNum].hasGradebook) {
j7940eec2020-12-28 14:00:41 -0600910 $(".btns .btn.grades").show();
911 } else {
912 $(".btns .btn.grades").hide();
913 }
914
915 //Hide tabs if only one tab is visible
916 if ($("#dtpsTabBar .btn:visible").length < 2) {
917 $("#dtpsTabBar").hide();
918 }
919
920 //Show teacher
921 if (dtps.classes[classNum].teacher) {
922 $("#classInfo .teacher .teacherName").text(dtps.classes[classNum].teacher.name);
923 $("#classInfo .teacher .teacherImage").css("background-image", "url('" + dtps.classes[classNum].teacher.photoURL + "')");
924 $("#classInfo .teacher").show();
925 } else {
926 $("#classInfo .teacher").hide();
927 }
928
929 if (dtps.classes[classNum].homepage) {
930 $("#classInfo .homepage").show();
931 } else {
932 $("#classInfo .homepage").hide();
933 }
j7940eec2020-12-28 14:00:41 -0600934 }
935
j7940eec2020-12-28 14:00:41 -0600936 if (dtps.selectedContent !== "grades") $(".classContent").removeClass("fixedGradeSummary");
937}
938
939/**
940 * Displays the class homepage
941 *
942 * @param {number} num Class number to show the homepage for
943 */
944dtps.classHome = function (num) {
945 //Render loading screen
946 $(".card.details").html(/*html*/`
947 <i onclick="fluid.cards.close('.card.details')" class="fluid-icon close">close</i>
j6ca9c7e2026-10-13 20:39:55 +0000948 <h3 style="font-weight: bold;">${DOMPurify.sanitize(dtps.classes[num].subject)} Homepage</h3>
j7940eec2020-12-28 14:00:41 -0600949
950 <br />
951 <p>Loading...</p>
952 `);
953
954 //Fetch homepage from the LMS
955 dtpsLMS.fetchHomepage(dtps.classes[num].lmsID).then(homepage => {
956 if (homepage) {
j6ca9c7e2026-10-13 20:39:55 +0000957 homepage = dtps.sanitizeContent(homepage);
958
j7940eec2020-12-28 14:00:41 -0600959 //Get computed background and text color to style the iFrame with
960 var computedBackgroundColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--cards");
961 var computedTextColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--text");
962
963 if ($("body").hasClass("dark")) {
964 homepage = dtps.brightenTextForDarkMode(homepage, computedBackgroundColor);
965 }
966
jb39e6d92021-01-30 20:34:04 -0800967 //Generate a blob with the assignment body and get its data URL
968 var blob = new Blob([`
j7940eec2020-12-28 14:00:41 -0600969 <base target="_blank" />
970 <link type="text/css" rel="stylesheet" href="https://cdn.jottocraft.com/CanvasCSS.css" media="screen,projection"/>
971 <style>body {background-color: ${computedBackgroundColor}; color: ${computedTextColor};</style>
972 ${homepage}
973 `], { type: 'text/html' });
jb39e6d92021-01-30 20:34:04 -0800974 var homepageURL = window.URL.createObjectURL(blob);
j7940eec2020-12-28 14:00:41 -0600975
jb39e6d92021-01-30 20:34:04 -0800976 $(".card.details").html(/*html*/`
977 <i onclick="fluid.cards.close('.card.details')" class="fluid-icon close">close</i>
j7940eec2020-12-28 14:00:41 -0600978
j6ca9c7e2026-10-13 20:39:55 +0000979 <h4 style="font-weight: bold;">${DOMPurify.sanitize(dtps.classes[num].subject)} Homepage</h4>
j7940eec2020-12-28 14:00:41 -0600980
jb39e6d92021-01-30 20:34:04 -0800981 <br />
982 <div style="margin-top: 20px;" class="homepageBody">
j6ca9c7e2026-10-13 20:39:55 +0000983 <iframe id="homepageIframe" onload="dtps.iframeLoad('homepageIframe')" style="margin: 10px 0px; width: 100%; border: none; outline: none;" src="${homepageURL}"></iframe>
jb39e6d92021-01-30 20:34:04 -0800984 </div>
985 `);
j7940eec2020-12-28 14:00:41 -0600986
987 fluid.cards(".card.details");
988 } else {
989 fluid.cards.close('.card.details');
990 dtps.error("Homepage unavailable", "homepage is either empty or undefined @ dtps.classHome");
991 }
992 }).catch(e => {
993 dtps.error("Couldn't load homepage", "Caught a promise rejection @ dtps.classHome", e);
994 })
995}
996
997/**
j7940eec2020-12-28 14:00:41 -0600998 * Shows a URL in the iFrame card
999 *
1000 * @param {string} url The URL to load
1001 */
1002dtps.showIFrameCard = function (url) {
1003 //Remove any previous URLs
1004 $('#CardIFrame').attr('src', '');
1005
1006 //Show iFrame card
1007 fluid.cards('.card.iFrameCard');
1008
1009 //Load new URL
j6ca9c7e2026-10-13 20:39:55 +00001010 $('#CardIFrame').attr('src', dtps.safeURL(url));
j7940eec2020-12-28 14:00:41 -06001011}
1012
1013/**
1014 * Brightens text in an HTML string for dark mode
1015 *
1016 * @param {string} html The HTML to brighten text for
1017 * @param {string} [bg] The background color that the HTML will be displayed on
1018 * @returns {string} HTML string with brightened colors
1019 */
1020dtps.brightenTextForDarkMode = function (html, bg) {
1021 //Use dark mode algorithm
1022 if (!bg) bg = "black";
1023 var fakeRoot = $('<div></div>').append(html);
jd80b6e02021-04-19 20:16:38 -07001024
1025 //Reset text color to black if there is a background color set and no other color set
1026 fakeRoot.find("*").filter(function () {
1027 return ($(this).css("background-color") || $(this).css("background")) && !$(this).css("color") && !$(this).parents().filter(function () {
1028 return $(this).css("color");
1029 }).length;
1030 }).toArray().forEach(element => {
1031 //Reset to black
1032 $(element).css("color", "#2D3B45");
1033 });
1034
1035 //Brighten text colors
j7940eec2020-12-28 14:00:41 -06001036 fakeRoot.find("span").filter(function () {
1037 return $(this).css("color") && !($(this).css("background-color") || $(this).css("background")) && !$(this).parents().filter(function () {
1038 return $(this).css("background-color") || $(this).css("background");
1039 }).length;
1040 }).toArray().forEach(element => {
1041 //Brighten color
1042 var brightness = tinycolor($(element).css("color")).getBrightness() / 255 * 100;
1043 var targetBrightness = (100 - (tinycolor(bg).getBrightness() / 255 * 100)) - brightness;
1044 var brightnessDiff = targetBrightness - brightness;
1045
1046 if (brightnessDiff > 0) {
1047 $(element).css("color", "#" + tinycolor($(element).css("color")).brighten(Math.abs(brightnessDiff)).toHex());
1048 } else {
1049 $(element).css("color", "#" + tinycolor($(element).css("color")).darken(Math.abs(brightnessDiff)).toHex());
1050 }
1051 });
jd80b6e02021-04-19 20:16:38 -07001052
j7940eec2020-12-28 14:00:41 -06001053 return fakeRoot.html();
1054}
1055
1056/**
j7940eec2020-12-28 14:00:41 -06001057 * Opens the settings page
1058 *
1059 * @param {boolean} [forceRerenderDashboard] If this is true, the dashboard settings will be re-rendered
1060 */
1061dtps.settings = function (forceRerenderDashboard) {
1062 //Render dashboard HTML if not already loaded
1063 if (forceRerenderDashboard || ($("#leftDashboardColumn").attr("loaded") !== "true")) {
1064 //Returns dashboard item HTML from a dashboard item array
1065 function dashboardHTML(dashboardArray) {
1066 return dashboardArray.map(dashboardItem => {
1067 return /*html*/`
1068 <div dashboardItem-id="${dashboardItem.id}" style="height: ${dashboardItem.size * 1.7 + 50}px" class="dashboardItem">
1069 <h5>
1070 <i class="fluid-icon">${dashboardItem.icon}</i>
1071 <span>${dashboardItem.name}</span>
1072 </h5>
1073 </div>
1074 `;
1075 }).join("");
1076 }
1077
1078 //Render dashboard items
1079 $("#leftDashboardColumn").html(dashboardHTML(dtps.leftDashboard));
1080 $("#rightDashboardColumn").html(dashboardHTML(dtps.rightDashboard));
1081
1082 //Make dashboard items sortable
1083 $(".dashboardColumn").sortable({
1084 connectWith: ".dashboardColumn",
1085 update: function (e, ui) {
1086 dtps.saveDashboardPrefs();
1087 }
1088 });
1089
1090 //Store loaded state to prevent reloading dashboard items
1091 $("#leftDashboardColumn").attr("loaded", "true");
1092 }
1093
j7940eec2020-12-28 14:00:41 -06001094 fluid.cards('.settingsCard');
1095}
1096
1097/**
jdc6ea0e2022-04-26 16:03:27 -07001098 * Enables the reload warning when the user exists settings
j7940eec2020-12-28 14:00:41 -06001099 */
1100dtps.settingsReloadWarning = function () {
jdc6ea0e2022-04-26 16:03:27 -07001101 dtps.reloadPending = true;
j7940eec2020-12-28 14:00:41 -06001102}
1103
1104/**
j7940eec2020-12-28 14:00:41 -06001105 * Saves dashboard prefrences
1106 */
1107dtps.saveDashboardPrefs = function () {
1108 var dashboardPrefs = [];
1109
1110 //Add dashboard items
1111 for (var i = 0; i < $(".dashboardColumn").children().length; i++) {
1112 //Get HTML item
1113 var child = $($(".dashboardColumn").children()[i]);
1114
1115 //Add item to dashboardPrefs array
1116 dashboardPrefs.push({
1117 id: child.attr("dashboardItem-id"),
1118 side: child.parent().attr("id").includes("left") ? "left" : "right"
1119 });
1120 }
1121
1122 //Save to local storage
1123 window.localStorage.setItem("dtpsDashboardItems", JSON.stringify(dashboardPrefs));
1124
1125 //Reload dashboard items
1126 dtps.loadDashboardPrefs();
1127}
1128
1129/**
1130 * Resets dashboard prefrences
1131 */
1132dtps.resetDashboardPrefs = function () {
1133 //Remove dashboard pref from localStorage
1134 window.localStorage.removeItem("dtpsDashboardItems");
1135
1136 //Reload dashboard items
1137 dtps.loadDashboardPrefs();
1138
1139 //Re-render dashboard
1140 dtps.settings(true);
1141}
1142
1143/**
j7940eec2020-12-28 14:00:41 -06001144 * Loads dashboard prefrences
1145 */
1146dtps.loadDashboardPrefs = function () {
1147 //Define left and right dashboard columns
1148 dtps.leftDashboard = [];
1149 dtps.rightDashboard = [];
1150
1151 //Add items to dashboard columns
1152 if (window.localStorage.dtpsDashboardItems) {
1153 //Add from user prefs
1154
1155 //Parse JSON
1156 var dashboardPref = JSON.parse(window.localStorage.dtpsDashboardItems);
1157
1158 //Generate arrays of dashboard item IDs
1159 var dashboardIDs = dtps.dashboardItems.map(item => item.id);
1160
1161 //Add items to dashboard according to prefs
1162 dashboardPref.forEach(dashboardItemPref => {
1163 if (dashboardIDs.includes(dashboardItemPref.id)) {
1164 //Get item index based on dashboardIDs array
1165 var itemIndex = dashboardIDs.indexOf(dashboardItemPref.id);
1166
1167 //Get item from dtps.dashboardItems array
1168 var dashboardItem = dtps.dashboardItems[itemIndex];
1169
1170 //Add item to dashboard
1171 if (dashboardItemPref.side == "left") {
1172 dtps.leftDashboard.push(dashboardItem);
1173 } else if (dashboardItemPref.side == "right") {
1174 dtps.rightDashboard.push(dashboardItem);
1175 }
1176 }
1177 });
1178 } else {
1179 //Add from defaults
1180 dtps.dashboardItems.forEach(dashboardItem => {
1181 if (dashboardItem.defaultSide == "left") {
1182 dtps.leftDashboard.push(dashboardItem);
1183 } else if (dashboardItem.defaultSide == "right") {
1184 dtps.rightDashboard.push(dashboardItem);
1185 }
1186 })
1187 }
1188}
1189
1190/**
1191 * Renders initial static DTPS HTML
1192 */
1193dtps.render = function () {
1194 //Remove all existing link tags and LMS head content
j2fcf4e52021-03-11 14:37:26 -08001195 if (!dtpsLMS.isDemoLMS) {
1196 $("link:not(.dtpsHeadItem)").remove();
1197 $("head *:not(.dtpsHeadItem)").remove();
1198 }
j7940eec2020-12-28 14:00:41 -06001199
1200 //Set default body classes
1201 $("body").attr("class", "dark showThemeWindows hasSidebar hasNavbar dashboard");
1202
1203 //Set document title and favicon
1204 document.title = "Power+";
1205 jQuery("<link/>", {
1206 rel: "shortcut icon",
1207 type: "image/png",
1208 href: dtps.baseURL + "/favicon.png"
1209 }).appendTo("head");
1210
1211 //Remove existing LMS HTML (excluding DTPS loading screen HTML)
1212 jQuery("body *:not(#dtpsNativeOverlay):not(#dtpsNativeOverlay *)").remove();
1213
1214 //Render HTML
1215 jQuery("body").append(/*html*/`
1216 <div class="sidebar"></div>
1217
1218 <div class="navbar">
1219 <div class="logo">
1220 <img src="${dtps.baseURL + "/icon.svg"}" />
j0f3d7db2026-10-13 04:56:55 +00001221 <h4>Power+</h4>
j7940eec2020-12-28 14:00:41 -06001222 </div>
1223
j2fcf4e52021-03-11 14:37:26 -08001224 ${dtps.unstable && !dtpsLMS.isDemoLMS ? `
j7940eec2020-12-28 14:00:41 -06001225 <div id="dtpsUnstable" class="navitem">
1226 <i style="font-size: 16px;" class="fluid-icon">warning</i>
j0f3d7db2026-10-13 04:56:55 +00001227 <span style="font-weight: bold; font-size: 10px;">THIS IS AN UNOFFICIAL VERSION OF POWER+. USE AT YOUR OWN RISK.</span>
j7940eec2020-12-28 14:00:41 -06001228 </div>
1229 ` : ""}
1230
1231 <div class="items" id="dtpsFixedSearch">
1232 <i class="inputIcon fluid-icon">search</i>
1233 <input id="dtpsMainSearchBox" style="margin: 0px; width: 500px;" type="search" class="inputIcon filled" placeholder="Search" />
1234 </div>
1235
jb39e6d92021-01-30 20:34:04 -08001236 <div class="items" style="float: right;">
j450fbd42022-09-01 11:13:11 -07001237 <a style="display: none;" id="dtpsUnreadCount" target="_blank" href="/conversations" class="navitem">
1238 <i class="fluid-icon">inbox</i>
1239 <span></span>
1240 </a>
jb39e6d92021-01-30 20:34:04 -08001241 <div class="navitem" onclick="dtps.settings();">
1242 <i class="fluid-icon">settings</i>
1243 <span>Settings</span>
j7940eec2020-12-28 14:00:41 -06001244 </div>
1245 </div>
j7940eec2020-12-28 14:00:41 -06001246 </div>
1247
1248 <div id="dtpsSearchResults" class="card acrylicMaterial" style="display: none;">
1249 <h5 id="dtpsSearchStatus"><i class="fluid-icon">search</i> <span>Search</span></h5>
1250 <div id="dtpsSearchData" style="display: none;"></div>
1251 <div id="dtpsSearchInfo">
1252 <p>By defualt, Power+ will search based on the page you're on. You can use the keywords below for more advanced searches:</p>
1253 <div class="grid samesize">
1254 <div class="item">
1255 <p><i class="fluid-icon">library_books</i> type:coursework</p>
1256 <p><i class="fluid-icon">view_module</i> type:module</p>
1257 <p><i class="fluid-icon">assignment</i> type:assignment</p>
1258 <p><i class="fluid-icon">assessment</i> type:grade</p>
1259 <p><i class="fluid-icon">announcement</i> type:announcement</p>
1260 </div>
1261 <div class="item">
1262 <p><i class="fluid-icon">home</i> type:homepage</p>
1263 <p><i class="fluid-icon">insert_drive_file</i> type:page</p>
1264 <p><i class="fluid-icon">forum</i> type:discussion</p>
1265 <p><i class="fluid-icon">people</i> type:person</p>
1266 <div class="divider"></div>
1267 <p><i class="fluid-icon">class</i> class:English</p>
1268 </div>
1269 </div>
1270 </div>
1271 </div>
1272
1273 <div class="headerArea classImage">
1274 <img style="display: none;" />
1275 <div class="content">
1276 <h1 id="headText"><i class="fluid-icon">dashboard</i> <span>Dashboard</span></h1>
1277 <div id="classInfo" style="min-height: 18px;">
1278 <p class="teacher" style="display: none;">
1279 <span class="teacherImage"></span> <span class="teacherName"></span>
1280 </p>
1281 <p onclick="dtps.classHome(dtps.selectedClass);" class="homepage" style="cursor: pointer; display: none;">
1282 <i class="fluid-icon">home</i> <span>Homepage</span>
1283 </p>
j7940eec2020-12-28 14:00:41 -06001284 <p class="contentLabel" style="display: none;">
1285 <i class="fluid-icon"></i> <span></span>
1286 </p>
1287 </div>
1288 <div style="display: none;" id="dtpsTabBar" class="btns">
1289 <button init="true" onclick="if (dtps.classes[dtps.selectedClass].modules && (window.localStorage.getItem('courseworkPref-' + dtps.classes[dtps.selectedClass].id) == 'moduleStream')) { fluid.screen('moduleStream', dtps.classes[dtps.selectedClass].id); } else { fluid.screen('stream', dtps.classes[dtps.selectedClass].id); }" class="btn stream">
1290 <i class="fluid-icon">library_books</i>
1291 Coursework
1292 </button>
1293 <button init="true" onclick="fluid.screen('people', dtps.classes[dtps.selectedClass].id);" class="btn people">
1294 <i class="fluid-icon">people</i>
1295 People
1296 </button>
1297 <button init="true" onclick="fluid.screen('discussions', dtps.classes[dtps.selectedClass].id);" class="btn discuss">
1298 <i class="fluid-icon">forum</i>
1299 Discussions
1300 </button>
1301 <button init="true" onclick="fluid.screen('pages', dtps.classes[dtps.selectedClass].id);" class="btn pages">
1302 <i class="fluid-icon">insert_drive_file</i>
1303 Pages
1304 </button>
1305 <button init="true" onclick="fluid.screen('gradebook', dtps.classes[dtps.selectedClass].id);" class="btn grades">
1306 <i class="fluid-icon">assessment</i>
jdc6ea0e2022-04-26 16:03:27 -07001307 Gradebook
j7940eec2020-12-28 14:00:41 -06001308 </button>
1309 </div>
1310 </div>
1311 </div>
1312
1313 <!-- Class content area -->
1314 <div class="classContent">
1315 <div class="spinner"></div>
1316 </div>
1317
1318 <!-- Settings card (its inner HTML is added later) -->
1319 <div style="height: 100%; overflow: auto !important;" class="card withnav focus close container settingsCard"></div>
1320
j0f3d7db2026-10-13 04:56:55 +00001321 <!-- Changelog card (The changelog is removed, but this is also used for the firstrun dialog) -->
j7940eec2020-12-28 14:00:41 -06001322 <div style="border-radius: 30px;" class="card focus changelog close container">
1323 <i onclick="fluid.cards.close('.card.changelog')" class="fluid-icon close">close</i>
1324 <h3>What's new in Power+</h3>
1325 <h5>Loading...</h5>
1326 </div>
1327
1328 <!-- General details card for assignments, outcomes, class info, etc. -->
1329 <div style="border-radius: 30px;" class="card focus details close container">
1330 <i onclick="fluid.cards.close('.card.details')" class="fluid-icon close">close</i>
1331 <p>An error occured</p>
1332 </div>
1333
1334 <!-- General iFrame card (with white background) -->
1335 <div style="border-radius: 30px; top: 50px; background-color: white; color: black;" class="card focus close iFrameCard container">
1336 <i style="color: black !important;" onclick="fluid.cards.close('.card.iFrameCard'); $('#CardIFrame').attr('src', '');" class="fluid-icon close">close</i>
1337 <br /><br />
1338 <iframe style="width: 100%; height: calc(100vh - 175px); border: none;" id="CardIFrame"></iframe>
1339 </div>
1340 `);
1341
1342 $("#dtpsMainSearchBox").on("focus", function () {
1343 $("#dtpsSearchResults").show();
1344 });
1345
1346 $("#dtpsMainSearchBox").on("blur", function () {
1347 $("#dtpsSearchResults").hide();
1348 });
1349
1350 $("#dtpsMainSearchBox").on("input", function () {
1351 dtps.setSearchBox();
1352 });
1353
1354 $(document).on("keydown", "#dtpsMainSearchBox", function (e) {
1355 if (e.key == "Enter") {
1356 //Validate input and tags
1357 var term = $("#dtpsMainSearchBox").val().replace(/(type|class):[a-z]*/gi, "").trim();
1358 if ($("#dtpsMainSearchBox").attr("data-search-type") && $("#dtpsMainSearchBox").attr("data-dtps-course")) {
jd4fc5d82020-12-28 19:38:41 -06001359 fluid.screen("search", {
1360 term: term,
1361 type: $("#dtpsMainSearchBox").attr("data-search-type"),
1362 course: $("#dtpsMainSearchBox").attr("data-dtps-course"),
1363 ctxType: $("#dtpsMainSearchBox").attr("data-ctx-type"),
1364 ctxCourse: $("#dtpsMainSearchBox").attr("data-ctx-course")
1365 });
j7940eec2020-12-28 14:00:41 -06001366 $("#dtpsMainSearchBox").blur();
1367 }
1368 }
1369 });
1370}
1371
1372/**
1373 * Sets the search box text based on the current page or keywords
1374 */
1375dtps.setSearchBox = function () {
1376 var value = $("#dtpsMainSearchBox").val() || "";
1377
1378 var type = null;
1379 var course = dtps.selectedClass == "dash" ? "dash" : dtps.classes[dtps.selectedClass];
1380 var icon = null;
1381 var error = false;
1382 var autoType = null;
1383 var autoCourse = dtps.selectedClass == "dash" ? "dash" : dtps.classes[dtps.selectedClass];
1384
1385 //Get automatic type from selected content
1386 if (dtps.selectedContent == "people") type = "people";
1387 if (dtps.selectedContent == "discuss") type = "discussions";
1388 if (dtps.selectedContent == "pages") type = "pages";
1389 if (dtps.selectedContent == "grades") type = "grades";
1390 if ((dtps.selectedClass == "dash") || (dtps.selectedContent == "stream") || (dtps.selectedContent == "moduleStream")) type = "coursework";
jb39e6d92021-01-30 20:34:04 -08001391 autoType = type;
1392
j7940eec2020-12-28 14:00:41 -06001393 //Reuse auto type if on search
1394 if (dtps.selectedClass == "search") {
1395 type = $("#dtpsMainSearchBox").attr("data-ctx-type");
1396 course = $("#dtpsMainSearchBox").attr("data-ctx-course");
1397 if (!isNaN(Number(course))) course = dtps.classes[course];
1398 }
1399
1400 //Check for type override from search box
1401 if (value.split(" ").includes("type:coursework")) type = "coursework";
1402 if (value.split(" ").includes("type:homepage")) type = "homepages";
1403 if (value.split(" ").includes("type:page")) type = "pages";
1404 if (value.split(" ").includes("type:discussion")) type = "discussions";
1405 if (value.split(" ").includes("type:grade")) type = "grades";
1406 if (value.split(" ").includes("type:person")) type = "people";
1407 if (value.split(" ").includes("type:assignment")) type = "assignments";
1408 if (value.split(" ").includes("type:module")) type = "modules";
1409 if (value.split(" ").includes("type:announcement")) type = "announcements";
1410 if (value.split(" ").includes("type:all")) type = "everything";
1411
1412 //Get icon from final type
1413 if (type == "coursework") icon = "library_books";
1414 if (type == "people") icon = "people";
1415 if (type == "discussions") icon = "forum";
1416 if (type == "pages") icon = "insert_drive_file";
1417 if (type == "grades") icon = "assessment";
1418 if (type == "assignments") icon = "assignment";
1419 if (type == "modules") icon = "view_module";
1420 if (type == "homepages") icon = "home";
1421 if (type == "announcements") icon = "announcement";
1422 if (type == "everything") icon = "warning";
1423
1424 //Check for course override from search box
1425 if (value.includes("class:")) {
1426 var partialSubject = value.split("class:")[1].split(" ")[0].toLowerCase();
1427 if (partialSubject == "all") {
1428 course = "all";
1429 } else if (partialSubject) {
1430 dtps.classes.forEach(c => {
1431 if (c.subject.toLowerCase().includes(partialSubject)) {
1432 course = c;
1433 }
1434 });
1435 }
1436 }
1437
1438 //Check if the course supports the type
1439 if ((course !== "dash") && (course !== "all")) {
1440 if ((type == "pages") && !course.pages) error = true;
1441 if ((type == "discussions") && !course.discussions) error = true;
1442 if ((type == "modules") && !course.modules) error = true;
1443 if ((type == "homepages") && !course.homepage) error = true;
1444 if ((type == "people") && !course.people) error = true;
1445 }
1446
1447 if ((course == "dash") || (course == "all")) {
1448 $("#dtpsSearchStatus i").text(icon);
1449 $("#dtpsSearchStatus span").text("Search " + (type == "everything" ? type : "all " + type));
1450 $("#dtpsMainSearchBox").attr("placeholder", "Search " + (type == "everything" ? type : "all " + type));
1451 $("#dtpsMainSearchBox").attr("data-dtps-course", "all");
1452 $("#dtpsMainSearchBox").attr("data-search-type", type);
1453 } else if (error) {
1454 $("#dtpsSearchStatus i").text("error");
j6ca9c7e2026-10-13 20:39:55 +00001455 $("#dtpsSearchStatus span").html(`Cannot search for ${DOMPurify.sanitize(type)} in <b style="color: ${dtps.escapeAttr(course.color)};">${DOMPurify.sanitize(course.subject)}</b>`);
j7940eec2020-12-28 14:00:41 -06001456 $("#dtpsMainSearchBox").attr("placeholder", "Cannot search for " + type + " in " + course.subject);
1457 $("#dtpsMainSearchBox").attr("data-dtps-course", "");
1458 $("#dtpsMainSearchBox").attr("data-search-type", "");
1459 } else if (course || true) {
1460 $("#dtpsSearchStatus i").text(icon);
j6ca9c7e2026-10-13 20:39:55 +00001461 $("#dtpsSearchStatus span").html(`Search ${DOMPurify.sanitize(type)} in <b style="color: ${dtps.escapeAttr(course.color)};">${DOMPurify.sanitize(course.subject)}</b>`);
j7940eec2020-12-28 14:00:41 -06001462 $("#dtpsMainSearchBox").attr("placeholder", "Search " + type + " in " + course.subject);
1463 $("#dtpsMainSearchBox").attr("data-dtps-course", course.num);
1464 $("#dtpsMainSearchBox").attr("data-search-type", type);
1465 }
1466
1467 //Set auto type
1468 if (dtps.selectedClass !== "search") {
1469 $("#dtpsMainSearchBox").attr("data-ctx-type", autoType);
1470 $("#dtpsMainSearchBox").attr("data-ctx-course", autoCourse == "dash" ? "dash" : autoCourse.num);
1471 }
1472}
1473
1474/**
1475 * Renders basic content after the user has been loaded
1476 */
1477dtps.renderLite = function () {
1478 //Add hideGrades body class if enabled and preference listener
1479 if (fluid.get("pref-hideGrades") == "true") { jQuery('body').addClass('hidegrades'); }
1480 document.addEventListener("pref-hideGrades", function (e) {
1481 if ((e.detail == "true") || (e.detail == true)) {
1482 //hideGrades has been enabled, add class to body to hide grades via CSS
1483 jQuery('body').addClass('hidegrades');
1484 } else {
1485 //hideGrades has been disabled, remove class from body to show grades
1486 jQuery('body').removeClass('hidegrades');
1487 }
1488 });
1489
j5bcb1122021-05-25 12:53:21 -07001490 //Add alternateFont body class if enabled and preference listener
1491 if (fluid.get("pref-alternateFont") == "true") { jQuery('body').addClass('alternateFont'); }
1492 document.addEventListener("pref-alternateFont", function (e) {
1493 if ((e.detail == "true") || (e.detail == true)) {
1494 //alternateFont has been enabled, add class to body to change font
1495 jQuery('body').addClass('alternateFont');
1496 } else {
1497 //alternateFont has been disabled, remove class from body to revert font change
1498 jQuery('body').removeClass('alternateFont');
1499 }
1500 });
1501
jdc6ea0e2022-04-26 16:03:27 -07001502 /**
1503 * A callback for blocking Fluid UI card closes
1504 */
1505 dtps.closeScreen = function () {
1506 if (dtps.reloadPending) {
1507 jQuery("body").addClass("requiredModal");
1508 fluid.alert("Reload required", "Some of the settings you've changed require a reload to take effect.", "refresh", [
1509 { name: "Reload Power+", icon: "refresh", action: () => window.location.reload() }
1510 ], "var(--theme)");
1511 return true;
1512 }
1513
1514 return false;
1515 }
1516
j7940eec2020-12-28 14:00:41 -06001517 //Render settings card
1518 var baseHost = new URL(dtps.baseURL).hostname;
1519 jQuery(".card.settingsCard").html(/*html*/`
1520 <i onclick="fluid.cards.close('.card.settingsCard')" class="fluid-icon close">close</i>
1521
1522 <div style="position: fixed; height: calc(100% - 100px);" class="sidenav">
1523 <div class="title">
1524 <img src="${dtps.baseURL + "/icon.svg"}" style="width: 50px;vertical-align: middle;padding: 7px; padding-top: 14px;" />
1525 <div style="vertical-align: middle; display: inline-block;">
1526 <h5 style="font-weight: bold;display: inline-block;vertical-align: middle;">Power+</h5>
j5e67d8e2022-11-08 22:55:04 -08001527 <p>
1528 <span style="vertical-align: middle;">${dtps.readableVer}</span>
j5e67d8e2022-11-08 22:55:04 -08001529 </p>
1530 ${(dtps.unstable ? `<p style="font-size: 12px; color: red; margin-top: 6px;">UNSTABLE</p>` : "")}
j7940eec2020-12-28 14:00:41 -06001531 </div>
1532 </div>
1533
j423ed602021-06-01 21:36:17 -07001534 <div onclick="$('.abtpage').hide();$('.abtpage.settings').show();" class="item active">
j7940eec2020-12-28 14:00:41 -06001535 <i class="fluid-icon">settings</i> Settings
1536 </div>
j423ed602021-06-01 21:36:17 -07001537 <div onclick="$('.abtpage').hide();$('.abtpage.theme').show();" class="item">
jb39e6d92021-01-30 20:34:04 -08001538 <i class="fluid-icon">format_paint</i> Theme
1539 </div>
j423ed602021-06-01 21:36:17 -07001540 <div onclick="$('.abtpage').hide();$('.abtpage.dashboard').show();" class="item">
j7940eec2020-12-28 14:00:41 -06001541 <i class="fluid-icon">dashboard</i> Dashboard
1542 </div>
1543 ${dtps.env == "dev" ? /*html*/`
j423ed602021-06-01 21:36:17 -07001544 <div onclick="$('.abtpage').hide();$('.abtpage.debugging').show();" class="item">
j7940eec2020-12-28 14:00:41 -06001545 <i class="fluid-icon">bug_report</i> Debugging
1546 </div>
j7940eec2020-12-28 14:00:41 -06001547 ` : ``}
j423ed602021-06-01 21:36:17 -07001548 <div onclick="$('.abtpage').hide();$('.abtpage.about').show();" class="item abt">
j7940eec2020-12-28 14:00:41 -06001549 <i class="fluid-icon">info</i> About
1550 </div>
1551 </div>
1552
1553 <div style="min-height: 100%" class="content">
1554 <div class="abtpage settings">
1555 <h5><b>Settings</b></h5>
j0f3d7db2026-10-13 04:56:55 +00001556
1557 ${dtpsLMS.dtech ? `<p style="color: var(--text);"><b>As of October 2026, all d.tech-specific features, including CBL grade calculation, have been removed from Power+.</b></p>` : ``}
j7adec892020-12-31 10:56:28 -06001558
j7940eec2020-12-28 14:00:41 -06001559 <br />
1560 <p>Sidebar</p>
1561
1562 <div onclick="fluid.set('pref-hideGrades');" class="switch pref-hideGrades"><span class="head"></span></div>
1563 <div class="label"><i class="fluid-icon">visibility_off</i> Hide class grades</div>
1564
j7940eec2020-12-28 14:00:41 -06001565 <br /><br />
1566 <p>Classes</p>
1567
1568 <div onclick="fluid.set('pref-fullNames'); dtps.settingsReloadWarning();" class="switch pref-fullNames"><span class="head"></span></div>
1569 <div class="label"><i class="fluid-icon">title</i> Show full class names</div>
1570
1571 <br /><br />
j29812c42022-04-27 15:41:40 -07001572 <div onclick="fluid.set('pref-hideClassImages'); fluid.screen();" class="switch pref-hideClassImages"><span class="head"></span></div>
j7940eec2020-12-28 14:00:41 -06001573 <div class="label"><i class="fluid-icon">image</i> Hide class images</div>
1574
j608526f2022-04-26 20:32:47 -07001575 ${dtpsLMS.shortName === "Canvas" ? /*html*/`
1576 <br /><br />
1577 <div onclick="fluid.set('pref-showAllClasses'); dtps.settingsReloadWarning();" class="switch pref-showAllClasses"><span class="head"></span></div>
jd88b8432022-06-12 15:37:35 -07001578 <div class="label"><i class="fluid-icon">visibility</i> Show all published classes, including those which may have ended</div>
j608526f2022-04-26 20:32:47 -07001579 ` : ""}
1580
1581 <br /><br />
1582 <p>Assignments</p>
1583
j29812c42022-04-27 15:41:40 -07001584 <div onclick="fluid.set('pref-unusualDueDates'); fluid.screen();" class="switch pref-unusualDueDates active"><span class="head"></span></div>
j608526f2022-04-26 20:32:47 -07001585 <div class="label"><i class="fluid-icon">highlight</i> Highlight outlying due dates</div>
1586
j0f3d7db2026-10-13 04:56:55 +00001587 <div id="dtpsPrereleaseTesting" style="${window.localStorage.prereleaseEnabled || (dtps.env == "dev") ? "" : "display: none;"}">
j7940eec2020-12-28 14:00:41 -06001588 <br /><br />
j0f3d7db2026-10-13 04:56:55 +00001589 <p>Release mode</p>
j7940eec2020-12-28 14:00:41 -06001590
1591 <div>
1592 <div class="btns row small">
1593 <button
1594 onclick="window.localStorage.setItem('dtpsLoaderPref', 'prod')"
j0f3d7db2026-10-13 04:56:55 +00001595 class="btn ${window.localStorage.dtpsLoaderPref !== "local" ? "active" : ""}">
j7940eec2020-12-28 14:00:41 -06001596 <i class="fluid-icon">label</i> Production
1597 </button>
j7940eec2020-12-28 14:00:41 -06001598 <button
1599 onclick="window.localStorage.setItem('dtpsLoaderPref', 'local')"
1600 class="btn ${window.localStorage.dtpsLoaderPref == "local" ? "active" : ""}">
1601 <i class="fluid-icon">developer_board</i> Local
1602 </button>
1603 </div>
1604 </div>
1605 </div>
1606
1607 </div>
1608
jb39e6d92021-01-30 20:34:04 -08001609 <div style="display: none;" class="abtpage theme">
1610 <h5><b>Theme</b></h5>
1611 <br />
1612 <div class="themeSelectionUI flat"></div>
1613 </div>
j7940eec2020-12-28 14:00:41 -06001614
j7940eec2020-12-28 14:00:41 -06001615 <div style="display: none;" class="abtpage dashboard">
1616 <h5><b>Dashboard</b></h5>
1617 <p>You can rearrange the items shown on the dashboard by dragging them below. You might have to reload Power+ for changes to take effect.</p>
1618
1619 <button onclick="dtps.resetDashboardPrefs();" class="btn small"><i class="fluid-icon">refresh</i> Reset dashboard layout</button>
1620
1621 <br />
1622
1623 <div id="leftDashboardColumn" class="dashboardColumn"></div>
1624
1625 <div id="rightDashboardColumn" class="dashboardColumn"></div>
1626 </div>
1627
1628 ${dtps.env == "dev" ? /*html*/`
1629 <div style="display: none;" class="abtpage debugging">
1630 <h5><b>Debugging</b></h5>
jd88b8432022-06-12 15:37:35 -07001631 <p>These settings are for development purposes only and might break Power+. Use at your own risk.</p>
j7940eec2020-12-28 14:00:41 -06001632
1633 <div>
1634 <button onclick="dtps.firstrun()" class="btn small"><i class="fluid-icon">web_asset</i> Show firstrun screen</button>
1635 </div>
1636
1637 <br /><br />
1638
1639 <h5>Release configuration</h5>
1640
j0f3d7db2026-10-13 04:56:55 +00001641 <button onclick="['dtpsLoaderPref', 'prereleaseEnabled', 'dtpsLMSOverride'].forEach(k => window.localStorage.removeItem(k)); window.location.reload();" class="btn small"><i class="fluid-icon">cancel</i> Clear release configurations</button>
j7940eec2020-12-28 14:00:41 -06001642 <br /><br />
1643
1644 <div>
j6ca9c7e2026-10-13 20:39:55 +00001645 <input id="dtpsLMSOverride" value="${dtps.escapeAttr(window.localStorage.dtpsLMSOverride || "")}" placeholder="LMS override" />
j7940eec2020-12-28 14:00:41 -06001646 <button class="btn small" onclick="window.localStorage.setItem('dtpsLMSOverride', $('#dtpsLMSOverride').val())"><i class="fluid-icon">save</i> Save</button>
1647 </div>
j7940eec2020-12-28 14:00:41 -06001648 </div>
1649 ` : ``}
1650
1651 <div style="display: none;" class="abtpage about">
1652 <h5><b>About</b></h5>
1653
1654 <div class="card" style="padding: 10px 20px; box-shadow: none !important; border: 2px solid var(--elements); margin-top: 20px;">
1655 <img src="${dtps.baseURL + "/icon.svg"}" style="height: 50px; margin-right: 10px; vertical-align: middle; margin-top: 20px;" />
1656
1657 <div style="display: inline-block; vertical-align: middle;">
j0f3d7db2026-10-13 04:56:55 +00001658 <h4 id="dtpsAboutName" style="font-weight: bold; font-size: 32px; margin-bottom: 0px; user-select: none;">Power+</h4>
j7940eec2020-12-28 14:00:41 -06001659 <div style="font-size: 16px; margin-top: 5px;">
1660 ${dtps.readableVer}
j47ec9482026-10-13 21:04:37 +00001661 <div style="display: inline-block;margin: 0px 5px;font-size: 12px;">${baseHost !== "dtps.jottocraft.com" ? `(from ${baseHost})` : ""}</div>
j7940eec2020-12-28 14:00:41 -06001662 </div>
1663 </div>
1664
j0f3d7db2026-10-13 04:56:55 +00001665 <div style="margin-top: 15px; margin-bottom: 7px;">
1666 <a style="color: var(--lightText); margin: 0px 5px;" href="https://jottocraft.com/contact"><i class="fluid-icon" style="vertical-align: middle">email</i> Contact me</a>
j7940eec2020-12-28 14:00:41 -06001667 </div>
1668 </div>
1669
1670 <div class="card" style="padding: 10px 20px; box-shadow: none !important; border: 2px solid var(--elements); margin-top: 20px;">
1671 <div style="margin-top: 12px;">
j6ca9c7e2026-10-13 20:39:55 +00001672 <img src="${dtps.escapeAttr(dtps.user.photoURL)}" style="height: 50px; margin-right: 10px; vertical-align: middle; border-radius: 50%;" />
j7940eec2020-12-28 14:00:41 -06001673
1674 <div style="display: inline-block; vertical-align: middle;">
j6ca9c7e2026-10-13 20:39:55 +00001675 <h4 style="font-weight: bold; font-size: 32px; margin: 0px;">${DOMPurify.sanitize(dtps.user.name)} <span style="font-size: 12px; line-height: 0px;">${DOMPurify.sanitize(dtps.user.id)}</span></h4>
j7940eec2020-12-28 14:00:41 -06001676 </div>
1677 </div>
1678
1679 <div style="margin-top: 15px; margin-bottom: 7px;">
1680 <a style="color: var(--lightText); margin: 0px 5px;" href="/logout"><i class="fluid-icon" style="vertical-align: middle">exit_to_app</i> Logout</a>
1681 </div>
1682 </div>
1683
1684 <div class="card" style="padding: 10px 20px; box-shadow: none !important; border: 2px solid var(--elements); margin-top: 20px;">
j6ca9c7e2026-10-13 20:39:55 +00001685 <img src="${dtps.escapeAttr(dtpsLMS.logo)}" style="height: 50px; margin-right: 10px; vertical-align: middle; margin-top: 20px; border-radius: 50%;" />
j7940eec2020-12-28 14:00:41 -06001686
1687 <div style="display: inline-block; vertical-align: middle;">
j6ca9c7e2026-10-13 20:39:55 +00001688 <h4 style="font-weight: bold; font-size: 32px; margin-bottom: 0px;">${DOMPurify.sanitize(dtpsLMS.name)}</h4>
j7940eec2020-12-28 14:00:41 -06001689 ${dtpsLMS.description ? `
j6ca9c7e2026-10-13 20:39:55 +00001690 <div style="font-size: 16px; margin-top: 5px;">${DOMPurify.sanitize(dtpsLMS.description)}</div>
j7940eec2020-12-28 14:00:41 -06001691 ` : ``}
1692 </div>
1693
1694 <div style="margin-top: 15px; margin-bottom: 7px;">
j6ca9c7e2026-10-13 20:39:55 +00001695 <a style="color: var(--lightText); margin: 0px 5px;" href="${dtps.escapeAttr(dtpsLMS.source)}"><i class="fluid-icon" style="vertical-align: middle">code</i> LMS integration source code</a>
j7940eec2020-12-28 14:00:41 -06001696 </div>
1697 </div>
1698
1699 <div class="card advancedOptions" style="padding: 8px 16px; box-shadow: none !important; border: 2px solid var(--elements); margin-top: 20px; ${dtps.env == "dev" ? `` : `display: none;`}">
1700 <div style="display: inline-block; vertical-align: middle;">
1701 <h4 style="font-weight: bold; font-size: 28px; margin-bottom: 0px;">Advanced Options</h4>
1702 </div>
1703
j5bcb1122021-05-25 12:53:21 -07001704 <br /><br />
1705 <div onclick="fluid.set('pref-alternateFont')" class="switch pref-alternateFont"><span class="head"></span></div>
1706 <div class="label"><i class="fluid-icon">font_download</i> Use Alternate Font</div>
1707 <br /><br />
1708
j7940eec2020-12-28 14:00:41 -06001709 <div style="margin-top: 15px; margin-bottom: 7px;">
1710 <a style="color: var(--lightText); margin: 0px 5px; cursor: pointer;" onclick="dtps.clearData();"><i class="fluid-icon" style="vertical-align: middle">refresh</i> Reset Power+</a>
j0f3d7db2026-10-13 04:56:55 +00001711 <a style="color: var(--lightText); margin: 0px 5px; cursor: pointer;" onclick="if (confirm('Only enable Local Development Mode if you are modifying the Power+ source code on your device. Proceeding could allow unauthorized scripts to load, which can cause security issues. Are you sure you want to continue?')) {window.localStorage.prereleaseEnabled = 'true'; $('#dtpsPrereleaseTesting').show(); alert('Local Development Mode can be enabled by going to Settings -> Release mode');}"><i class="fluid-icon" style="vertical-align: middle">code</i> Allow Local Development Mode</a>
j7940eec2020-12-28 14:00:41 -06001712 </div>
1713 </div>
1714
1715 <br />
1716 ${dtps.env == "dev" ? `` : `<p style="cursor: pointer; color: var(--secText, gray)" onclick="$('.advancedOptions').show(); $(this).hide();" class="advOp">Show advanced options</p>`}
1717
1718 <div style="text-align: center; padding: 50px 0px;">
jdc6ea0e2022-04-26 16:03:27 -07001719 <a href="https://jottocraft.com">
1720 <img style="height: 38px; margin-right: 10px; vertical-align: middle;" src="https://cdn.jottocraft.com/images/footerImage.png" />
1721 <h5 style="display: inline-block; vertical-align: middle; color: var(--text);">jottocraft</h5>
1722 </a>
j0f3d7db2026-10-13 04:56:55 +00001723 <p>Copyright (c) jottocraft 2018-2026. Power+ is <a href="https://jottocraft.com/oss">open source</a>.
j7940eec2020-12-28 14:00:41 -06001724 </div>
1725 </div>
1726 </div>
1727 `);
1728
j7940eec2020-12-28 14:00:41 -06001729 //Load Fluid UI
1730 fluid.onLoad();
1731
1732 //Render sidebar
1733 dtps.showClasses();
1734
1735 //Remove loading screen styles
1736 jQuery("#dtpsNativeOverlay style").remove();
1737
1738 //Fade out loading screen
1739 jQuery("#dtpsNativeOverlay").css("opacity", "0");
1740
1741 //Remove loading screen after the animation is complete
1742 setTimeout(() => jQuery("#dtpsNativeOverlay").remove(), 200);
1743}
1744
1745//Start loading DTPS
1746dtps.init();
1747
1748//LMS Integration documentation -------------------------------------------------------------------------------------
1749
1750/**
1751 * @namespace dtpsLMS
1752 * @description Global DTPS LMS integration object. All LMS-related tasks, such as fetching data, are handled by this object. This is always loaded first.
1753 * @global
1754 * @property {string} name Full LMS name
1755 * @property {string} [shortName] Short LMS name
1756 * @property {string} legalName Legal name (or names) to show in the "Welcome to Power+" disclaimer
1757 * @property {string} [description] A short description of the LMS integration provided
1758 * @property {string} logo LMS logo image URL
1759 * @property {string} url URL to the LMS' website
1760 * @property {string} source URL to the LMS integration's source code
j450fbd42022-09-01 11:13:11 -07001761 * @property {string} [inboxURL] URL to the LMS inbox. Required only if dtpsLMS.fetchUnreadMessageCount count is implemented
j7940eec2020-12-28 14:00:41 -06001762 * @property {boolean} [dtech] True if this LMS is d.tech
j7940eec2020-12-28 14:00:41 -06001763 */
1764
1765/**
1766 * @name dtpsLMS.fetchUser
1767 * @description [REQUIRED] Fetches data for the current user from the LMS. If the user is not signed in, reject with an object that looks like {action: "login", redirectURL: "..."} to login the user.
1768 * @kind function
1769 * @return {Promise<User>} A promise which resolves to a User object
1770 */
1771
1772/**
j450fbd42022-09-01 11:13:11 -07001773 * @name dtpsLMS.fetchUnreadMessageCount
1774 * @description [OPTIONAL] Fetches the unread message count for the current user
1775 * @kind function
1776 * @return {Promise<string>} A promise which resolves to a string depicting the count of unread messages
1777 */
1778
1779/**
j7940eec2020-12-28 14:00:41 -06001780* @name dtpsLMS.fetchClasses
1781* @description [REQUIRED] Fetches class data from the LMS
1782* @kind function
1783* @param {string} userID The user ID to fetch classes for
1784* @return {Promise<Class[]>} A promise which resolves to an array of Class objects
1785*/
1786
1787/**
1788* @name dtpsLMS.fetchAssignments
1789* @description [REQUIRED] Fetches assignment data for a course from the LMS
1790* @kind function
1791* @param {string} userID The user ID to fetch assignments for
1792* @param {string} classID The class ID to fetch assignments for
1793* @return {Promise<Assignment[]>} A promise which resolves to an array of Assignment objects
1794*/
1795
1796/**
1797* @name dtpsLMS.fetchModules
1798* @description [OPTIONAL] Fetches module data for a course from the LMS
1799* @kind function
1800* @param {string} userID The user ID to fetch modules for
1801* @param {string} classID The class ID to fetch modules for
1802* @return {Promise<Module[]>} A promise which resolves to an array of Module objects
1803*/
1804
1805/**
1806* @name dtpsLMS.collapseModule
1807* @description [OPTIONAL] Collapses a module in the LMS
1808* @kind function
1809* @param {string} classID The ID of the class
1810* @param {string} moduleID The ID of the module to collapse
1811* @param {boolean} collapsed True if the module is collapsed, false otherwise
1812* @return {Promise} A promise which resolves when the operation is completed
1813*/
1814
1815/**
1816* @name dtpsLMS.collapseAllModules
1817* @description [OPTIONAL] Collapses all modules in the LMS
1818* @kind function
1819* @param {string} classID The ID of the class
1820* @param {boolean} collapsed True if all modules should be collapsed, false otherwise
1821* @return {Promise} A promise which resolves when the operation is completed
1822*/
1823
1824/**
1825* @name dtpsLMS.fetchAnnouncements
1826* @description [OPTIONAL] Fetches recent announcements for a course from the LMS
1827* @kind function
1828* @param {string} classID The class ID to fetch announcements for
1829* @return {Promise<Announcement[]>} A promise which resolves to an array of Announcement objects
1830*/
1831
1832/**
j7940eec2020-12-28 14:00:41 -06001833* @name dtpsLMS.fetchHomepage
1834* @description [OPTIONAL] Fetches homepage HTML for a course from the LMS
1835* @kind function
1836* @param {string} classID The class ID to get the homepage for
1837* @return {Promise<string>} A promise which resolves to the HTML for the class homepage
1838*/
1839
1840/**
1841* @name dtpsLMS.fetchUsers
1842* @description [OPTIONAL] Fetches the users for a course from the LMS
1843* @kind function
1844* @param {string} classID The class ID to fetch users for
1845* @return {Promise<ClassSection[]>} A promise which resolves to an array of sections in this class
1846*/
1847
1848/**
1849* @name dtpsLMS.fetchDiscussionThreads
1850* @description [OPTIONAL] Fetches discussion threads for a course from the LMS
1851* @kind function
1852* @param {string} classID The class ID to fetch discussion threads for
1853* @return {Promise<PartialDiscussionThread[]>} A promise which resolves to an array of partial Discussion Thread objects
1854*/
1855
1856/**
1857* @name dtpsLMS.fetchDiscussionPosts
1858* @description [REQUIRED IF dtpsLMS.fetchDiscussionThreads IS IMPLEMENTED] Fetches discussion posts in a thread from the LMS
1859* @kind function
1860* @param {string} classID The class ID to fetch discussion posts for
1861* @param {string} threadID The discussion thread ID to fetch discussion posts for
1862* @return {Promise<DiscussionThread>} A promise which resolves to a full discussion thread object
1863*/
1864
1865/**
1866* @name dtpsLMS.fetchPages
1867* @description [OPTIONAL] Fetches pages for a course from the LMS
1868* @kind function
1869* @param {string} classID The class ID to fetch pages for
1870* @return {Promise<PartialPage[]>} A promise which resolves to an array of partial page objects
1871*/
1872
1873/**
1874* @name dtpsLMS.fetchPageContent
1875* @description [REQUIRED IF dtpsLMS.fetchPages IS IMPLEMENTED] Fetches content for a page from the LMS
1876* @kind function
1877* @param {string} classID The class ID to fetch page content for
1878* @param {string} pageID The page ID to fetch page content for
1879* @return {Promise<Page>} A promise which resolves to a full DTPS page object
1880*/
1881
1882/**
j7940eec2020-12-28 14:00:41 -06001883* @name dtpsLMS.isUsualDueDate
1884* @description [OPTIONAL, INSTITUTION ONLY] This function returns true if the due date provided is usual/expected and false if the due date is unusual/expected. If the due date is unusual, it is shown in bold in the UI. For institutions where there is a pattern/standard for due dates between classes.
1885* @kind function
1886* @param {Date} date The due date to check
1887* @return {boolean} True if the due date is usual, false if the due date is unusual/unexpected.
1888*/
1889
1890/**
1891* @name dtpsLMS.updateAssignments
1892* @description [OPTIONAL, INSTITUTION ONLY] This function can be implemented by institution-specific scripts to loop through and override assignment data returned by the LMS.
1893* @kind function
1894* @param {Assignment[]} assignments Original assignments array
jdc6ea0e2022-04-26 16:03:27 -07001895* @param {Class} course The class that the assignment is in
j7940eec2020-12-28 14:00:41 -06001896* @return {Promise<Assignment[]>} A promise that resolves to the updated assignments array
1897*/
1898
1899/**
1900* @name dtpsLMS.updateClasses
1901* @description [OPTIONAL, INSTITUTION ONLY] This function can be implemented by institution-specific scripts to loop through and override class data returned by the LMS.
1902* @kind function
1903* @param {Class[]} classes Original classes array
1904* @return {Promise<Class[]>} A promise that resolves to the updated classes array
1905*/
1906
1907//Type definitions -------------------------------------------------------------------------------------
1908
1909/**
1910 * @typedef {string|Date} Date
1911 * @description A date string recognized by {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse|Date.parse} or an actual {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date|Date} object
1912 */
1913
1914/**
1915 * @typedef {Object} User
1916 * @description Defines user objects in DTPS
1917 * @property {string} name User name
1918 * @property {string} id User ID
1919 * @property {string} photoURL User photo URL
1920 * @property {string} url [ONLY FOR DTPSLMS.FETCHUSERS] The URL to this user's profile. Only used when displaying users in the people tab.
1921 * @property {User[]} [children] [ONLY FOR DTPS.USER] Array of child users. If this is defined, the user is treated as a parent account. Sub-children are not allowed.
1922 * @property {boolean} parent [ONLY FOR DTPS.USER] Automatically managed by DTPS. True if the user is a parent account.
1923 */
1924
1925/**
1926* @typedef {Object} Class
1927* @description Defines class objects in DTPS
1928* @property {string} name Name of the class
1929* @property {string} id Class ID used by Power+
1930* @property {string} lmsID Class ID used for LMS API calls
1931* @property {string} userID The ID of the user this class is associated with (from the parameter of dtpsLMS.fetchClasses)
1932* @property {number} num Index of the class in the dtps.classes array
1933* @property {string} subject Class subject
j29812c42022-04-27 15:41:40 -07001934* @property {number[]} usualDueRange The range of usual due dates for this course [min,max]. Anything outside this range is considered unusual and highlighted if enabled.
j7940eec2020-12-28 14:00:41 -06001935* @property {ClassSection[]|boolean} [people] Users in this class. True if the class supports the "People" tab, but not yet loaded. If this is true dtpsLMS.fetchUsers must be implemented.
1936* @property {string} [icon] The icon to show with this class
1937* @property {string} [group] The name of the group that this class is in
1938* @property {number|string} [period] The period or section the user has this class at
j2566c4e2021-10-01 15:25:49 -07001939* @property {Date} [startDate] The start date for this course. Only used internally for filtering out stale courses.
1940* @property {Date} [endDate] The end date for this course. Only used internally for filtering out stale courses.
1941* @property {Date} [termStartDate] The start date for the term this course is in. Only used internally for filtering out stale courses.
1942* @property {Date} [termEndDate] The end date for the term this course is in. Only used internally for filtering out stale courses.
j7940eec2020-12-28 14:00:41 -06001943* @property {Assignment[]} assignments Class assignments. Assume assignments are still loading if this is undefined. The class has no assignments if this is an empty array. Loaded in dtps.init.
1944* @property {Module[]|boolean} [modules] Class modules. Assume this class supports the modules feature, but is not yet loaded, if this is true and that the class has no modules if this is an empty array. For LMSs that do not support modules, either keep it undefined or set it to false.
1945* @property {DiscussionThread[]|boolean} [discussions] Class discussion threads. Assume this class supports discussions, but not yet loaded, if this is true and that the class has no threads if this is an empty array. For LMSs that do not support discussions, either keep it undefined or set it to false.
1946* @property {Page[]|boolean} [pages] Class pages. Assume this class supports the pages feature, but not yet loaded, if true and that the class has no pages if this is an empty array. For LMSs that do not support pages, either keep it undefined or set it to false.
1947* @property {string} [newDiscussionThreadURL] A URL the user can visit to create a new discussion thread in this class
1948* @property {boolean} [homepage] True if the class has a homepage. If a class has a homepage, dtpsLMS.fetchHomepage must be implemented.
1949* @property {string} [term] Class term
1950* @property {string} [color] Class color
jb39e6d92021-01-30 20:34:04 -08001951* @property {number} [grade] Current percentage grade in the class (a number from 0 to 100)
j7940eec2020-12-28 14:00:41 -06001952* @property {string} [letter] Current letter grade in the class
j7940eec2020-12-28 14:00:41 -06001953* @property {string} [image] URL to the class background image
1954* @property {User} [teacher] Class teacher. If the class has multiple teachers, this is the primary teacher.
1955* @property {boolean} [hasGradebook] Automatically managed by DTPS. True if the class should show the gradebook tab.
j7940eec2020-12-28 14:00:41 -06001956*/