Pages

Automate course copies

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name        Pages
// @namespace   CCAU
// @description Automate course copies
// @match       https://*.instructure.com/courses/*/pages
// @version     0.1.0
// @author      CIDT
// @grant       none
// @license     BSD-3-Clause
// ==/UserScript==
"use strict";
(() => {
  // out/utils.js
  function clickButton(sel) {
    const element = document.querySelector(sel);
    const btn = element;
    btn?.click();
  }
  function log(msg) {
    console.log("[CCAU] " + msg);
  }
  function observeDOM(element, callback) {
    const observer = new MutationObserver(callback);
    observer.observe(element, {
      childList: true
    });
    return observer;
  }

  // out/check.js
  function deleteAll() {
    const s = ".select-page-checkbox";
    const s2 = "#ccau_omnibox";
    const chk = document.querySelector(s2).checked;
    Array.from(document.querySelectorAll(s)).map((e) => e).forEach((box) => {
      const label = box.ariaLabel;
      if (box.checked !== chk && !label?.includes("University Information")) {
        box.click();
      }
    });
    if (chk) {
      clickButton(".delete_pages");
    }
  }
  function addButton() {
    const row = document.querySelector("thead");
    const slot = row?.children[0].children[0];
    const omniBox = document.createElement("input");
    omniBox.type = "checkbox";
    omniBox.id = "ccau_omnibox";
    omniBox.onclick = deleteAll;
    if (slot?.innerHTML.includes("ccau_omnibox")) {
      log("Omni-box already exists");
      return;
    }
    if (!row) {
      log("Row not found");
      return;
    }
    log("Adding omni-box");
    slot?.appendChild(omniBox);
  }

  // out/index.js
  observeDOM(document.body, () => {
    const msg0 = "This friendly creature sees all, however ";
    const msg1 = "it probably wont know what to do with it.";
    log(msg0 + msg1);
    setTimeout(addButton, 500);
  });
})();