v3.8.0 (RRS-3)
diff --git a/README.md b/README.md
index cf093ae..6eb8346 100644
--- a/README.md
+++ b/README.md
@@ -12,7 +12,7 @@
## Resources
- [Source code](https://bitbucket.org/jottocraft/dtps)
-- [Issue tracker](https://jottocraft.atlassian.net/jira/software/c/projects/DTPS/issues)
+- [Issue tracker](https://bugs.jottocraft.com)
- [Developer documentation](https://powerplus.app/docs)
<br /><br /><br /><br /><br /><br />
diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml
index d02f592..8aba4e2 100644
--- a/bitbucket-pipelines.yml
+++ b/bitbucket-pipelines.yml
@@ -15,4 +15,4 @@
script:
- npm ci
- npm run build
- - npx wrangler pages publish build --project-name=dtps
\ No newline at end of file
+ - npm run deploy
\ No newline at end of file
diff --git a/build.js b/build.js
index a47a030..38aaeb2 100644
--- a/build.js
+++ b/build.js
@@ -82,9 +82,6 @@
fs.copyFileSync("ui/fluid.css", "build/fluid/fluid.css");
fs.copyFileSync("ui/fluid.js", "build/fluid/fluid.js");
- //Write CNAME
- fs.writeFileSync(path.join("build", "CNAME"), dev ? "dev.dtps.jottocraft.com" : "powerplus.app", "utf8");
-
//Copy www
ncp("www", "build", function () {
if (dev) {
diff --git a/chrome/background.js b/chrome/background.js
deleted file mode 100644
index 118014f..0000000
--- a/chrome/background.js
+++ /dev/null
@@ -1,5 +0,0 @@
-chrome.runtime.onMessage.addListener(function (message) {
- if (message.messageName == 'extensionUninstall') {
- chrome.management.uninstallSelf();
- }
-});
\ No newline at end of file
diff --git a/chrome/communicator.js b/chrome/communicator.js
deleted file mode 100644
index 2a08a23..0000000
--- a/chrome/communicator.js
+++ /dev/null
@@ -1,169 +0,0 @@
-if (window.location.hostname == "powerplus.app") {
- const observer = new MutationObserver(mutations => {
- mutations.forEach(({ addedNodes }) => {
- addedNodes.forEach(node => {
- //Power+ button
- if (node.nodeType === 1 && node.id == "dtpsInstallBtn") {
- node.setAttribute("onclick", "window.location.href = 'https://dtechhs.instructure.com/power+/'");
- node.innerHTML = `<i class="material-icons">open_in_new</i> Open`;
- }
- })
- })
- })
-
- // Starts the monitoring
- observer.observe(document.documentElement, {
- childList: true,
- subtree: true
- })
-} else if ((window.location.pathname == "/power+") || (window.location.pathname == "/power+/")) {
- //Check for light or dark theme
- var light = false;
- if (window.localStorage.fluidTheme == "light") {
- light = true;
- } else if (((window.localStorage.fluidTheme == "system") || (window.localStorage.fluidTheme == "auto")) && !window.matchMedia("(prefers-color-scheme: dark)").matches) {
- light = true;
- }
-
- const useClassicDTPS = window.location.search && window.location.search.includes("classicEdition=true");
- const observer = new MutationObserver(mutations => {
- mutations.forEach(({ addedNodes }) => {
- addedNodes.forEach(node => {
- //Power+ preloader
- if (node.nodeType === 1 && node.tagName === 'BODY') {
- node.innerHTML = /*html*/`
- <div dtps="true" id="dtpsNativeOverlay" style="background-color: inherit; 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="${useClassicDTPS ? "https://i.imgur.com/fqqPF9i.png" : (light ? "https://i.imgur.com/0WzWwb1.png" : "https://i.imgur.com/7dDUVh2.png")}" />
- <br dtps="true" />
- <div dtps="true" class="progress"><div id="dtpsLoadingScreenBar" dtps="true" class="indeterminate"></div></div>
- <style dtps="true">body {background-color: ${light ? "white" : "#151515"}; --crxElements: ${light ? "#ececec" : "#2b2b2b"}; --crxText: ${light ? "#333" : "#efefef"}; overflow: hidden;}*,:after,:before{box-sizing:border-box}.progress{background:var(--crxElements);position:relative;width:600px;height:5px;overflow:hidden;border-radius:12px;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: var(--crxText);margin-top: 24px;}</style>
- </div>
- `;
- } else if (node.nodeType === 1 && node.tagName === 'HEAD') {
- node.innerHTML = /*html*/`
- <link dtps="true" rel="shortcut icon" href="https://powerplus.app/favicon.png" type="image/png">
- <meta dtps="true" name="viewport" content="width=device-width, initial-scale=1">
- <meta dtps="true" charset="utf-8">
- <title dtps="true">Power+</title>
- <meta dtps="true" name="description" content="A better UI for Canvas LMS">
- <meta dtps="true" name="author" content="jottocraft">
- `;
- } else if (node.nodeType === 1 && node.tagName === 'SCRIPT' && (node.textContent && node.textContent.includes('"current_user"'))) {
- //Do nothing for node containing enviornment data for faster load times
- } else if (node.nodeType === 1 && node.getAttribute("dtps") != "true") {
- //Node is not added by dtps
- node.remove();
- }
- })
- })
- })
-
- //Start MutationObserver
- observer.observe(document.documentElement, {
- childList: true,
- subtree: true
- });
-
- //Get Power+ base URL
- var baseURL = "https://powerplus.app";
- if (useClassicDTPS) {
- baseURL = "https://classic.dtps.jottocraft.com";
- } else if (window.localStorage.dtpsLoaderPref == "dev") {
- baseURL = "https://dev.dtps.jottocraft.com";
- } else if (window.localStorage.githubRepo && (window.localStorage.dtpsLoaderPref == "github")) {
- baseURL = "https://jottocraft.github.io/" + window.localStorage.githubRepo;
- } else if (window.localStorage.externalReleaseURL && (window.localStorage.dtpsLoaderPref == "external")) {
- baseURL = window.localStorage.externalReleaseURL;
- } else if (window.localStorage.dtpsLoaderPref == "local") {
- baseURL = "http://localhost:2750";
- }
-
- //Set DTPS loader parameters
- var s = document.createElement("script");
- s.textContent = "window.dtpsPreLoader = true;window.dtpsBaseURL = '" + baseURL + "'";
- s.async = false;
- s.setAttribute("dtps", "true");
- document.documentElement.appendChild(s);
-
- //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;
- s.setAttribute("dtps", "true");
- document.documentElement.appendChild(s);
-
- //Wait for page to load
- window.onload = function () {
- //Stop observer
- observer.disconnect();
-
- //Determine LMS script to load
- var lmsScript = null;
- if (window.location.hostname.startsWith("dtechhs")) {
- lmsScript = "dtech";
- } else if (window.location.hostname.includes("instructure.com")) {
- lmsScript = "canvas";
- } 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;
- }
-
- //Check for debugging LMS overrides
- if (window.localStorage.dtpsLMSOverride) lmsScript = window.localStorage.dtpsLMSOverride;
-
- //Add script to DOM
- var s = document.createElement("script");
- s.src = useClassicDTPS ? "https://classic.dtps.jottocraft.com/init.js" : 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
- 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+/";
-} else {
- var releaseType = null;
- if (window.localStorage.dtpsLoaderPref == "dev") releaseType = "Power+ (dev)";
- if (window.localStorage.dtpsLoaderPref == "github") releaseType = "Power+ (branch)";
- if (window.localStorage.dtpsLoaderPref == "external") releaseType = "Power+ (external)";
- if (window.localStorage.dtpsLoaderPref == "local") releaseType = "Power+ (local)";
-
- const observer = new MutationObserver(mutations => {
- mutations.forEach(({ addedNodes }) => {
- addedNodes.forEach(node => {
- //Power+ button
- if (node.nodeType === 1 && node.id == "menu") {
- node.insertAdjacentHTML("beforeend", /*html*/`
- <li class="menu-item ic-app-header__menu-list-item ">
- <a id="global_nav_dtps_link" role="button" href="/power+/" class="ic-app-header__menu-list-link">
- <div class="menu-item-icon-container" aria-hidden="true">
- <svg xmlns="http://www.w3.org/2000/svg" class="ic-icon-svg ic-icon-svg--dtps" version="1.1" viewBox="0 0 48 63.999"><path d="m5.333 0c-2.946 0-5.333 2.4-5.333 5.333v48c0 2.933 2.388 5.333 5.333 5.333h5.333v5.333l6.667-5.333 6.667 5.333v-5.333h18.667c2.947 0 5.333-2.4 5.333-5.333v-2.667c0 2.933-2.387 5.333-5.333 5.333h-18.667v-5.333h-13.333v5.333h-4c-2.209 0-4-1.867-4-4 0-2.4 1.791-4 4-4h36c2.947 0 5.333-2.4 5.333-5.333v-37.333c0-2.933-2.387-5.333-5.333-5.333h-37.333z"/></svg>
- </div>
- <div class="menu-item__text">${releaseType || "Power+"}</div>
- </a>
- </li>
- `);
- }
- })
- })
- })
-
- // Starts the monitoring
- observer.observe(document.documentElement, {
- childList: true,
- subtree: true
- })
-}
\ No newline at end of file
diff --git a/chrome/injector.js b/chrome/injector.js
new file mode 100644
index 0000000..95a926f
--- /dev/null
+++ b/chrome/injector.js
@@ -0,0 +1,4 @@
+const s = document.createElement("script");
+s.src = chrome.runtime.getURL("loader.js");
+s.onload = () => s.remove();
+document.documentElement.appendChild(s);
\ No newline at end of file
diff --git a/chrome/loader.js b/chrome/loader.js
new file mode 100644
index 0000000..f379ccc
--- /dev/null
+++ b/chrome/loader.js
@@ -0,0 +1,188 @@
+(function () {
+ function verifyCanvasInstance(cb) {
+ window.onload = function () {
+ //Check global ENV
+ if (window.ENV.current_user_global_id) {
+ //What are the odds that another non-Canvas page uses this?
+ //Hopefully slim-to-none because I'm using this as an indicator of a Canvas instance...
+ window.localStorage.setItem("dtpsThinksThisIsCanvas", "true");
+ cb();
+ }
+ }
+ }
+
+ //Is this a Canvas instance? (always YES for instructure.com subdomains)
+ const knownCanvasInstance = (
+ window.localStorage.getItem("dtpsThinksThisIsCanvas") === "true"
+ || window.location.hostname.endsWith("instructure.com")
+ );
+
+ if ((window.location.pathname == "/power+") || (window.location.pathname == "/power+/")) {
+ if (!knownCanvasInstance) {
+ verifyCanvasInstance(() => window.location.reload());
+ return;
+ }
+
+ //Check for light or dark theme
+ var light = false;
+ if (window.localStorage.fluidTheme == "light") {
+ light = true;
+ } else if (((window.localStorage.fluidTheme == "system") || (window.localStorage.fluidTheme == "auto")) && !window.matchMedia("(prefers-color-scheme: dark)").matches) {
+ light = true;
+ }
+
+ //Globally-Unique User ID
+ let guuid;
+
+ const useClassicDTPS = window.location.search && window.location.search.includes("classicEdition=true");
+ const observer = new MutationObserver(mutations => {
+ mutations.forEach(({ addedNodes }) => {
+ addedNodes.forEach(node => {
+ //Power+ preloader
+ if (node.nodeType === 1 && node.tagName === 'BODY') {
+ node.insertAdjacentHTML("afterbegin", /*html*/`
+ <div dtps="true" id="dtpsNativeOverlay" style="background-color: inherit; 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="${useClassicDTPS ? "https://i.imgur.com/fqqPF9i.png" : (light ? "https://i.imgur.com/0WzWwb1.png" : "https://i.imgur.com/7dDUVh2.png")}" />
+ <br dtps="true" />
+ <div dtps="true" class="progress"><div id="dtpsLoadingScreenBar" dtps="true" class="indeterminate"></div></div>
+ <style dtps="true">body {background-color: ${light ? "white" : "#151515"}; --crxElements: ${light ? "#ececec" : "#2b2b2b"}; --crxText: ${light ? "#333" : "#efefef"}; overflow: hidden;}*,:after,:before{box-sizing:border-box}.progress{background:var(--crxElements);position:relative;width:600px;height:5px;overflow:hidden;border-radius:12px;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: var(--crxText);margin-top: 24px;}</style>
+ </div>
+ `);
+ } else if (node.nodeType === 1 && node.tagName === 'HEAD') {
+ node.insertAdjacentHTML("afterbegin", /*html*/`
+ <link dtps="true" rel="shortcut icon" href="https://powerplus.app/favicon.png" type="image/png">
+ <meta dtps="true" name="viewport" content="width=device-width, initial-scale=1">
+ <meta dtps="true" charset="utf-8">
+ <title dtps="true">Power+</title>
+ <meta dtps="true" name="description" content="A better UI for Canvas LMS">
+ <meta dtps="true" name="author" content="jottocraft">
+ `);
+ } else if (node.nodeType === 1 && node.tagName === 'SCRIPT' && (node.textContent && node.textContent.includes('"current_user"'))) {
+ //Do nothing for node containing environment data for faster load times (skip fetching user data)
+ guuid = node.textContent.match(/"current_user_global_id":"(.*?)"/)[1];
+ } else if (node.nodeType === 1 && node.getAttribute("dtps") != "true") {
+ //Node is not added by dtps loader
+ node.remove();
+ }
+ })
+ })
+ });
+
+ //Start MutationObserver
+ observer.observe(document.documentElement, {
+ childList: true,
+ subtree: true
+ });
+
+ //Get Power+ base URL
+ var baseURL = "https://powerplus.app";
+ if (useClassicDTPS) {
+ baseURL = "https://classic.powerplus.app";
+ } else if (window.localStorage.externalReleaseURL && (window.localStorage.dtpsLoaderPref == "external")) {
+ baseURL = window.localStorage.externalReleaseURL;
+ } else if (window.localStorage.dtpsLoaderPref == "local") {
+ baseURL = "http://localhost:2750";
+ }
+
+ //Set DTPS loader parameters
+ var s = document.createElement("script");
+ s.textContent = "window.dtpsPreLoader = true;window.dtpsBaseURL = '" + baseURL + "'";
+ s.async = false;
+ s.setAttribute("dtps", "true");
+ document.documentElement.appendChild(s);
+
+ //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;
+ s.setAttribute("dtps", "true");
+ document.documentElement.appendChild(s);
+
+ //Hash global user ID for extra privacy
+ window.crypto.subtle.digest("SHA-256", new TextEncoder().encode(guuid)).then(data => {
+ //unique hash
+ let uh = Array.from(new Uint8Array(data)).map((b) => b.toString(16).padStart(2, '0')).join('');
+
+ //Wait for page to load
+ window.onload = function () {
+ //Stop observer
+ observer.disconnect();
+
+ //Determine LMS script to load
+ var lmsScript = null;
+ if (window.location.hostname === "dtechhs.instructure.com") {
+ lmsScript = "dtech";
+ } else {
+ lmsScript = "canvas";
+ }
+
+ //Check for debugging LMS overrides
+ if (window.localStorage.dtpsLMSOverride) lmsScript = window.localStorage.dtpsLMSOverride;
+
+ //Add script to DOM
+ var s = document.createElement("script");
+ s.src = useClassicDTPS ? "https://classic.powerplus.app/init.js" : baseURL + "/scripts/lms/" + lmsScript + ".js?uh=" + uh;
+ s.async = false;
+ s.setAttribute("dtps", "true");
+ document.documentElement.appendChild(s);
+ s.onerror = function () {
+ //Couldn't load debugging script, fallback to production
+ if (window.localStorage.dtpsLoaderPref && (window.localStorage.dtpsLoaderPref !== "prod")) {
+ console.log("[DTPS CHROME] Failed to load development 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") && knownCanvasInstance) {
+ //redirect to Power+ after login
+ console.log("[DTPS Chrome] Redirecting after login...");
+ window.location.href = "/power+/";
+ } else {
+ let releaseType = null;
+ const loaderPref = window.localStorage.getItem("dtpsLoaderPref");
+ if (loaderPref === "external") releaseType = "Power+ (external)";
+ if (loaderPref === "local") releaseType = "Power+ (local)";
+
+ function injectDTPSButton(node) {
+ node.insertAdjacentHTML("beforeend", /*html*/`
+ <li class="menu-item ic-app-header__menu-list-item ">
+ <a id="global_nav_dtps_link" role="button" href="/power+/" class="ic-app-header__menu-list-link">
+ <div class="menu-item-icon-container" aria-hidden="true">
+ <svg xmlns="http://www.w3.org/2000/svg" class="ic-icon-svg ic-icon-svg--dtps" version="1.1" viewBox="0 0 48 63.999"><path d="m5.333 0c-2.946 0-5.333 2.4-5.333 5.333v48c0 2.933 2.388 5.333 5.333 5.333h5.333v5.333l6.667-5.333 6.667 5.333v-5.333h18.667c2.947 0 5.333-2.4 5.333-5.333v-2.667c0 2.933-2.387 5.333-5.333 5.333h-18.667v-5.333h-13.333v5.333h-4c-2.209 0-4-1.867-4-4 0-2.4 1.791-4 4-4h36c2.947 0 5.333-2.4 5.333-5.333v-37.333c0-2.933-2.387-5.333-5.333-5.333h-37.333z"/></svg>
+ </div>
+ <div class="menu-item__text">${releaseType || "Power+"}</div>
+ </a>
+ </li>
+ `);
+ }
+
+ if (knownCanvasInstance) {
+ //Inject button as the page loads in
+ const observer = new MutationObserver(mutations => {
+ mutations.forEach(({ addedNodes }) => {
+ addedNodes.forEach(node => {
+ //Power+ button
+ if (node.nodeType === 1 && node.id === "menu") {
+ injectDTPSButton(node);
+ }
+ })
+ })
+ });
+
+ // Starts the monitoring
+ observer.observe(document.documentElement, {
+ childList: true,
+ subtree: true
+ });
+ } else {
+ verifyCanvasInstance(() => {
+ injectDTPSButton(document.getElementById("menu"));
+ });
+ }
+ }
+})();
\ No newline at end of file
diff --git a/chrome/manifest.json b/chrome/manifest.json
index 9d5e15d..33576f1 100644
--- a/chrome/manifest.json
+++ b/chrome/manifest.json
@@ -1,23 +1,33 @@
{
- "manifest_version": 2,
-
+ "manifest_version": 3,
"name": "Power+",
"description": "A better UI for Canvas LMS",
- "version": "3.0.6",
- "background": {
- "scripts": ["background.js"]
- },
+ "version": "3.1.0",
"content_scripts": [
{
"run_at": "document_start",
- "matches": ["https://*.instructure.com/*", "https://powerplus.app/"],
- "js": ["communicator.js"]
+ "matches": [
+ "https://*/*"
+ ],
+ "js": [
+ "injector.js"
+ ]
+ }
+ ],
+ "web_accessible_resources": [
+ {
+ "resources": [
+ "loader.js"
+ ],
+ "matches": [
+ "*://*/*"
+ ]
}
],
"icons": {
- "16": "16.png",
- "32": "32.png",
- "48": "48.png",
- "128": "128.png"
- }
-}
+ "16": "16.png",
+ "32": "32.png",
+ "48": "48.png",
+ "128": "128.png"
+ }
+}
\ No newline at end of file
diff --git a/docs/README.md b/docs/README.md
index 789a14e..7b3b4ad 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -2,4 +2,4 @@
### Resources
- [Source code](https://bitbucket.org/jottocraft/dtps)
-- [Issue tracker](https://jottocraft.atlassian.net/jira/software/c/projects/DTPS/issues)
\ No newline at end of file
+- [Issue tracker](https://bugs.jottocraft.com)
\ No newline at end of file
diff --git a/package-lock.json b/package-lock.json
index eb21977..6c05dd8 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -7,6 +7,7 @@
"name": "dtps",
"license": "MIT",
"devDependencies": {
+ "@cloudflare/kv-asset-handler": "^0.2.0",
"express": "^4.17.2",
"foodoc": "^0.0.9",
"glob": "^7.2.0",
@@ -15,6 +16,7 @@
"ncp": "^2.0.0",
"rimraf": "^3.0.2",
"terser": "^5.10.0",
+ "ua-parser-js": "^1.0.32",
"wrangler": "^2.0.6"
}
},
@@ -30,6 +32,27 @@
"node": ">=6.0.0"
}
},
+ "node_modules/@cloudflare/kv-asset-handler": {
+ "version": "0.2.0",
+ "resolved": "https://registry.npmjs.org/@cloudflare/kv-asset-handler/-/kv-asset-handler-0.2.0.tgz",
+ "integrity": "sha512-MVbXLbTcAotOPUj0pAMhVtJ+3/kFkwJqc5qNOleOZTv6QkZZABDMS21dSrSlVswEHwrpWC03e4fWytjqKvuE2A==",
+ "dev": true,
+ "dependencies": {
+ "mime": "^3.0.0"
+ }
+ },
+ "node_modules/@cloudflare/kv-asset-handler/node_modules/mime": {
+ "version": "3.0.0",
+ "resolved": "https://registry.npmjs.org/mime/-/mime-3.0.0.tgz",
+ "integrity": "sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==",
+ "dev": true,
+ "bin": {
+ "mime": "cli.js"
+ },
+ "engines": {
+ "node": ">=10.0.0"
+ }
+ },
"node_modules/@esbuild-plugins/node-globals-polyfill": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/@esbuild-plugins/node-globals-polyfill/-/node-globals-polyfill-0.1.1.tgz",
@@ -3585,6 +3608,25 @@
"node": ">= 0.6"
}
},
+ "node_modules/ua-parser-js": {
+ "version": "1.0.32",
+ "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-1.0.32.tgz",
+ "integrity": "sha512-dXVsz3M4j+5tTiovFVyVqssXBu5HM47//YSOeZ9fQkdDKkfzv2v3PP1jmH6FUyPW+yCSn7aBVK1fGGKNhowdDA==",
+ "dev": true,
+ "funding": [
+ {
+ "type": "opencollective",
+ "url": "https://opencollective.com/ua-parser-js"
+ },
+ {
+ "type": "paypal",
+ "url": "https://paypal.me/faisalman"
+ }
+ ],
+ "engines": {
+ "node": "*"
+ }
+ },
"node_modules/uc.micro": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz",
@@ -3848,6 +3890,23 @@
"integrity": "sha512-FDge0dFazETFcxGw/EXzOkN8uJp0PC7Qbm+Pe9T+av2zlBpOgunFHkQPPn+eRuClU73JF+98D531UgayY89tow==",
"dev": true
},
+ "@cloudflare/kv-asset-handler": {
+ "version": "0.2.0",
+ "resolved": "https://registry.npmjs.org/@cloudflare/kv-asset-handler/-/kv-asset-handler-0.2.0.tgz",
+ "integrity": "sha512-MVbXLbTcAotOPUj0pAMhVtJ+3/kFkwJqc5qNOleOZTv6QkZZABDMS21dSrSlVswEHwrpWC03e4fWytjqKvuE2A==",
+ "dev": true,
+ "requires": {
+ "mime": "^3.0.0"
+ },
+ "dependencies": {
+ "mime": {
+ "version": "3.0.0",
+ "resolved": "https://registry.npmjs.org/mime/-/mime-3.0.0.tgz",
+ "integrity": "sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==",
+ "dev": true
+ }
+ }
+ },
"@esbuild-plugins/node-globals-polyfill": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/@esbuild-plugins/node-globals-polyfill/-/node-globals-polyfill-0.1.1.tgz",
@@ -6531,6 +6590,12 @@
"mime-types": "~2.1.24"
}
},
+ "ua-parser-js": {
+ "version": "1.0.32",
+ "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-1.0.32.tgz",
+ "integrity": "sha512-dXVsz3M4j+5tTiovFVyVqssXBu5HM47//YSOeZ9fQkdDKkfzv2v3PP1jmH6FUyPW+yCSn7aBVK1fGGKNhowdDA==",
+ "dev": true
+ },
"uc.micro": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz",
diff --git a/package.json b/package.json
index 441d4e1..426100a 100644
--- a/package.json
+++ b/package.json
@@ -4,6 +4,8 @@
"scripts": {
"start": "node dev.js",
"build": "node build.js",
+ "wd": "wrangler dev --port 2750",
+ "deploy": "wrangler publish",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
@@ -21,11 +23,12 @@
"author": "jottocraft",
"license": "MIT",
"bugs": {
- "url": "https://jottocraft.atlassian.net/browse/DTPS"
+ "url": "https://bugs.jottocraft.com"
},
"homepage": "https://powerplus.app",
"main": "server.js",
"devDependencies": {
+ "@cloudflare/kv-asset-handler": "^0.2.0",
"express": "^4.17.2",
"foodoc": "^0.0.9",
"glob": "^7.2.0",
@@ -34,6 +37,7 @@
"ncp": "^2.0.0",
"rimraf": "^3.0.2",
"terser": "^5.10.0",
+ "ua-parser-js": "^1.0.32",
"wrangler": "^2.0.6"
}
}
diff --git a/scripts/core.js b/scripts/core.js
index 3fbf9d7..e4c5c7c 100644
--- a/scripts/core.js
+++ b/scripts/core.js
@@ -1,7 +1,7 @@
/**
* @file DTPS Core functions and module loader
* @author jottocraft
- * @version v3.7.0
+ * @version v3.8.0
*
* @copyright Copyright (c) 2018-2022 jottocraft
* @license MIT
@@ -38,8 +38,8 @@
* @property {string} cblSpec A URL to the CBL specification document used by dangerous Power+ CBL features
*/
var dtps = {
- ver: 370,
- readableVer: "v3.7.0",
+ ver: 380,
+ readableVer: "v3.8.0",
env: new URL(window.dtpsBaseURL || "https://powerplus.app").hostname == "localhost" ? "dev" : window.jottocraftSatEnv || "prod",
classes: [],
baseURL: window.dtpsBaseURL || "https://powerplus.app",
@@ -154,15 +154,16 @@
* Fetches and displays the DTPS changelog modal
*
* @param {number} fromVersion The previous version of DTPS installed. Will show popup changelogs since that version, if there aren't any, it will silently skip.
+ * @param {boolean} draft True to show draft changelogs
*/
-dtps.changelog = function (fromVersion) {
+dtps.changelog = function (fromVersion, draft = false) {
let changelogFetchURL;
if (fromVersion) {
//Check for popup w/ all previous important updates query
changelogFetchURL = `https://bugs.jottocraft.com/api/issues?query=${encodeURIComponent(`project: RRS product: dtps rollout: released version code: ${fromVersion + 1} .. ${dtps.ver} popup: popup sort by: {version code} desc`)}&fields=summary,description,idReadable,customFields(projectCustomField(field(name)),value(name))`;
} else {
//Latest query
- changelogFetchURL = `https://bugs.jottocraft.com/api/issues?query=${encodeURIComponent(`project: RRS product: dtps rollout: released version code: * .. ${dtps.ver} sort by: {version code} desc`)}&fields=summary,description,idReadable,customFields(projectCustomField(field(name)),value(name))&$top=1`;
+ changelogFetchURL = `https://bugs.jottocraft.com/api/issues?query=${encodeURIComponent(`project: RRS product: dtps rollout: ${draft ? "draft" : "released"} version code: * .. ${dtps.ver} sort by: {version code} desc`)}&fields=summary,description,idReadable,customFields(projectCustomField(field(name)),value(name))&$top=1`;
}
jQuery.getScript("https://cdnjs.cloudflare.com/ajax/libs/showdown/1.8.6/showdown.min.js", function () {
@@ -189,7 +190,9 @@
<p style="margin: 6px 0px;">${releaseDateFormatted}</p>
</div>
<br />
- ${changelogHTML}
+ <div id="changelogStyles">
+ ${changelogHTML}
+ </div>
`);
});
@@ -205,7 +208,7 @@
jQuery(".card.changelog").html(`
<i onclick="fluid.cards.close('.card.changelog')" class="fluid-icon close">close</i>
${releasesHTML.join(`<div style="margin: 40px 0px !important;" class="divider"></div>`)}
- <br /><br />
+ <br />
<button onclick="window.open('https://bugs.jottocraft.com/issues?q=project:%20RRS%20product:%20dtps%20rollout:%20released%20sort%20by:%20%7Bversion%20code%7D%20desc')" class="btn small outline"><i class="fluid-icon">update</i> View previous changelogs</button>
`);
@@ -273,10 +276,12 @@
<div class="welcomeSection">
<i class="fluid-icon">security</i>
<h5>Privacy</h5>
- <p>Power+ records your device & network type, Canvas institution, country, and state/region when you load Power+.
- Power+ does <b>not</b> utilize cookies or fingerprinting when collecting data.
- Additionally, data is collected directly by Power+ and is never shared with or sold to any third parties.
+ <p>
+ Power+ records your device and network type, Canvas institution, and region when you load Power+.
+ Analytics events are associated with a unique ID generated with a one-way-hash from your Canvas ID and institution.
+ Data is collected directly by Power+ and is never shared with or sold to any third parties.
Power+ does <b>not</b> and will <b>never</b> collect any personal information, such as names, classes, or grades.
+ </p>
</div>
<div class="welcomeSection">
<i class="fluid-icon">priority_high</i>
@@ -759,7 +764,7 @@
//Changelog will only show if the release notes are on GitHub
dtps.changelog(Number(window.localStorage.dtps));
}
-
+
//Render inbox
if (dtpsLMS.fetchUnreadMessageCount) {
dtpsLMS.fetchUnreadMessageCount().then(count => {
@@ -1900,7 +1905,12 @@
<img src="${dtps.baseURL + "/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 + (dtps.unstable ? ` <span style="font-size: 12px; color: red;">(unstable)</span>` : "")}</p>
+ <p>
+ <span style="vertical-align: middle;">${dtps.readableVer}</span>
+ <span style="margin: 0 1.5px; display: inline-block; color: var(--secText);"></span>
+ <a target="_blank" style="color: var(--lightText); font-size: 12px; vertical-align: middle;" href="https://jottocraft.com/feedback?key=dtps"><i class="fluid-icon" style="vertical-align: middle; font-size: 14px; margin: 0 1px 0 0;">feedback</i> Feedback</a>
+ </p>
+ ${(dtps.unstable ? `<p style="font-size: 12px; color: red; margin-top: 6px;">UNSTABLE</p>` : "")}
</div>
</div>
@@ -2080,6 +2090,10 @@
<button onclick="dtps.firstrun()" class="btn small"><i class="fluid-icon">web_asset</i> Show firstrun screen</button>
</div>
+ <div>
+ <button onclick="dtps.changelog(undefined, true);" class="btn small"><i class="fluid-icon">description</i> Show draft changelog</button>
+ </div>
+
<br /><br />
<h5>Release configuration</h5>
@@ -2141,8 +2155,7 @@
</div>
<div style="margin-top: 15px; margin-bottom: 7px;"><a onclick="dtps.changelog();" style="color: var(--lightText); margin: 0px 5px;" href="#"><i class="fluid-icon" style="vertical-align: middle">update</i> Changelog</a>
- <a onclick="if (window.confirm('Are you sure you want to uninstall Power+? The extension will be removed and all of your Power+ data will be erased. If you use the Power+ bookmarklet, you will have to remove that yourself.')) { document.dispatchEvent(new CustomEvent('extensionData', { detail: 'extensionUninstall' })); window.localStorage.clear(); window.alert('Power+ has been uninstalled. Reload the page to go back to ${dtpsLMS.shortName}.') }" style="color: var(--lightText); margin: 0px 5px; cursor: pointer;"><i class="fluid-icon" style="vertical-align: middle">delete_outline</i> Uninstall</a>
- <a style="color: var(--lightText); margin: 0px 5px;" href="mailto:[email protected]"><i class="fluid-icon" style="vertical-align: middle">email</i> Contact me ([email protected])</a>
+ <a style="color: var(--lightText); margin: 0px 5px;" href="mailto:[email protected]"><i class="fluid-icon" style="vertical-align: middle">email</i> Contact me: [email protected]</a>
</div>
</div>
diff --git a/scripts/lms/dtech.js b/scripts/lms/dtech.js
index 3daca8a..bcf7e84 100644
--- a/scripts/lms/dtech.js
+++ b/scripts/lms/dtech.js
@@ -9,7 +9,7 @@
*/
//Load Canvas integration
-jQuery.getScript(window.dtpsBaseURL + "/scripts/lms/canvas.js", function () {
+jQuery.getScript(window.dtpsBaseURL + "/scripts/lms/canvas.js?upstream=true", function () {
//Get global dangerous CBL preference
const dangerousCBLEnabled = window.localStorage.getItem("pref-dangerousCBL") == "true";
diff --git a/server/index.js b/server/index.js
new file mode 100644
index 0000000..52cb910
--- /dev/null
+++ b/server/index.js
@@ -0,0 +1,91 @@
+/**
+ * Power+ Production Server v2
+ * (c) jottocraft 2022. All rights reserved.
+ */
+
+import { getAssetFromKV, NotFoundError, MethodNotAllowedError } from '@cloudflare/kv-asset-handler';
+import manifestJSON from '__STATIC_CONTENT_MANIFEST';
+import UAParser from "ua-parser-js";
+
+const assetManifest = JSON.parse(manifestJSON);
+
+async function logAnalyticsEvent(url, request, env, ctx) {
+ //Collect statistics about this event
+ const entrypoint = url.pathname.split("/").pop();
+ const colo = request.cf.colo;
+ const canvasInstance = new URL(request.headers.get("Referer")).hostname;
+ const uh = url.searchParams.get("uh");
+ const country = request.cf.country;
+ const region = request.cf.regionCode;
+ const deviceOS = new UAParser(request.headers.get("User-Agent")).getOS();
+ const isp = request.cf.asOrganization;
+
+ //Record statistics
+ await env.EVENTS.writeDataPoint({
+ blobs: [
+ canvasInstance,
+ entrypoint,
+ country,
+ region,
+ colo,
+ deviceOS,
+ isp
+ ],
+ indexes: [uh]
+ });
+}
+
+async function serveKV(request, env, ctx) {
+ const url = new URL(request.url);
+
+ try {
+ const res = await getAssetFromKV(
+ {
+ request,
+ waitUntil: (promise) => ctx.waitUntil(promise)
+ },
+ {
+ ASSET_NAMESPACE: env.__STATIC_CONTENT,
+ ASSET_MANIFEST: assetManifest
+ }
+ );
+
+ ctx.waitUntil(async function () {
+ //Log analytics event
+ if (
+ url.pathname.startsWith("/scripts/lms/")
+ && url.pathname.endsWith(".js")
+ && (url.searchParams.get("upstream") !== "true")
+ && url.searchParams.get("uh")
+ ) {
+ logAnalyticsEvent(url, request, env, ctx);
+ }
+ });
+
+ return res;
+ } catch (e) {
+ if (e instanceof NotFoundError) {
+ url.pathname = "/404.html";
+ return await getAssetFromKV(
+ {
+ request: new Request(url, request),
+ waitUntil: (promise) => ctx.waitUntil(promise)
+ },
+ {
+ ASSET_NAMESPACE: env.__STATIC_CONTENT,
+ ASSET_MANIFEST: assetManifest
+ }
+ );
+ } else if (e instanceof MethodNotAllowedError) {
+ return new Response('Error 405 Method Not Allowed', { status: 405 });
+ } else {
+ return new Response('Error 500 An unexpected error occurred', { status: 500 });
+ }
+ }
+}
+
+export default {
+ async fetch(request, env, ctx) {
+ return await serveKV(request, env, ctx);
+ }
+};
diff --git a/ui/dtps.css b/ui/dtps.css
index a98ae7b..9debc04 100644
--- a/ui/dtps.css
+++ b/ui/dtps.css
@@ -3,6 +3,18 @@
(c) jottocraft 2018-2022
*/
+#changelogStyles {
+ line-height: 1.6;
+}
+
+#changelogStyles li {
+ margin: 8px 0px;
+}
+
+#changelogStyles h4 {
+ font-size: 22px;
+}
+
.card.alert h5 {
font-size: 20px;
}
diff --git a/ui/fluid.css b/ui/fluid.css
index 67fd39f..d22c980 100644
--- a/ui/fluid.css
+++ b/ui/fluid.css
@@ -180,7 +180,7 @@
}
body.themeImage input:not(.filled):not([type=submit]):not([type=color]):not([type=range]):not([type=file]):not([type=checkbox]):not([type=button]):not([type=radio]):not([type=reset]),
-body.themeImage button.outline, body.themeImage textarea, body.themeImage .block:not(.clickable):not(.card), body.themeImage code {
+body.themeImage button.outline, body.themeImage textarea, body.themeImage .block:not(.clickable):not(.card) {
backdrop-filter: blur(20px) !important;
background: var(--lightAcrylic) !important;
}
@@ -812,166 +812,6 @@
box-shadow: var(--elementShadow);
}
-/* Code
--------------------------------------------------- */
-
-code {
- display: block;
- font-family: monospace, monospace !important;
- font-size: 16px;
- padding: 20px;
- box-shadow: var(--lightShadow) !important;
- overflow: auto;
- border-radius: var(--cardRadius);
- background: var(--content);
-}
-
-code * {
- font-family: monospace, monospace !important;
-}
-
-/* desert scheme ported from vim to google prettify */
-
-code .nocode {
- background-color: none;
- color: var(--text);
-}
-
-code .str {
- color: #ffa0a0
-}
-
-/* string - pink */
-
-code .kwd {
- color: #f0e68c
-}
-
-code .com {
- color: #87ceeb
-}
-
-/* comment - skyblue */
-
-code .typ {
- color: #98fb98
-}
-
-/* type - lightgreen */
-
-code .lit {
- color: #cd5c5c
-}
-
-/* literal - darkred */
-
-code .pun {
- color: var(--text)
-}
-
-/* punctuation */
-
-code .pln {
- color: var(--text)
-}
-
-/* plaintext */
-
-code .tag {
- color: #f0e68c
-}
-
-/* html/xml tag - lightyellow */
-
-code .atn {
- color: #bdb76b
-}
-
-/* attribute name - khaki */
-
-code .atv {
- color: #ffa0a0
-}
-
-/* attribute value - pink */
-
-code .dec {
- color: #98fb98
-}
-
-/* decimal - lightgreen */
-
-/* stackoverflow code formatting for light themes */
-
-[data-theme-type=light] code .nocode {
- background-color: none;
- color: var(--text);
-}
-
-[data-theme-type=light] code .str {
- color: #7D2727
-}
-
-/* string - pink */
-
-[data-theme-type=light] code .kwd {
- color: #101094
-}
-
-[data-theme-type=light] code .com {
- color: #858C93
-}
-
-/* comment - skyblue */
-
-[data-theme-type=light] code .typ {
- color: #2B91AF
-}
-
-/* type - lightgreen */
-
-[data-theme-type=light] code .lit {
- color: #7D2727
-}
-
-/* literal - darkred */
-
-[data-theme-type=light] code .pun {
- color: var(--text)
-}
-
-/* punctuation */
-
-[data-theme-type=light] code .pln {
- color: var(--text)
-}
-
-/* plaintext */
-
-[data-theme-type=light] code .tag {
- color: #7D2727
-}
-
-/* html/xml tag - lightyellow */
-
-[data-theme-type=light] code .atn {
- color: #E64320
-}
-
-/* attribute name - khaki */
-
-[data-theme-type=light] code .atv {
- color: #0F74BD
-}
-
-/* attribute value - pink */
-
-[data-theme-type=light] code .dec {
- color: #101094
-}
-
-/* decimal - lightgreen */
-
/* Input
-------------------------------------------------- */
@@ -1868,9 +1708,9 @@
.sidenav .title h5 {
font-size: 22px;
- height: 40px;
+ height: 24px;
margin: 0;
- line-height: 40px;
+ line-height: 24px;
}
.sidenav .title p {
diff --git a/wrangler.toml b/wrangler.toml
new file mode 100644
index 0000000..44fea80
--- /dev/null
+++ b/wrangler.toml
@@ -0,0 +1,13 @@
+name = "dtps"
+main = "server/index.js"
+compatibility_date = "2022-11-09"
+account_id = "17174d3fc7098a664b04fb3c4c4ec65c"
+workers_dev = false
+
+[site]
+bucket = "./build"
+
+[[unsafe.bindings]]
+type = "analytics_engine"
+name = "EVENTS"
+dataset = "dtps_events"
\ No newline at end of file