Crowdmark Assignment Saver

Save your crowdmark assignments for local access. Works well with ctrl+P (if it doesn't fit, try changing your paper size/orientation/scale).

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Crowdmark Assignment Saver
// @namespace    local
// @version      1.3
// @description  Save your crowdmark assignments for local access. Works well with ctrl+P (if it doesn't fit, try changing your paper size/orientation/scale).
// @match        https://app.crowdmark.com/*
// @grant        none
// @run-at       document-end
// @license      unlicense
// ==/UserScript==

(function () {
"use strict";

let lastUrl = null;
let btn = null;
function callback() {
    if (lastUrl !== location.href) {
      lastUrl = location.href;
      if(location.pathname.startsWith("/student/assessments")) {
        addButton();
      } else {
        removeButton();
      }
    }
}

window.addEventListener("load", callback);

new MutationObserver(callback).observe(document, { subtree: true, childList: true });

function exportQuestions() {

    const elements = [...document.getElementsByClassName("processed-text")];

    if (!elements.length) {
        alert("No .processed-text elements found.");
        return;
    }

    const combined = elements.map((el, i) => `
<section class="question">
  <h2>Question ${i + 1}</h2>
  ${el.innerHTML}
</section>
`).join("<hr>");

    const html = `
<html>
<head>
${document.head.innerHTML}

<style>
:root{
  --base:#fff;
  --mantle:#fff;
  --surface0:#fff;
  --text:#000;
}

body{
  background:var(--base);
  color:var(--text);
  font-family:system-ui, sans-serif;
  line-height:1.65;
  margin:40px;
}

.question{
  background:var(--base);
  border: none;
  border-radius:10px;
  padding:24px;
  margin-bottom:36px;

  break-inside: avoid;
  page-break-inside: avoid;
}

h2{
  margin-top:0;
  margin-bottom:12px;
  color:var(--text);   /* dark instead of blue */
}

/* PRINT STYLES */
@media print {

  @page{
    margin:12mm;   /* tighter PDF margins */
  }

  body{
    background:white;
    color:black;
    margin:0;      /* avoid double margins */
  }
  h2 {
    color: black;
  }
  hr {
    display: none;
  }

  .question{
    background:none;
    border: none;
    box-shadow:none;

    break-inside: avoid;
    page-break-inside: avoid;
  }

  p, li{
    orphans:3;
    widows:3;
  }

  mjx-container[display="true"]{
    break-inside: avoid;
    overflow:visible;
    max-width:100%;
    transform:scale(0.95);
    transform-origin:left top;
  }
}
</style>
</head>
<body>
${combined}
</body>
</html>
`;

    const blob = new Blob([html], { type: "text/html" });
    const url = URL.createObjectURL(blob);

    window.open(url, "_blank");
}

function addButton() {

    btn = document.createElement("button");
    btn.textContent = "Export Questions";

    Object.assign(btn.style, {
        position: "fixed",
        bottom: "20px",
        left: "20px",
        zIndex: "9999",
        padding: "10px 16px",
        borderRadius: "8px",
        border: "none",
        background: "#8caaee",
        color: "#303446",
        fontWeight: "600",
        cursor: "pointer"
    });

    btn.addEventListener("click", exportQuestions);

    document.body.appendChild(btn);
}
function removeButton() {
  if (btn) {
   btn.remove();
  }
}
})();