果壳选课优化

优化果壳选课界面

目前為 2022-08-31 提交的版本,檢視 最新版本

// ==UserScript==
// @name         果壳选课优化
// @namespace    https://jwxk.ucas.ac.cn/
// @version      0.1
// @description  优化果壳选课界面
// @author       You
// @include        *//jwxk.ucas.ac.cn/courseManage/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=ucas.ac.cn
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    function hideFullCourse() {
        let body = document.querySelector("#regfrm > table > tbody")
        if (body === null) {
            return
        }
        for (let i = 0; i < body.childElementCount; i++) {
            let node = body.children[i]
            if (node.firstElementChild.firstElementChild.disabled) {
                node.style.display = "none"
            }
        }
    }

    function showEnglishCourseButton() {
        let box = document.querySelector("#regfrm2 > div:nth-child(9)")
        if (box === null) {
            return
        }
        let button = document.createElement('button')
        button.id = 'go-english-btn'
        button.innerHTML = '跳转英语课'
        button.setAttribute('class', 'btn btn-primary')
        button.setAttribute('type', 'submit')
        button.onclick = function() {
            document.querySelector("#id_915").checked = true
            document.querySelector("#regfrm2 > div:nth-child(9) > button").click()
        }
        box.appendChild(button)
    }

    function showCourseCount() {
        let body = document.querySelector("#regfrm > table > tbody")
        if (body === null) {
            return
        }
        let count = 0
        for (let i = 0; i < body.childElementCount; i++) {
            let node = body.children[i]
            if (!node.firstElementChild.firstElementChild.disabled) {
                count++
            }
        }
        let node = document.querySelector("#main-content > div > div.m-cbox.m-lgray > div.mc-body > div.alert-danger")
        node.innerHTML = node.innerHTML + '<br/>当前可选课程数量:' + count
    }

    function start() {
        console.log('start')
        hideFullCourse()
        showEnglishCourseButton()
        showCourseCount()
    }
    setTimeout(start, 100)
})();