v3.0.6: new homepage & assignments ui for d.tech lms
diff --git a/scripts/assignments.js b/scripts/assignments.js
index a8a1141..99ed67d 100644
--- a/scripts/assignments.js
+++ b/scripts/assignments.js
@@ -474,20 +474,67 @@
var assignment = dtps.classes[classNum].assignments[assignmentIDs.indexOf(id)];
//The assignment body is rendered in an iFrame to keep its content and styling isolated from the rest of the page
- var assignmentBodyURL = null;
+ var assignmentBodyHTML = null;
if (assignment.body) {
//Get computed background and text color to style the iFrame with
var computedBackgroundColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--cards");
var computedTextColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--text");
- //Generate a blob with the assignment body and get its data URL
- var blob = new Blob([`
+ var body = assignment.body;
+ if ($("body").hasClass("dark")) {
+ body = dtps.brightenTextForDarkMode(assignment.body, computedBackgroundColor);
+ }
+
+ var hasKeywords = false;
+ if (body.toLowerCase().includes("deliverable") && body.toLowerCase().includes("instruction") && body.toLowerCase().includes("look for")) hasKeywords = true;
+ if ((window.location.hostname == "dtechhs.instructure.com") && hasKeywords && ($('<div></div>').append(body).children("table").find("tbody tr").length > 1)) {
+ var sections = [];
+ $('<div></div>').append(body).children("table").find("tbody tr").toArray().forEach((element, i) => {
+ var text = $(element).find("h4:first-child").text().toLowerCase();
+ if (!text) return;
+
+ var tmpjQuery = $(element);
+ tmpjQuery.find("h4:first-child").remove();
+ var innerHTML = tmpjQuery.html();
+ if (!innerHTML) return;
+
+ var icon = null;
+ if (text.includes("deliverable")) { icon = "description"; text = "Deliverables"; }
+ if (text.includes("instruction")) { icon = "assignment"; text = "Instructions"; }
+ if (text.includes("look for")) { icon = "find_in_page"; text = "Look Fors"; }
+
+ sections.push({ text, icon, innerHTML });
+ });
+
+ var tmpjQuery = $('<div></div>').append(body);
+ tmpjQuery.children("table").replaceWith(sections.map(s => {
+ return `
+ <div style="margin: 20px 0px;">
+ <h2><i style="vertical-align: middle; margin-right: 10px; font-size: 24px;" class="material-icons-outlined">${s.icon}</i><span style="vertical-align: middle;text-decoration: underline;">${s.text}</span></h2>
+ ${s.innerHTML}
+ </div>
+ `;
+ }).join(""));
+ var outerHTML = tmpjQuery.html();
+
+ var blob = new Blob([`
+ <base target="_blank" />
+ <link type="text/css" rel="stylesheet" href="https://cdn.jottocraft.com/CanvasCSS.css" media="screen,projection"/>
+ <link href="https://fonts.googleapis.com/icon?family=Material+Icons+Outlined" rel="stylesheet">
+ <style>body {background-color: ${computedBackgroundColor}; color: ${computedTextColor};} *:not(a) { color: ${computedTextColor} !important; }</style>
+ ${outerHTML}
+ `], { type: 'text/html' });
+ assignmentBodyHTML = `<iframe id="assignmentParts" onload="dtps.iframeLoad('assignmentParts')" style="margin: 10px 0px; width: 100%; border: none; outline: none;" src="${window.URL.createObjectURL(blob)}" />`;
+ } else {
+ //Generate a blob with the assignment body and get its data URL
+ var blob = new Blob([`
<base target="_blank" />
<link type="text/css" rel="stylesheet" href="https://cdn.jottocraft.com/CanvasCSS.css" media="screen,projection"/>
- <style>body {background-color: ${computedBackgroundColor}; color: ${computedTextColor};</style>
- ${assignment.body}
+ <style>body {background-color: ${computedBackgroundColor}; color: ${computedTextColor};}</style>
+ ${body}
`], { type: 'text/html' });
- assignmentBodyURL = window.URL.createObjectURL(blob);
+ assignmentBodyHTML = `<iframe id="assignmentIframe" onload="dtps.iframeLoad('assignmentIframe')" style="margin: 10px 0px; width: 100%; border: none; outline: none;" src="${window.URL.createObjectURL(blob)}" />`;
+ }
}
//Get assignment rubric HTML
@@ -548,7 +595,7 @@
</div>
<div style="margin-top: 20px;" class="assignmentBody">
- ${assignment.body ? `<iframe id="assignmentIframe" onload="dtps.iframeLoad('assignmentIframe')" style="margin: 10px 0px; width: 100%; border: none; outline: none;" src="${assignmentBodyURL}" />` : ""}
+ ${assignment.body ? assignmentBodyHTML : ""}
</div>
${assignment.body ? `<div style="margin: 5px 0px; background-color: var(--darker); height: 1px; width: 100%;" class="divider"></div>` : ""}
@@ -658,8 +705,8 @@
var action = "";
if (item.type == "assignment") action = "dtps.assignment('" + item.id + "', " + classNum + ")";
if (item.type == "page") {
- action = "fluid.screen('pages', '" + classID + "|" + item.id + "|true')";
- }
+ action = "fluid.screen('pages', '" + classID + "|" + item.id + "|true')";
+ }
if (item.type == "discussion") {
action = "fluid.screen('discussions', '" + classID + "|" + item.id + "|true')";
}
@@ -853,25 +900,81 @@
var computedBackgroundColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--cards");
var computedTextColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--text");
- //Generate a blob with the assignment body and get its data URL
- var blob = new Blob([`
- <base target="_blank" />
- <link type="text/css" rel="stylesheet" href="https://cdn.jottocraft.com/CanvasCSS.css" media="screen,projection"/>
- <style>body {background-color: ${computedBackgroundColor}; color: ${computedTextColor};</style>
- ${homepage}
- `], { type: 'text/html' });
- var homepageURL = window.URL.createObjectURL(blob);
+ if ($("body").hasClass("dark")) {
+ homepage = dtps.brightenTextForDarkMode(homepage, computedBackgroundColor);
+ }
- $(".card.details").html(/*html*/`
- <i onclick="fluid.cards.close('.card.details')" class="material-icons close">close</i>
+ if ($('<div></div>').append(homepage).find(".enhanceable_content.tabs>ul>li").toArray().length > 1) {
+ //Use special d.tech LMS optimized homepage
+ var fragments = [];
+ $('<div></div>').append(homepage).find(".enhanceable_content.tabs>ul>li").toArray().forEach((fragment) => {
+ var text = $(fragment).text().toLowerCase();
+ if (!text) return;
- <h4 style="font-weight: bold;">${dtps.classes[num].subject} Homepage</h4>
+ var id = $(fragment).find("a").attr("href").replace("#", "");
+ if (!id) return;
- <br />
- <div style="margin-top: 20px;" class="homepageBody">
- <iframe id="homepageIframe" onload="dtps.iframeLoad('homepageIframe')" style="margin: 10px 0px; width: 100%; border: none; outline: none;" src="${homepageURL}" />
- </div>
- `);
+ var html = $(homepage).find("#" + id).html();
+ if (!html) return;
+
+ var icon = null;
+ if (text.includes("agenda")) { icon = "format_list_numbered"; text = "Agenda"; }
+ if (text.includes("instructor")) { icon = "person"; text = "Instructor"; }
+ if (text.includes("course info")) { icon = "info"; text = "Course Info"; }
+ if (text.includes("resources")) { icon = "article"; text = "Course Resources"; }
+
+ //Generate a blob with the assignment body and get its data URL
+ var blob = new Blob([`
+ <base target="_blank" />
+ <link type="text/css" rel="stylesheet" href="https://cdn.jottocraft.com/CanvasCSS.css" media="screen,projection"/>
+ <style>body {background-color: ${computedBackgroundColor}; color: ${computedTextColor};</style>
+ ${html}
+ `], { type: 'text/html' });
+ var frameURL = window.URL.createObjectURL(blob);
+
+ fragments.push({ text, id, icon, frameURL });
+ });
+
+ $(".card.details").html(/*html*/`
+ <i onclick="fluid.cards.close('.card.details')" class="material-icons close">close</i>
+
+ <h4 style="font-weight: bold;">${dtps.classes[num].subject} Homepage</h4>
+
+ <br />
+ ${dtps.classes[num].videoMeetingURL ? `<button onclick="window.open('${dtps.classes[num].videoMeetingURL}')" class="btn small"><i class="material-icons">videocam</i> Zoom</button>` : ``}
+ <div class="btns row small">
+ ${fragments.map((fragment, i) => {
+ return `<button onclick="$(this).addClass('active');$(this).siblings().removeClass('active');$('#homepageFragment').attr('src', '${fragment.frameURL}'); dtps.iframeLoad('homepageFragment');"
+ style="text-transform: capitalize;" class="btn ${i == 0 ? "active" : ""}">${fragment.icon ? `<i class="material-icons">${fragment.icon}</i> ` : ""}${fragment.text}</button>`;
+ }).join("")}
+ </div>
+
+ <br />
+ <div style="margin-top: 20px;" class="homepageBody">
+ <iframe id="homepageFragment" onload="dtps.iframeLoad('homepageFragment')" style="margin: 10px 0px; width: 100%; border: none; outline: none;" src="${fragments[0].frameURL}" />
+ </div>
+ `);
+ } else {
+ //Generate a blob with the assignment body and get its data URL
+ var blob = new Blob([`
+ <base target="_blank" />
+ <link type="text/css" rel="stylesheet" href="https://cdn.jottocraft.com/CanvasCSS.css" media="screen,projection"/>
+ <style>body {background-color: ${computedBackgroundColor}; color: ${computedTextColor};</style>
+ ${homepage}
+ `], { type: 'text/html' });
+ var homepageURL = window.URL.createObjectURL(blob);
+
+ $(".card.details").html(/*html*/`
+ <i onclick="fluid.cards.close('.card.details')" class="material-icons close">close</i>
+
+ <h4 style="font-weight: bold;">${dtps.classes[num].subject} Homepage</h4>
+
+ <br />
+ <div style="margin-top: 20px;" class="homepageBody">
+ <iframe id="homepageIframe" onload="dtps.iframeLoad('homepageIframe')" style="margin: 10px 0px; width: 100%; border: none; outline: none;" src="${homepageURL}" />
+ </div>
+ `);
+ }
fluid.modal(".card.details");
} else {
diff --git a/scripts/core.js b/scripts/core.js
index f613b06..112b432 100644
--- a/scripts/core.js
+++ b/scripts/core.js
@@ -1,7 +1,7 @@
/**
* @file DTPS Core functions and module loader
* @author jottocraft
- * @version v3.0.5
+ * @version v3.0.6
*
* @copyright Copyright (c) 2018-2020 jottocraft. All rights reserved.
* @license GPL-2.0-only
@@ -35,8 +35,8 @@
* @property {object} remoteConfig Configuration variables that can be remotely changed
*/
var dtps = {
- ver: 305,
- readableVer: "v3.0.5",
+ ver: 306,
+ readableVer: "v3.0.6",
env: new URL(window.dtpsBaseURL || "https://powerplus.app").hostname == "localhost" ? "dev" : window.jottocraftSatEnv || "prod",
classes: [],
baseURL: window.dtpsBaseURL || "https://powerplus.app",
@@ -241,11 +241,11 @@
if (!window.dtpsPreLoader || dtps.user) {
//Only show the loader if the extension hasn't already shown it
jQuery("body").append(/*html*/`
- <div id="dtpsNativeOverlay" style="position: fixed; top: 0px; left: 0px; width: 100vw; height: 100vh; z-index: 999; background: #191919; text-align: center; z-index: 999; transition: opacity 0.2s;">
-
- <img style="height: 100px; margin-top: 132px;" src="https://i.imgur.com/eiTE2sW.png" />
- <div class="spinner" style="margin-top: 300px;"></div>
- <style>body { overflow: hidden !important; } .spinner { width: 40px; height: 40px; margin: 40px auto; background-color: gray; border-radius: 100%; -webkit-animation: sk-scaleout 1.0s infinite ease-in-out; animation: sk-scaleout 1.0s infinite ease-in-out; } @-webkit-keyframes sk-scaleout { 0% { -webkit-transform: scale(0) } 100% { -webkit-transform: scale(1.0); opacity: 0; } } @keyframes sk-scaleout { 0% { -webkit-transform: scale(0); transform: scale(0); } 100% { -webkit-transform: scale(1.0); transform: scale(1.0); opacity: 0; } }</style>
+ <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;">
+ <img style="height: 100px; margin-top: 132px;" src="https://i.imgur.com/7dDUVh2.png" />
+ <br />
+ <div class="progress"><div class="indeterminate"></div></div>
+ <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>
</div>
`);
}
@@ -1043,6 +1043,36 @@
}
/**
+ * Brightens text in an HTML string for dark mode
+ *
+ * @param {string} html The HTML to brighten text for
+ * @param {string} [bg] The background color that the HTML will be displayed on
+ * @returns {string} HTML string with brightened colors
+ */
+dtps.brightenTextForDarkMode = function(html, bg) {
+ //Use dark mode algorithm
+ if (!bg) bg = "black";
+ var fakeRoot = $('<div></div>').append(html);
+ fakeRoot.find("span").filter(function() {
+ return $(this).css("color") && !($(this).css("background-color") || $(this).css("background")) && !$(this).parents().filter(function() {
+ return $(this).css("background-color") || $(this).css("background");
+ }).length;
+ }).toArray().forEach(element => {
+ //Brighten color
+ var brightness = tinycolor($(element).css("color")).getBrightness() / 255 * 100;
+ var targetBrightness = (100 - (tinycolor(bg).getBrightness() / 255 * 100)) - brightness;
+ var brightnessDiff = targetBrightness - brightness;
+
+ if (brightnessDiff > 0) {
+ $(element).css("color", "#" + tinycolor($(element).css("color")).brighten(Math.abs(brightnessDiff)).toHex());
+ } else {
+ $(element).css("color", "#" + tinycolor($(element).css("color")).darken(Math.abs(brightnessDiff)).toHex());
+ }
+ });
+ return fakeRoot.html();
+}
+
+/**
* Stores grade data locally for the previous grade feature
*
* @param classNum Class number to log grade
@@ -1441,7 +1471,7 @@
<div class="btns row small">
<button
onclick="window.localStorage.setItem('dtpsLoaderPref', 'prod')"
- class="btn ${window.localStorage.dtpsLoaderPref != "canary" && window.localStorage.dtpsLoaderPref != "debugging" ? "active" : ""}">
+ class="btn ${!["canary", "codespace", "debugging"].includes(window.localStorage.dtpsLoaderPref) ? "active" : ""}">
<i class="material-icons">label</i> Production
</button>
${window.localStorage.githubCanary ? /*html*/`
diff --git a/scripts/pages-discussions.js b/scripts/pages-discussions.js
index 0b85576..c071ee3 100644
--- a/scripts/pages-discussions.js
+++ b/scripts/pages-discussions.js
@@ -46,7 +46,7 @@
jQuery(".sidebar").html(/*html*/`
<div class="bigLogo" style="text-align: center; margin: 10px 0 20px; height: 38px;">
<i style="font-size: 28px; margin-right: 7px; vertical-align: middle;" class="material-icons">forum</i>
- <h4 style="color: var(--text); display: inline-block; font-size: 28px; vertical-align: middle; margin: 0px;">Discussions</h4>
+ <h4 style="color: var(--text); display: inline-block; font-size: 26px; vertical-align: middle; margin: 0px;">Discussions</h4>
</div>
<div class="items">
@@ -304,7 +304,7 @@
jQuery(".sidebar").html(/*html*/`
<div class="bigLogo" style="text-align: center; margin: 10px 0 20px; height: 38px;">
<i style="font-size: 28px; margin-right: 7px; vertical-align: middle;" class="material-icons">insert_drive_file</i>
- <h4 style="color: var(--text); display: inline-block; font-size: 28px; vertical-align: middle; margin: 0px;">Pages</h4>
+ <h4 style="color: var(--text); display: inline-block; font-size: 26px; vertical-align: middle; margin: 0px;">Pages</h4>
</div>
<div class="items">