updates
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 30aeecb..3dd4378 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -26,7 +26,7 @@
npm start
```
-When the server is ready, open Power+ and go to Settings -> About -> Show Advanced Options -> Debug mode and type in the port the server is running on (the default is 2750). Then, reload Power+ and go to Settings -> Prerelease testing and select "Debugging". This will make Power+ load from the local server instead of the live version the next time you reload.
+When the server is ready, open Power+ and go to Settings -> About -> Show Advanced Options -> Enable debug config. Then, reload Power+ and go to Settings -> Prerelease testing and select "Debugging". This will make Power+ load from the local server instead of the live version the next time you reload.
## NPM scripts
- `start` Starts an HTTP server for testing Power+ locally
diff --git a/README.md b/README.md
index d553d5d..b218d85 100644
--- a/README.md
+++ b/README.md
@@ -23,21 +23,14 @@
- [Contributing](CONTRIBUTING.md)
## Bookmarklet
-If you cannot use the Power+ [Chrome Extension](https://chrome.google.com/webstore/detail/power%20/pakgdifknldaiglefmpkkgfjndemfapo), you can add a bookmarklet instead to access Power+.
+If you cannot use the Power+ [Chrome Extension](https://chrome.google.com/webstore/detail/power%20/pakgdifknldaiglefmpkkgfjndemfapo), you can add the bookmarklet below to access Power+. Once the bookmarklet is added, open Canvas, then click the bookmarklet to load Power+.
<br />
Stable bookmarklet
```javascript
-javascript:jQuery.getScript('https://powerplus.app/init.js');dtpsLoader=2;
-```
-
-
-Firefox bookmarklet
-
-```javascript
-javascript:(function(){jQuery.getScript('https://powerplus.app/init.js');dtpsLoader=2;})();
+javascript:!function(){window.dtpsBaseURL="https://powerplus.app",window.dtpsLoader=3;var d=document.createElement("script");d.src=window.dtpsBaseURL+"/init.js",document.head.appendChild(d)}();
```
<br /><br /><br /><br /><br /><br />
diff --git a/chrome/communicator.js b/chrome/communicator.js
index 6a593d3..4d6ed43 100644
--- a/chrome/communicator.js
+++ b/chrome/communicator.js
@@ -26,8 +26,11 @@
<div dtps="true" 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 dtps="true" style="height: 100px; margin-top: 132px;" src="https://i.imgur.com/7dDUVh2.png" />
<br dtps="true" />
- <div dtps="true" class="progress"><div dtps="true" class="indeterminate"></div></div>
- <style dtps="true">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 dtps="true" class="progress"><div id="dtpsLoadingScreenBar" dtps="true" class="indeterminate"></div></div>
+ <p id="dtpsLoadingScreenStatus" dtps="true">
+ ${window.localStorage.dtpsLoaderPref == "codespace" ? `[codespace] Click <a onclick="window.localStorage.dtpsLoaderPref = 'prod';window.location.reload();" href="#">here</a> to switch to production` : ``}
+ </p>
+ <style dtps="true">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%}}p{font-family:BlinkMacSystemFont,-apple-system,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,"Fira Sans","Droid Sans","Helvetica Neue",Helvetica,Arial,sans-serif;color: #c4c4c4;margin-top: 24px;}</style>
</div>
`;
} else if (node.nodeType === 1 && node.tagName === 'HEAD') {
@@ -47,20 +50,34 @@
})
})
- // Starts the monitoring
+ //Start MutationObserver
observer.observe(document.documentElement, {
childList: true,
subtree: true
- })
+ });
- //tell Power+ the loader is already shown
+ //Get Power+ base URL
+ var baseURL = "https://powerplus.app";
+ if (window.localStorage.debuggingConfig && (window.localStorage.dtpsLoaderPref == "debugging")) {
+ if (window.localStorage.debuggingConfig == "true") {
+ baseURL = "http://localhost:2750";
+ } else if (window.localStorage.debuggingConfig) {
+ baseURL = window.localStorage.debuggingConfig;
+ }
+ } else if (window.localStorage.githubCanary && (window.localStorage.dtpsLoaderPref == "canary")) {
+ baseURL = "https://jottocraft.github.io/" + window.localStorage.githubCanary;
+ } else if (window.localStorage.codespaceExternalURL && (window.localStorage.dtpsLoaderPref == "codespace")) {
+ baseURL = "https://" + window.localStorage.codespaceExternalURL.replace(/\//g, "") + ".apps.codespaces.githubusercontent.com";
+ }
+
+ //Set DTPS loader parameters
var s = document.createElement("script");
- s.textContent = "window.dtpsPreLoader = true;";
+ s.textContent = "window.dtpsPreLoader = true;window.dtpsBaseURL = '" + baseURL + "'";
s.async = false;
s.setAttribute("dtps", "true");
document.documentElement.appendChild(s);
- //add jQuery
+ //Load jQuery
var s = document.createElement("script");
s.src = "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js";
s.async = false;
@@ -78,7 +95,7 @@
lmsScript = "dtech";
} else if (window.location.hostname.includes("instructure.com")) {
lmsScript = "canvas";
- } else {
+ } else if (!window.localStorage.dtpsLMSOverride) {
console.log("[DTPS CHROME]", "Could not find a valid LMS script for this site. Is Power+ supported on " + window.location.hostname + "?");
return;
}
@@ -86,47 +103,34 @@
//Check for debugging LMS overrides
if (window.localStorage.dtpsLMSOverride) lmsScript = window.localStorage.dtpsLMSOverride;
- //load Power+ script
- window.dtpsLoader = 4;
- var script = "https://powerplus.app/scripts/lms/" + lmsScript + ".js";
-
- //Check for debugging/canary scripts
- var debuggingPath = window.localStorage.dtpsDebuggingPort ? "http://localhost:" + window.localStorage.dtpsDebuggingPort + "/scripts/lms/" + lmsScript + ".js" : null;
- var canaryPath = window.localStorage.githubCanary ? "https://jottocraft.github.io/" + window.localStorage.githubCanary + "/scripts/lms/" + lmsScript + ".js" : null;
-
- //Check for version preference
- if (debuggingPath && (window.localStorage.dtpsLoaderPref == "debugging")) {
- script = debuggingPath;
- } else if (canaryPath && (window.localStorage.dtpsLoaderPref == "canary")) {
- script = canaryPath;
- }
-
//Add script to DOM
var s = document.createElement("script");
- s.src = script;
+ s.src = baseURL + "/scripts/lms/" + lmsScript + ".js";
s.async = false;
s.setAttribute("dtps", "true");
document.documentElement.appendChild(s);
s.onerror = function () {
//Couldn't load debugging script, fallback to production
- console.log("[DTPS CHROME] Failed to load debugging script. Falling back to production.");
- window.localStorage.dtpsLoaderPref = "prod";
- var ss = document.createElement("script");
- ss.src = "https://powerplus.app/scripts/lms/" + lmsScript + ".js";
- ss.async = false;
- ss.setAttribute("dtps", "true");
- document.documentElement.appendChild(ss);
+ if (window.localStorage.dtpsLoaderPref && (window.localStorage.dtpsLoaderPref !== "prod")) {
+ console.log("[DTPS CHROME] Failed to load debugging script. Falling back to production.");
+ window.localStorage.dtpsLoaderPref = "prod";
+ window.location.reload();
+ } else {
+ document.getElementById("dtpsLoadingScreenBar").style.animationPlayState = "paused";
+ document.getElementById("dtpsLoadingScreenStatus").innerText = "Could not load Power+. Please try again later.";
+ }
};
}
} else if (window.location.search.includes("dtpsLogin=true")) {
//redirect to Power+ after login
- console.log("[DTPS Chrome] Redirecting after login...")
- window.location.href = "/power+"
+ console.log("[DTPS Chrome] Redirecting after login...");
+ window.location.href = "/power+";
} else {
var releaseType = null;
- if (window.localStorage.dtpsLoaderPref == "debugging") releaseType = "DEBUG";
- if (window.localStorage.dtpsLoaderPref == "canary") releaseType = "CANARY";
+ if (window.localStorage.dtpsLoaderPref == "debugging") releaseType = "Power+ (debug)";
+ if (window.localStorage.dtpsLoaderPref == "canary") releaseType = "Power+ (canary)";
+ if (window.localStorage.dtpsLoaderPref == "codespace") releaseType = "Power+ (codespace)";
const observer = new MutationObserver(mutations => {
mutations.forEach(({ addedNodes }) => {
diff --git a/chrome/manifest.json b/chrome/manifest.json
index 42fd1a3..63de246 100644
--- a/chrome/manifest.json
+++ b/chrome/manifest.json
@@ -3,7 +3,7 @@
"name": "Power+",
"description": "A better UI for Canvas LMS",
- "version": "3.0.1",
+ "version": "3.0.2",
"background": {
"scripts": ["background.js"]
},
diff --git a/package.json b/package.json
index bd0b2b9..4d32ecf 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "dtps",
"description": "A better UI for Canvas LMS",
"scripts": {
- "start": "node start.js",
+ "start": "node server.js",
"build": "node build.js",
"predeploy": "npm run build",
"deploy": "gh-pages -d build -m \"npm deploy\"",
diff --git a/scripts/core.js b/scripts/core.js
index c71d529..f613b06 100644
--- a/scripts/core.js
+++ b/scripts/core.js
@@ -37,10 +37,10 @@
var dtps = {
ver: 305,
readableVer: "v3.0.5",
- env: window.localStorage.dtpsLoaderPref == "debugging" ? "dev" : window.jottocraftSatEnv || "prod",
+ env: new URL(window.dtpsBaseURL || "https://powerplus.app").hostname == "localhost" ? "dev" : window.jottocraftSatEnv || "prod",
classes: [],
- baseURL: document.currentScript.src ? document.currentScript.src.split("/scripts/core.js")[0] : "https://powerplus.app",
- unstable: window.localStorage.dtpsLoaderPref == "canary" || window.localStorage.dtpsLoaderPref == "debugging" || String(document.currentScript.src).includes("http://localhost"),
+ baseURL: window.dtpsBaseURL || "https://powerplus.app",
+ unstable: window.dtpsBaseURL !== "https://powerplus.app",
gradebookExpanded: false,
updates: [],
dashboardItems: [
@@ -1364,6 +1364,7 @@
});
//Render settings card
+ var baseHost = new URL(dtps.baseURL).hostname;
jQuery(".card.settingsCard").html(/*html*/`
<i onclick="fluid.cards.close('.card.settingsCard')" class="material-icons close">close</i>
@@ -1372,7 +1373,7 @@
<img src="https://powerplus.app/icon.svg" style="width: 50px;vertical-align: middle;padding: 7px; padding-top: 14px;" />
<div style="vertical-align: middle; display: inline-block;">
<h5 style="font-weight: bold;display: inline-block;vertical-align: middle;">Power+</h5>
- <p>${dtps.readableVer + (window.localStorage.dtpsLoaderPref ? ` <span style="font-size: 12px;">(${window.localStorage.dtpsLoaderPref})</span>` : "")}</p>
+ <p>${dtps.readableVer + (dtps.unstable ? ` <span style="font-size: 12px;">(unstable)</span>` : "")}</p>
</div>
</div>
@@ -1392,7 +1393,7 @@
<i class="material-icons">bug_report</i> Debugging
</div>
` : ``}
- <div onclick="$('.abtpage').hide();$('.abtpage.about').show(); if ($('body').hasClass('sudo')) { $('.advancedOptions').show(); $('.advOp').hide(); } else { $('.advancedOptions').hide(); $('.advOp').show(); }" class="item abt">
+ <div onclick="$('.abtpage').hide();$('.abtpage.about').show();" class="item abt">
<i class="material-icons">info</i> About
</div>
</div>
@@ -1432,7 +1433,7 @@
</div>
</div>
- ${window.localStorage.githubCanary || window.localStorage.dtpsDebuggingPort ? /*html*/`
+ ${window.localStorage.githubCanary || window.localStorage.debuggingConfig || window.localStorage.codespaceExternalURL ? /*html*/`
<br /><br />
<p>Prerelease testing</p>
@@ -1450,7 +1451,14 @@
<i class="material-icons">build_circle</i> Canary
</button>
` : ``}
- ${window.localStorage.dtpsDebuggingPort ? /*html*/`
+ ${window.localStorage.codespaceExternalURL ? /*html*/`
+ <button
+ onclick="window.localStorage.setItem('dtpsLoaderPref', 'codespace')"
+ class="btn ${window.localStorage.dtpsLoaderPref == "codespace" ? "active" : ""}">
+ <i class="material-icons">code</i> Codespace
+ </button>
+ ` : ``}
+ ${window.localStorage.debuggingConfig ? /*html*/`
<button
onclick="window.localStorage.setItem('dtpsLoaderPref', 'debugging')"
class="btn ${window.localStorage.dtpsLoaderPref == "debugging" ? "active" : ""}">
@@ -1498,9 +1506,14 @@
<br />
+ <h5>Script configuration</h5>
+
+ <button onclick="['dtpsLoaderPref', 'debuggingConfig', 'githubCanary', 'codespaceExternalURL', 'dtpsLMSOverride'].forEach(k => window.localStorage.removeItem(k)); window.location.reload();" class="btn small"><i class="material-icons">cancel</i> Reset release overrides</button>
+ <br /><br />
+
<div>
- <input id="dtpsDebuggingPort" value="${window.localStorage.dtpsDebuggingPort || ""}" placeholder="Debugging Port" />
- <button class="btn small" onclick="window.localStorage.setItem('dtpsDebuggingPort', $('#dtpsDebuggingPort').val())"><i class="material-icons">save</i> Save</button>
+ <input id="dtpsCodespaceURL" value="${window.localStorage.codespaceExternalURL || ""}" placeholder="GitHub Codespace subdomain" />
+ <button class="btn small" onclick="window.localStorage.setItem('codespaceExternalURL', $('#dtpsCodespaceURL').val())"><i class="material-icons">save</i> Save</button>
</div>
<div>
@@ -1533,7 +1546,7 @@
<h4 style="font-weight: bold; font-size: 32px; margin-bottom: 0px;">Power+</h4>
<div style="font-size: 16px; margin-top: 5px;">
${dtps.readableVer}
- <div class="buildInfo" style="display: inline-block;margin: 0px 5px;font-size: 12px;cursor: pointer;"></div>
+ <div style="display: inline-block;margin: 0px 5px;font-size: 12px;">${baseHost !== "powerplus.app" ? `(from ${baseHost})` : ""}</div>
</div>
</div>
@@ -1573,19 +1586,19 @@
</div>
</div>
- <div class="card advancedOptions" style="padding: 8px 16px; box-shadow: none !important; border: 2px solid var(--elements); margin-top: 20px; display: none;">
+ <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;`}">
<div style="display: inline-block; vertical-align: middle;">
<h4 style="font-weight: bold; font-size: 28px; margin-bottom: 0px;">Advanced Options</h4>
</div>
<div style="margin-top: 15px; margin-bottom: 7px;">
<a style="color: var(--lightText); margin: 0px 5px; cursor: pointer;" onclick="dtps.clearData();"><i class="material-icons" style="vertical-align: middle">refresh</i> Reset Power+</a>
- <a style="color: var(--lightText); margin: 0px 5px; cursor: pointer;" onclick="window.localStorage.dtpsDebuggingPort = window.prompt('Please enter the port the server is running on'); alert('Reload the page for changes to take effect');"><i class="material-icons" style="vertical-align: middle">bug_report</i> Debug mode</a>
+ <a style="color: var(--lightText); margin: 0px 5px; cursor: pointer;" onclick="window.localStorage.debuggingConfig = 'true'; alert('Debugging configuration enabled. Reload Power+ to see changes.');"><i class="material-icons" style="vertical-align: middle">bug_report</i> Enable debug config</a>
</div>
</div>
<br />
- <p style="cursor: pointer; color: var(--secText, gray)" onclick="$('.advancedOptions').show(); $(this).hide();" class="advOp">Show advanced options</p>
+ ${dtps.env == "dev" ? `` : `<p style="cursor: pointer; color: var(--secText, gray)" onclick="$('.advancedOptions').show(); $(this).hide();" class="advOp">Show advanced options</p>`}
<div style="text-align: center; padding: 50px 0px;">
<img style="height: 45px; margin-right: 20px; vertical-align: middle;" src="https://cdn.jottocraft.com/images/footerImage.png" />
diff --git a/scripts/lms/demo.js b/scripts/lms/demo.js
index b31c036..7a68433 100644
--- a/scripts/lms/demo.js
+++ b/scripts/lms/demo.js
@@ -200,6 +200,16 @@
url: "https://www.google.com"
},
{
+ type: "page",
+ title: "Demo Page",
+ id: "1"
+ },
+ {
+ type: "discussion",
+ title: "Demo Discussion",
+ id: "1"
+ },
+ {
type: "assignment",
title: "Demo Assignment 1",
id: "191"
@@ -240,8 +250,7 @@
{
title: "Demo Discussion",
id: "1",
- locked: true,
- requireInitialPost: false
+ locked: true
}
])
})
@@ -250,18 +259,24 @@
//Fetches discussion thread posts from Canvas
dtpsLMS.fetchDiscussionPosts = function (classID, threadID) {
return new Promise(function (resolve, reject) {
- resolve([
- {
- id: "1",
- body: `<p>This discussion is for demonstration purposes only</p>`,
- postedAt: new Date(),
- author: {
- name: "Demo Teacher",
- id: "2",
- photoURL: "https://powerplus.app/logo.png"
+ resolve({
+ title: "Demo Discussion",
+ id: "1",
+ locked: true,
+ requireInitialPost: false,
+ posts: [
+ {
+ id: "1",
+ body: `<p>This discussion is for demonstration purposes only</p>`,
+ postedAt: new Date(),
+ author: {
+ name: "Demo Teacher",
+ id: "2",
+ photoURL: "https://powerplus.app/logo.png"
+ }
}
- }
- ])
+ ]
+ })
})
}
@@ -271,13 +286,7 @@
resolve([
{
title: "Demo Page",
- id: "1",
- updatedAt: new Date(),
- author: {
- name: "Demo Teacher",
- id: "2",
- photoURL: "https://powerplus.app/logo.png"
- }
+ id: "1"
}
])
})
@@ -286,7 +295,17 @@
//Fetches pages list data from Canvas
dtpsLMS.fetchPageContent = function (classID, pageID) {
return new Promise(function (resolve, reject) {
- resolve(`<p>This page is for demonstration purposes only</p>`);
+ resolve({
+ title: "Demo Page",
+ id: "1",
+ updatedAt: new Date(),
+ content: `<p>This page is for demonstration purposes only</p>`,
+ author: {
+ name: "Demo Teacher",
+ id: "2",
+ photoURL: "https://powerplus.app/logo.png"
+ }
+ });
})
}
diff --git a/start.js b/server.js
similarity index 94%
rename from start.js
rename to server.js
index 3b0452a..e65fc3b 100644
--- a/start.js
+++ b/server.js
@@ -35,6 +35,6 @@
app.listen(port, () => {
console.log("The Power+ development server is listening on port " + port);
- console.log("\nGo to Settings -> About -> Advanced Options -> Debug mode in Power+ to enable debug mode");
+ console.log("\nGo to Settings -> About -> Advanced Options -> Enable debug config in Power+ to enable debug mode");
console.log("Read CONTRIBUTING.md for more information");
});
\ No newline at end of file
diff --git a/www/demo/index.html b/www/demo/index.html
index 82016b8..75381e6 100644
--- a/www/demo/index.html
+++ b/www/demo/index.html
@@ -8,7 +8,7 @@
<title dtps="true">Power+ Demo</title>
<meta dtps="true" name="description" content="Power+ demonstration website">
<meta dtps="true" name="author" content="jottocraft">
- <script dtps="true">window.dtpsPreLoader = true;</script>
+ <script dtps="true">window.dtpsPreLoader = true; window.dtpsBaseURL = "https://powerplus.app";</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js" dtps="true"></script>
<script src="https://powerplus.app/scripts/lms/demo.js" dtps="true"></script>
</head>