Greasy Fork

Greasy Fork is available in English.

浙江理工大学体育理论考试辅助脚本-自动记录、恢复-SL大法好

保存写过的题目答案,并自动填写。

当前为 2020-12-31 提交的版本,查看 最新版本

// ==UserScript==
// @name         浙江理工大学体育理论考试辅助脚本-自动记录、恢复-SL大法好
// @namespace    https://eliotzhang.club
// @homepage     https://eliotzhang.club
// @version      1.0
// @description  保存写过的题目答案,并自动填写。
// @author       EliotZhang
// @match        http://tygl.zstu.edu.cn/*
// @run-at       document-end
// ==/UserScript==

(function () {
    'use strict';
    let EZ = '------浙理体育脚本 by EliotZhang------\n'
    let choice = ['A', 'B', 'C', 'D']
    var titles = null
    var length = 0

    function get_ans(k) {
        var st = titles[k].nextSibling.nextSibling
        var ans = ''
        while (st.style.length > 0) {
            if (st.firstChild.firstChild.checked) {
                ans = st.firstChild.firstChild.nextSibling.data.substr(2)
                break
            }
            st = st.nextSibling
        }
        return ans
    }

    function set_ans(k, ans) {
        var st = titles[k].nextSibling.nextSibling
        while (st.style.length > 0) {
            if (st.firstChild.firstChild.nextSibling.data.substr(2) === ans) {
                st.firstChild.firstChild.checked = true
                break
            }
            st = st.nextSibling
        }
    }

    function saveAns() {
        for (var i = 0; i < length; ++i) {
            var ans = get_ans(i)
            if (ans != '' && ans != undefined) {
                window.localStorage.setItem(titles[i].text, ans)
            }
        }
    }

    function loadAns() {
        for (var i = 0; i < length; ++i) {
            var ans = window.localStorage.getItem(titles[i].text)
            if (ans != null && ans != 'undefined') {
                set_ans(i, ans)
            }
        }
    }

    function main() {
        titles = $('a[id]')
        length = titles.length
        console.log(EZ, length)
        loadAns()
        setInterval(saveAns, 5000)
    }

    // Your code here...
    setTimeout(main, 5000)
})();