Greasy Fork is available in English.
网上学院函数库:登录后获取解析数据
当前为
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greasyfork.icu/scripts/395748/770240/wsxy_getData.js
// ==UserScript==
// @name wsxy_getData
// @namespace Vionlentmonkey
// @version 0.4
// @description 网上学院函数库:登录后获取解析数据
// ==/UserScript==
// 课程学分学时等信息
const getCourseInfo = async coursePk => {
let viewURL = `${location.origin}/sfxzwsxy//jypxks/modules/train/course/course_view.jsp?coursePk=${coursePk}`;
let response = await fetch(viewURL, {
method: 'POST',
body: 'blob'
});
let blob = await response.blob();
let csInfoHtml = await binary2Text(blob);
let elements = htmlToElements(csInfoHtml);
let courseCredit = Number(elements.querySelectorAll('#subjectInfo td')[7].textContent.trim());
let courseTime = Number(elements.querySelectorAll('#extendInfo td')[3].textContent.trim());
let courseInfo = {
courseCredit,
courseTime
};
return courseInfo;
};
// 获取课程对应的 iframe 资源地址,为获取播放器类型做准备。
const getFrameURL = async applyPk => {
let trainURL =
location.origin +
'/sfxzwsxy/jypxks/modules/train/ware/course_ware_view.jsp?applyPk=' +
applyPk +
'&courseType=1';
let response = await fetch(trainURL, {
method: 'POST',
body: 'blob'
});
let blob = await response.blob();
let csInfoHtml = await binary2Text(blob);
let elements = htmlToElements(csInfoHtml);
let warePath = elements.getElementById('warePath').value;
let iframeURL = 'http://218.94.1.181:5088/unzipapp/project/ware' + warePath;
//console.log('iframeURL: ' + iframeURL);
return iframeURL;
};
// 部分少见的新型播放器会弹出 confirm,避开为宜。
const skipNewVideoPlayerType = async (applyPk, callback) => {
// 未报名课程 applyPk === ''
if (applyPk) {
let iframeVideoPlayerType = {
method: 'POST',
// Fetch 不能获取跨域数据
url: await getFrameURL(applyPk),
onload: response => {
let csInfoHtml = response.responseText;
let elements = htmlToElements(csInfoHtml);
let isNewPlayer = elements.getElementById('video');
// return 永远为 undefined,以回调处理
callback(isNewPlayer, applyPk);
}
};
GM_xmlhttpRequest(iframeVideoPlayerType);
}
};