Greasy Fork

wsxy_Learn

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

目前为 2020-02-04 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.greasyfork.icu/scripts/396002/769961/wsxy_Learn.js

// ==UserScript==
// @name          wsxy_Learn
// @namespace     Vionlentmonkey
// @version       0.3
// @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();
  }
};

const autoOpenExam = async exams => {
  for await (let exam of exams) {
    const examURL = location.origin + '/sfxzwsxy/' + exam.getAttribute('onclick').split("'")[1];
    // 魔法打开的考卷确认交卷后不能自动关闭,只得如此暴力处理,1分钟后强行关闭。
    let autoExam = GM_openInTab(examURL, true);
    setTimeout(autoExam.close, 60000);
  }
};

const autoOpenTrain = async (isNewPlayer, applyPk) => {
  if (isNewPlayer) {
    console.log(`跳过 applyPk: ${applyPk}`);
  } else {
    const trainURL =
      location.origin +
      '/sfxzwsxy/jypxks/modules/train/ware/course_ware_view.jsp?applyPk=' +
      applyPk +
      '&courseType=1';
    const openClose = GM_openInTab(trainURL, true);
    // 25分钟自动关闭
    setTimeout(openClose.close, 1500000);
  }
};