Greasy Fork

Greasy Fork is available in English.

cnmooc 测验显示所有题目

无描述

// ==UserScript==
// @name         cnmooc 测验显示所有题目
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  无描述
// @author       Teruteru
// @match        https://www.cnmooc.org/examTest/stuExamList/*.mooc
// @icon         https://www.google.com/s2/favicons?sz=64&domain=cnmooc.org
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';


    let targetNode = document.querySelector('#examContentDiv');
    let observerOptions = {
        childList: true, // 观察目标子节点的变化,添加或删除
        attributes: true, // 观察属性变动
        subtree: true, //默认是false,设置为true后可观察后代节点
    }
    function callback(mutationList, observer) {
        mutationList.forEach((mutation) => {
            switch(mutation.type) {
                case 'childList':
                    //console.log(mutation);
                    break;
                case 'attributes':
                    //console.log(mutation.target.className);
                    var wrapper = document.querySelector('#practice-wrapper');
                    if (mutation.target.className === "practice-wrapper")
                    {
                        mutation.target.style.height = "auto";
                        mutation.target.addEventListener('scroll', function(e){e.stopPropagation()}, true);

                    }
                    if (mutation.target.className === "view-test practice-item"){
                        function addClass(obj, cls){
                            var obj_class = obj.className,
                                blank = (obj_class != '') ? ' ' : '';
                            obj.className = obj_class + blank + cls;
                        };
                        addClass(mutation.target, "current");
                    }
                    break;
            }
        });
    }

    let observer = new MutationObserver(callback);
    observer.observe(targetNode, observerOptions);
})();