Hdu课程总学分统计

统计hdu教务系统里当前界面的已选学分的辅助工具

目前為 2020-06-04 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Hdu课程总学分统计
// @namespace    http://tampermonkey.net/
// @version      1.00
// @description  统计hdu教务系统里当前界面的已选学分的辅助工具
// @author       litStronger
// @include      http://jxgl.hdu.edu.cn/*
// @grant        none

// ==/UserScript==
/*jshint esversion: 6 */
var calCredit = function () {
    'use strict';
    // Your code here...
    let credit = getNowPageCredit();
    setShownCredit(credit);

};
var getNowPageCredit = function () {
    let credit = 0;
    let allclass = document.querySelectorAll("#kcmcgrid > tbody >tr");
    for (let i = 1; i <= allclass.length - 2; ++i) {
        //table,i从1开始,到allclass.length-2结束,这里i=0是表头,表尾length-1这里表示table的页面跳转
        let selected = allclass[i].cells[8].innerText;
        if (selected === "已选") {
            credit = credit + parseFloat(allclass[i].children[4].innerText)
        }
    }
    return credit;
};
var setShownCredit = function (totalCredit) {
    let newtext = document.querySelector("#Table1 > tbody > tr.trtitle > td:nth-child(5)");
    newtext.innerText = "当前界面已选学分";
    let position = document.querySelector("#Table1 > tbody > tr:nth-child(2) > td:nth-child(5)");
    position.innerText = totalCredit;
};
setTimeout(calCredit,1000);
var showTotalCredit = function () {
    var tbodyp = document.getElementById("DBGrid");

    var tbody = tbodyp.children[0];
    var tbodyChildren = tbody.children;
    var sum = 0;
    for (let i = 1; i < tbodyChildren.length; ++i) {
        sum += parseFloat(tbodyChildren[i].children[5].innerText);
    }

    console.log("tool box");

    let toolBox = document.getElementsByClassName("toolbox")[0]
    console.log("tool box");
    var toolBoxMsg = document.getElementsByClassName("toolbox")[0].innerHTML;

    console.log(toolBox);
        console.log(toolBoxMsg);

    toolBox.innerHTML = toolBoxMsg+"<p>该学期已选学分"+sum+"</p>"
};

setTimeout(showTotalCredit, 1000);