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).

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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();
  }
}
})();