// ==UserScript== // @name Power+ Userscript Loader // @namespace https://powerplus.app/ // @version 1.1 // @description An alternate, customizable loader for Power+ // @author jottocraft // @license MIT // @icon https://powerplus.app/favicon.png // @grant none // @run-at document-start // @match https://*.instructure.com/power+* // @downloadURL none // ==/UserScript== (function () { 'use strict'; var s; //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; } //Replace canvas 404 page with Power+ const observer = new MutationObserver(mutations => { mutations.forEach(({ addedNodes }) => { addedNodes.forEach(node => { //Power+ preloader if (node.nodeType === 1 && node.tagName === 'BODY') { node.innerHTML = /*html*/`

`; } else if (node.nodeType === 1 && node.tagName === 'HEAD') { node.innerHTML = /*html*/` Power+ `; } 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 (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 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 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 { lmsScript = "canvas"; } //Check for debugging LMS overrides if (window.localStorage.dtpsLMSOverride) lmsScript = window.localStorage.dtpsLMSOverride; //Add script to DOM s = document.createElement("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 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."; } }; } })();