Greasy Fork

Greasy Fork is available in English.

雨课堂试题与试卷下载器(python学霸)

获取雨课堂考试试卷和试题内容

当前为 2023-12-04 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         雨课堂试题与试卷下载器(python学霸)
// @namespace    雨课堂内容与试卷下载器(python学霸)
// @version      2.0
// @description  获取雨课堂考试试卷和试题内容
// @author       python学霸
// @match        https://www.yuketang.cn/*
// @match        https://examination.xuetangx.com/*
// @match        https://www.yuketang.cn/v2/web/exam/*/*
// @match        https://examination.xuetangx.com/cover/*?isFrom=*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 下载内容的函数
    function downloadContent(content, filename) {
        var blob = new Blob([content], {type: 'text/plain'});
        var url = URL.createObjectURL(blob);
        var downloadButton = document.createElement('a');
        downloadButton.href = url;
        downloadButton.download = filename;
        downloadButton.textContent = '下载' + filename;
        downloadButton.style.display = 'block';
        downloadButton.style.margin = '10px auto';
        downloadButton.style.padding = '5px 15px';
        downloadButton.style.backgroundColor = '#4CAF50';
        downloadButton.style.color = 'white';
        downloadButton.style.textDecoration = 'none';
        downloadButton.style.border = 'none';
        downloadButton.style.borderRadius = '4px';
        downloadButton.style.cursor = 'pointer';
        var container = document.querySelector('.page-container') || document.body;
        if (container) {
            container.insertBefore(downloadButton, container.firstChild);
        }
    }

    // 检查是否在雨课堂的内容页面
    if (window.location.href.includes("www.yuketang.cn/cards/cards_info") || window.location.href.includes("www.yuketang.cn/v2/web/exam/")) {
        setTimeout(function() {
            var content = '';
            var slideLayers = document.querySelectorAll('.shape__text span');

            slideLayers.forEach(function(slideLayer) {
                var textContent = slideLayer.innerText;
                content += textContent + "\n\n";
            });

            if (content.trim().length > 0) {
                downloadContent(content, '雨课堂内容.txt');
            } else {
                console.error('没有找到.slide_layer元素或者内容为空');
            }
        }, 6000);
    }

    // 检查是否在雨课堂的试卷页面
    if (window.location.href.includes("examination.xuetangx.com/exam") || window.location.href.includes("examination.xuetangx.com/cover/")) {
        var examIdRegex = /\/exam\/(\d+)|\/cover\/(\d+)/;
        var matches = window.location.href.match(examIdRegex);
        var examId = matches[1] || matches[2];
        var accessToken = document.cookie.match(/x_access_token=([^;]+)/)[1];
        var url = "https://examination.xuetangx.com/exam_room/show_paper?exam_id=" + examId;

        fetch(url, {
            credentials: 'include',
            headers: {
                'Cookie': 'x_access_token=' + accessToken
            }
        })
        .then(response => response.json())
        .then(data => {
            var problems = data.data.problems;
            var content = '';

            for (var i = 0; i < problems.length; i++) {
                var problem = problems[i];
                content += problem.TypeText + "\n";
                content += problem.Body.replace(/<[^>]*>/g, '').replace(/\n/g, '') + "\n";

                if (problem.Options) {
                    for (var j = 0; j < problem.Options.length; j++) {
                        var option = problem.Options[j];
                        var key = option.key;
                        var value = option.value.replace(/<[^>]*>/g, '').replace(/\n/g, '');
                        content += key + ". " + value + "\n";
                    }
                }

                content += "+".repeat(10) + "\n";
            }

            downloadContent(content, "试卷_" + examId + ".txt");
        })
        .catch(error => console.log(error));
    }
})();