diff --git a/js/all-idle.js b/js/all-idle.js index cb3d4cdd..ae467bf8 100644 --- a/js/all-idle.js +++ b/js/all-idle.js @@ -1,5 +1,6 @@ -while (!window.splusLoaded || !window.splusLoaded.has("all")) { } -Logger.debug("Started loading all-idle.js"); +(async function() { + await loadDependencies("all-idle", ["all"]); +})(); // hack for course aliases (async function () { diff --git a/js/all.js b/js/all.js index e7d23a12..ac241f98 100644 --- a/js/all.js +++ b/js/all.js @@ -1,5 +1,10 @@ -while (!window.splusLoaded || !window.splusLoaded.has("preload")) { } -Logger.debug("Started loading all.js"); +(async function() { + // Wait for preload.js to finish running + while (!window.splusLoaded) { + await new Promise(resolve => setTimeout(resolve, 10)); + } + await loadDependencies("all", ["preload"]); +})(); // Inform user about theme { @@ -1259,5 +1264,4 @@ function indicateSubmittedAssignments() { setTimeout(indicateSubmitted, 1000); } -window.splusLoaded.add("all"); Logger.debug("Finished loading all.js"); \ No newline at end of file diff --git a/js/assessment.js b/js/assessment.js index 4a6ea57b..9f1a6fe7 100644 --- a/js/assessment.js +++ b/js/assessment.js @@ -1,5 +1,6 @@ -while (!window.splusLoaded || !window.splusLoaded.has("all")) { } -Logger.debug("Started loading assessment.js"); +(async function() { + await loadDependencies("assessment", ["all"]); +})(); // modifications to Confirm Submission assessment popup (function () { diff --git a/js/course.js b/js/course.js index 87119919..e758c469 100644 --- a/js/course.js +++ b/js/course.js @@ -1,5 +1,6 @@ -while (!window.splusLoaded || !window.splusLoaded.has("all")) { } -Logger.debug("Started loading course.js"); +(async function() { + await loadDependencies("course", ["all"]); +})(); let courseIdNumber; let courseSettingsCourseName; diff --git a/js/courses.js b/js/courses.js index 66e825cb..ed92ec5f 100644 --- a/js/courses.js +++ b/js/courses.js @@ -1,5 +1,6 @@ -while (!window.splusLoaded || !window.splusLoaded.has("all")) { } -Logger.debug("Started loading courses.js"); +(async function() { + await loadDependencies("courses", ["all"]); +})(); for (let course of document.querySelectorAll("li.course-item.list-item")) { let parent = course.parentNode; diff --git a/js/grades.js b/js/grades.js index 5a6c36b0..e6b137cb 100644 --- a/js/grades.js +++ b/js/grades.js @@ -1,5 +1,6 @@ -while (!window.splusLoaded || !window.splusLoaded.has("all")) { } -Logger.debug("Started loading grades.js"); +(async function() { + await loadDependencies("grades", ["all"]); +})(); const timeout = ms => new Promise(res => setTimeout(res, ms)); const BUG_REPORT_FORM_LINK = "https://docs.google.com/forms/d/e/1FAIpQLScF1_MZofOWT9pkWp3EfKSvzCPpyevYtqbAucp1K5WKGlckiA/viewform?entry.118199430="; diff --git a/js/home.js b/js/home.js index 5d30f50f..279a448e 100644 --- a/js/home.js +++ b/js/home.js @@ -1,5 +1,6 @@ -while (!window.splusLoaded || !window.splusLoaded.has("all")) { } -Logger.debug("Started loading home.js"); +(async function() { + await loadDependencies("home", ["all"]); +})(); /** @typedef {{id:number,title:string,message:string,timestamp?:Date,icon?:string}} Broadcast */ diff --git a/js/materials.js b/js/materials.js index 75d5766e..d6ab7c15 100644 --- a/js/materials.js +++ b/js/materials.js @@ -5,8 +5,9 @@ "use strict"; -while (!window.splusLoaded || !window.splusLoaded.has("all")) { } -Logger.debug("Started loading materials.js"); +(async function() { + await loadDependencies("materials", ["all"]); +})(); (async function () { let classId = window.location.pathname.match(/\/course\/(\d+)\/materials/)[1]; // ID of current course ("section"), as a string diff --git a/js/page.js b/js/page.js index c9ab6851..4da72f6e 100644 --- a/js/page.js +++ b/js/page.js @@ -1,5 +1,6 @@ -while (!window.splusLoaded || !window.splusLoaded.has("all")) { } -Logger.debug("Started loading page.js"); +(async function() { + await loadDependencies("page", ["all"]); +})(); // Adds an "Open in New Tab" link to /page pages which simply embed something. (function () { diff --git a/js/preload.js b/js/preload.js index 725f8310..a41b8712 100644 --- a/js/preload.js +++ b/js/preload.js @@ -1152,4 +1152,19 @@ new Setting( ); window.splusLoaded = new Set(["preload"]); + +async function loadDependencies(name, dependencies) { + if(window.splusLoaded.has(name)) { + throw new Error(`Already loaded ${name}`); + } + + while (!dependencies.every(d => window.splusLoaded.has(d))) { + Logger.debug(`Waiting to load ${name}: some of ${dependencies} not in ${window.splusLoaded}`); + await new Promise(resolve => setTimeout(resolve, 100)); + } + + window.splusLoaded.add(name); + Logger.debug(`Starting loading ${name}.js`); +} + Logger.debug("Finished loading preload.js"); \ No newline at end of file diff --git a/js/theme.js b/js/theme.js index b287c2b9..0dfff202 100644 --- a/js/theme.js +++ b/js/theme.js @@ -427,10 +427,17 @@ class Theme { }; let customSrc = Theme.getIcon(img.alt); if(img.src !== customSrc) { - Logger.debug(img, img.src, customSrc) img.src = customSrc; } img.classList.add("injected-course-icon"); + + if (img == bigCourseIcon && !document.querySelector("head > link[rel='icon'][type='image/svg+xml']")) { + let favicon = document.createElement("link"); + favicon.rel = "icon"; + favicon.type = "image/svg+xml"; + favicon.href = customSrc; + document.head.appendChild(favicon); + } } if (isLAUSD() && !shownMissingIconsNotification && coursesMissingDefaultIcons.size > 0 && showToast) { diff --git a/js/user.js b/js/user.js index 04dbdd83..45d6112d 100644 --- a/js/user.js +++ b/js/user.js @@ -1,3 +1,7 @@ +(async function() { + await loadDependencies("user", ["all"]); +})(); + (async function () { // I hate try..catch but It will work try { diff --git a/js/version-specific.js b/js/version-specific.js index fcdeed4f..e8e8354c 100644 --- a/js/version-specific.js +++ b/js/version-specific.js @@ -1,3 +1,11 @@ +(async function() { + // Wait for preload.js to finish running + while (!window.splusLoaded) { + await new Promise(resolve => setTimeout(resolve, 10)); + } + await loadDependencies("version-specific", ["preload"]); +})(); + /** Compares two version strings a and b. * @param {string} a A string representing a numerical version. * @param {string} b A string representing a numerical version. diff --git a/manifest.json b/manifest.json index df860606..a3ef8fb9 100644 --- a/manifest.json +++ b/manifest.json @@ -9,7 +9,7 @@ "id": "schoology.plus@aopell.me" } }, - "version": "7.2.2", + "version": "7.2.4", "icons": { "128": "imgs/icon@128.png", "64": "imgs/icon@64.png",