NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name Pages // @namespace CCAU // @description Automate course copies // @match https://*.instructure.com/courses/*/pages // @version 0.2.0 // @author 18-carat // @grant none // @license GPL-3.0-or-later // ==/UserScript== "use strict"; (() => { // out/ccau.js function isAdmin() { const adminButton = document.querySelector("#global_nav_accounts_link"); return adminButton ? true : false; } function getCourseID() { return window.location.href.match(/courses\/(\d+)/)?.[1] ?? "NO_COURSE_ID"; } async function isLiveCourse() { const response = await fetch("https://se.instructure.com/api/v1/courses/" + getCourseID()); const data = await response.json(); if (!data.start_at) { return new Promise((resolve) => resolve(true)); } return new Date(data.start_at) < /* @__PURE__ */ new Date(); } function observeDOM(element, callback) { const observer = new MutationObserver(callback); observer.observe(element, { childList: true }); return observer; } function clickButton(sel) { const element = document.querySelector(sel); const button = element; button?.click(); } // out/checkbox.js function deleteAll() { const selectAll = document.querySelector("#ccau_selectAll"); const checked = selectAll?.checked; const updatedPages = [ "University Information", "\u270F\uFE0FSE Evaluation Information", "Prerequisite Knowledge/Skills" ]; Array.from(document.querySelectorAll(".select-page-checkbox")).map((e) => e).filter((e) => e.checked != checked).filter((e) => updatedPages.find((p) => e.ariaLabel?.includes(p)) == void 0).forEach((e) => e.click()); if (checked) { clickButton(".delete_pages"); } } function addButton() { const slot = document.querySelector("thead > tr > th"); const selectAll = document.createElement("input"); selectAll.type = "checkbox"; selectAll.id = "ccau_selectAll"; selectAll.onclick = deleteAll; if (!slot || slot?.innerHTML.includes(selectAll.id)) { return; } slot?.appendChild(selectAll); } // out/index.js async function main() { if (!isAdmin()) { throw new Error("Only admins can use CCAU"); } if (await isLiveCourse()) { throw new Error("CCAU is disabled in live courses"); } observeDOM(document.body, () => setTimeout(addButton, 1e3)); } main(); })();