WHU Gpa Calc

WHU Gpa Calculator which will remove unrelated courses and calculate your gpa automatically.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         WHU Gpa Calc
// @license      GPLV3
// @namespace    https://github.com/liaosunny123/WHUGpaCalc
// @version      1.0.0
// @description  WHU Gpa Calculator which will remove unrelated courses and calculate your gpa automatically.
// @author       EpicMo
// @match        https://jwgl.whu.edu.cn/cjcx/cjcx_cxDgXscj.html?gnmkdm=N305005*
// @require      https://code.jquery.com/jquery-3.6.1.min.js
// ==/UserScript==

(async function() {
    //void conflict with the default JQ of the page
    window.jQuery361 = $.noConflict(true)
    
    //get the archivement element group
    var classArrs = []
    var gpa = 0.0
    function gpaCalc(classArrs){
        var sum = 0.0
        var sumStandardScore = 0.0
        classArrs.forEach(sp => {
            if(sp.type == '通识教育选修'){
                return;
            }
            sum += parseFloat(sp.score) * parseFloat(sp.standardScore)
            sumStandardScore += parseFloat(sp.standardScore)
        })
        return sum / sumStandardScore
    }

    function sleep(ms) {
        return new Promise(resolve => setTimeout(resolve, ms))
    }

    var arrs = $('#tabGrid').children().children('.ui-row-ltr')
    //await sleep(5000)

    async function getScore(){
        var count = 0
        while(count <= 21){
            if(arrs.length == 0){
                await sleep(500)
                arrs = $('#tabGrid').children().children('.ui-row-ltr')
                count++
            }else{
                arrs = $('#tabGrid').children().children('.ui-row-ltr')
                break
            }
        }

        if(count == 21){
            return 4.0
        }else{
            $.each(arrs, function(index, value){
                var cell = $(value).children()
                var classArr = {
                    classNo: $(cell[3]).text(),
                    className: $(cell[4]).text(),
                    standardScore: $(cell[6]).text(),
                    score: $(cell[9]).text(),
                    type: $(cell[5]).text()
                }
                Object.assign(classArrs, {[index]: classArr})
            })
            return gpaCalc(classArrs)
        }
    }
    
    gpa = (await getScore())

    console.log('GPA Calc: ' + gpa)

    var span = $('<span>有效绩点:' + gpa.toFixed(2) +' </span>')
    $('.col-sm-2').children().before(span)

    document.getElementById('search_go').addEventListener('click', async function(){
        console.log('GPA Calc: ' + (await getScore()))
        $('.col-sm-2').children().eq(0).text('有效绩点:' + (await getScore()).toFixed(2) + ' ')
    })
})()