⭐SuperStarExam⭐

学习通复制粘贴、题目选项一键复制、答题框粘贴、自动保存

目前为 2023-04-28 提交的版本。查看 最新版本

// ==UserScript==
// @name         ⭐SuperStarExam⭐
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  学习通复制粘贴、题目选项一键复制、答题框粘贴、自动保存
// @author       载月明归
// @match        *://mooc1.chaoxing.com/exam-ans/exam/test/*
// @match        *://mooc1.chaoxing.com/exam-ans/exam/preview/*
// @include      *mooc2/exam/preview*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=chaoxing.com
// @grant        none
// @license      GPL
// ==/UserScript==

(function() {
    //     'use strict';
    var $ = $ || window.$;

    // 去除禁止选中和复制
    setTimeout(()=>{
        $("body").removeAttr("onselectstart");
        $("html").css("user-select", "unset");
    },1000);

    // 更改背景颜色
    $(".whiteDiv").css("background","white");

    // 判断新老学习通
    if(window.location.href.includes("newMooc=true")){
        let answerOptObj;
        let title = "";
        let optionStr = "";
        let task1 = false;
        let task2 = false;
        let interval1=setInterval(function(){

            if($(".mark_name").length > 0 && !task1){
                $(".mark_name").append("<b style='border: none;outline: none;background: white;cursor:default;user-select: none' class='copyButton';>copy</b>");
                $(".mark_name:eq(1)").css("background","white");

                // 拼接选项和答案并复制
                $(".copyButton").on("click",function(){
                    // 拼接答案选项
                    // alert($(this).parent().parent().find(".stem_answer").text().replace(/\r|\n/ig,""));
                    // title =$(this).siblings("span").text() + $(this).siblings("div").text();
                    title =$(this).parent("h3:eq(0)").text().split("copy")[0];// 题号+ 题型 + 题目
                    answerOptObj = $(this).parent().parent().find(".answerBg"); // 答案选项
                    optionStr = "" // 清空
                    for(let i = 0;i<answerOptObj.length;i++){
                        // alert(answerOptObj.eq(i).find("span").text())
                        // optionStr += answerOptObj.eq(i).find("span").text() +" "+ answerOptObj.eq(i).find("div").text() + "\n";
                        optionStr += answerOptObj.eq(i).text().replace(/\s+/g, ' ').trim() + "\n";
                    }
                    copyToBoard(title + "\n" + optionStr)
                });
                task1 = true;
            }

            if($("iframe#ueditor_0").length >0){
                // 粘贴
                $('iframe[id^="ueditor_"]').each(function (){
                    let bodyElement = $(this).contents().find('body');
                    let iframeObj = this;
                    bodyElement[0].addEventListener('paste', function(e){
                        e.stopPropagation();
                    }, true);
                    // 自动点保存
                    bodyElement.on("blur",function(){
                       $(iframeObj).parents(".sub_que_div_parent").find(".savebtndiv a").click();
                    });
                });

                task2 = true;
            }

            if(task1 && task2){
                setTimeout(function(){clearInterval(interval1);},1000);
            }

        });


        // alert("new Mooc")
    }
    else{
        // alert("old Mooc")
        let interval1=setInterval(function(){
            if($(".mark_name").length > 0){
                $(".mark_name").append("<button class='copyButton'>copy</button>");
                $(".copyButton").on("click",function(e){
                    copyToBoard(`${$(".mark_name:eq(0)").text()}`);
                    //alert($(".mark_name").find("div").text());
                    // 按钮在表单中 故阻止表单提交
                    // e.preventDefault();
                    // return false;
                });
                clearInterval(interval1);
            }
        });
    }


    // 复制到剪贴板
    function copyToBoard (text) {
        try {
            const input = document.createElement('textarea')
            input.value = text
            document.body.appendChild(input)
            // input.focus() // focus会滚动页面到input处
            input.select()
            document.execCommand('copy')
            document.body.removeChild(input)
        } catch (err) {
            alert("浏览器不支持")
        }
    }

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址