Copy Code From CQUPT Code Question Lib

Copy code from CQUPT code question lib

2021-05-27 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

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

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

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

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

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

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

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

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

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

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

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Copy Code From CQUPT Code Question Lib
// @namespace    http://172.20.2.205/ctas/student.htm/
// @version      0.1.1
// @description  Copy code from CQUPT code question lib
// @author       Lomirus
// @match        http://172.20.2.205/ctas/student.htm
// @icon         https://www.google.com/s2/favicons?domain=2.205
// @grant        GM_setClipboard
// ==/UserScript==

'use strict';

window.onload = function() {
    const body = document.querySelector("frame").contentWindow.document.body;
    const getCodeButton = document.createElement("button");
    getCodeButton.textContent = "复制";
    getCodeButton.style.position = "absolute";
    getCodeButton.style.display = "block";
    getCodeButton.style.top = "0";
    getCodeButton.style.left = "40vw";
    getCodeButton.style.height= "56px";
    getCodeButton.style.width= "120px";
    getCodeButton.style.fontSize= "20px";
    getCodeButton.onclick = async () => {
        try {
            GM_setClipboard(getCode())
            alert("复制成功🧐")
        } catch {
            alert("😅复制麻了")
        }
    }
    body.appendChild(getCodeButton)
};


function getCode() {
    const ProgramContent = document.querySelector("frame")
        .contentWindow.document.querySelector("iframe")
        .contentWindow.document.querySelector("#ProgramContent")
        .childNodes;
    const elements = [...ProgramContent]
    return (
        elements
            .filter(el => el.nodeName === '#text')
            .map(el => el.textContent)
            .map(t => t.replace(/ /g, " "))
            .map(t => t.replace(/\d*?\)(.*)/g, "$1"))
            .join("\n")
    )
}