wsxy_autoSignup

网上学院函数库:自动报名

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

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/396002/769959/wsxy_autoSignup.js

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name          wsxy_autoSignup
// @namespace     Vionlentmonkey
// @version       0.2
// @description   网上学院函数库:自动报名
// @require       https://greasyfork.org/scripts/395748-wsxy-getdata/code/wsxy_getData.js
// @grant         none
// ==/UserScript==

// 自动报名高学分课程。2020年初,高于1学分的有且仅有20门3学分课程。
const autoSignupMaxCredit = async () => {
  // 彩蛋:需要 iframe 提升才会执行
  if (window.top === window.self) {
    let courses = document.querySelectorAll('#requiredCourseTable .course');
    for await (let c of courses) {
      let coursePk = c.getElementsByClassName('coursePk')[0].textContent;
      let title = c.getElementsByClassName('title')[0].getAttribute('title');
      let jdjs = c.getElementsByClassName('jdjs')[0].textContent; // 进度
      let csInfo = await getCourseInfo(coursePk);
      let csCredit = csInfo.courseCredit;
      if (jdjs === '未报名') {
        // 自动报名高学分课程
        if (csCredit > 1) {
          console.log(`${csCredit}学分:${title}`);
          c.click();
          console.log('Click:' + title);
          const info = document.getElementsByClassName('layui-layer-btn0');
          if (info.length === 1) {
            document.getElementsByClassName('layui-layer-btn0')[0].click();
            console.log('报名:' + title);
          }
        }
      }
    }
  }
};

// 自动报名高学时课程
const autoSignupMaxTime = async () => {
  // 数组存储所有未报名课程故的课时数据
  let timesArray = [];
  // 获取所有未报名课程的子节点。若直接使用所有必修课程,可能出现课程数字相同而对已报名课程二次点击。
  let unCoursesJdpoint = document.querySelectorAll(
    '#requiredCourseTable .course > .jdpoint[style]'
  );
  for await (let u of unCoursesJdpoint) {
    // 由子节点获取父节点从而获取课程编号
    let coursePk = u.parentNode.getElementsByClassName('coursePk')[0].textContent;
    let applyPk = await csPk2applyPk(coursePk);
    let csInfo = await getCourseInfo(coursePk);
    let csTime = csInfo.courseTime;
    skipNewVideoPlayerType(applyPk, (isNewPlayer, applyPk) => {
      if (isNewPlayer) {
        console.log(`跳过 applyPk: ${applyPk}`);
        timesArray.push(-Infinity);
      } else {
        timesArray.push(csTime);
      }
    });
  }
  let longest = Math.max(...timesArray);
  console.log(longest);
  let indexMax = timesArray.indexOf(longest);
  // 出现过该错误 indexMax === -Infinity 导致:
  // TypeError: unCoursesJdpoint[timesArray.indexOf(...)] is undefined
  if (unCoursesJdpoint[indexMax]) {
    unCoursesJdpoint[indexMax].parentNode.click();
  } else {
    location.reload(true);
  }
  const notice = document.getElementsByClassName('layui-layer-btn0');
  if (notice.length === 1) {
    document.getElementsByClassName('layui-layer-btn0')[0].click();
  }
};