ChaoxingAnswerToggler

隐藏或显示学习通作业选择题答案,复习专用。

目前为 2023-12-03 提交的版本。查看 最新版本

// ==UserScript==
// @name         ChaoxingAnswerToggler
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  隐藏或显示学习通作业选择题答案,复习专用。
// @author       Cassius0924
// @match        https://mooc1.chaoxing.com/mooc-ans/mooc2/work/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=chaoxing.com
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function toggleAnswer(event) {
        var questionContainer = event.target.closest('.questionLi');
        var answerDiv = questionContainer.querySelector('.mark_answer');

        if (answerDiv.style.visibility === 'hidden' || answerDiv.style.visibility === '') {
            answerDiv.style.visibility = 'visible';
        } else {
            answerDiv.style.visibility = 'hidden';
        }
    }

    function hideAllAnswers() {
        var answerDivs = document.querySelectorAll('.mark_answer');
        answerDivs.forEach(function(answerDiv) {
            answerDiv.style.visibility = 'hidden';
        });
    }

    function showAllAnswers() {
        var answerDivs = document.querySelectorAll('.mark_answer');
        answerDivs.forEach(function(answerDiv) {
            answerDiv.style.visibility = 'visible';
        });
    }

    function createElement(tag, className, style, content) {
        const element = document.createElement(tag);
        className && (element.className = className);
        style && (element.style = style);
        content && (element.innerHTML = content);
        return element;
    }

    const haStyle = {
        globalStyle: '.ha_hidden_all_answer{margin-top: -20px; width: 90px; height: 32px} .ha_show_all_answer{margin-top: -10px; margin-right: 50px;width: 90px; height: 32px} .ha_toggle_answer_button {margin-top: -43px;margin-left: 24px;width: 70px;height: 32px;line-height: 32px;} .ha_button {box-shadow: -4px -4px 10px -8px rgba(255, 255, 255, 1), 4px 4px 10px -8px rgba(0, 0, 0, .3); background: linear-gradient(135deg, rgba(230, 230, 230, 1) 0%, rgba(246, 246, 246, 1) 100%);cursor: pointer;border: 1px solid #e5e5e5;border-radius: 5px;text-align: center;} .ha_mark_answer{margin-left: 100px;}',

        add(css) {
            this.globalStyle.innerHTML += css;
        },

        get() {
            return createElement('style', 'ms-global-style', '', this.globalStyle);
        }
    }

    var questionContainers = document.querySelectorAll('.questionLi');

    questionContainers.forEach(function(questionContainer) {
        var answerDiv = questionContainer.querySelector('.mark_answer');
        answerDiv.classList.add('ha_mark_answer');
        answerDiv.style.width = 'auto';
        answerDiv.style.visibility = 'visible';
        var showAnswerButton = createElement('button', 'ha_toggle_answer_button');
        showAnswerButton.classList.add('ha_button');
        showAnswerButton.textContent = '显示答案';
        showAnswerButton.addEventListener('click', toggleAnswer);

        questionContainer.appendChild(showAnswerButton);
    });

    const topicNumberContainer = document.querySelector('#topicNumberScroll');
    var haControlDiv = createElement('div', 'ha_control_div');
    haControlDiv.classList.add('topicNumber_checkbox');
    topicNumberContainer.appendChild(haControlDiv);

    var haShowAllButton = createElement('button', 'ha_show_all_answer');
    haShowAllButton.classList.add('ha_button');
    haShowAllButton.textContent = '显示所有答案';
    haShowAllButton.addEventListener('click', showAllAnswers);
    haControlDiv.appendChild(haShowAllButton);

    var haHiddenAllButton = createElement('button', 'ha_hidden_all_answer');
    haHiddenAllButton.classList.add('ha_button');
    haHiddenAllButton.textContent = '隐藏所有答案';
    haHiddenAllButton.addEventListener('click', hideAllAnswers);
    haControlDiv.appendChild(haHiddenAllButton);


    document.querySelector('.mark_table').appendChild(haStyle.get());
})();

QingJ © 2025

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