本帖最后由 冥月影 于 2022-8-1 20:04 编辑
食之无味,弃之可惜
仅作备份
增加专业代码搜索框
- 原来的搜索界面只能搜索单条的课程开考信息
- 增加专业代码搜索框,可以直接通过专业代码搜索对应月份的开考课程
已知问题
- 当有多个同样的专业代码时,会只取第一条数据
- 广东的自考官网搜索使用,其他省份的应该不行。。
[JavaScript] 纯文本查看 复制代码 // ==UserScript==
// @name 自考-开考课程搜索
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author 1
// @match https://www.eeagd.edu.cn/*/kkkccx.jsp
// @icon https://www.google.com/s2/favicons?sz=64&domain=eeagd.edu.cn
// @grant unsafeWindow
// ==/UserScript==
(function() {
'use strict';
// Your code here...
init();
function init() {
let div01 = '<label class="col-lg-1 col-md-1 control-label">专业代码</label>';
let div02 =
'<div class="col-lg-2 col-md-2"><input type="text" id="zydm" style="width: 100px;" class="form-control" name="zydm" required="" value=""></div>';
let div03 = '<div class="col-lg-2 col-md-2" style="" id="search_zydm"></div>'
let div04 =
'<div class="col-lg-2 col-md-2x"><button id="search_zydm"><i class="icon wb-search" aria-hidden="true"></i>搜索专业代码</button></div>'
$('.form-group').append(div01);
$('.form-group').append(div02);
$('.form-group').append(div04);
// hock
unsafeWindow.window.eval(gd_post.toString().replace('if(data===null || data===""){',
't_fn = successFn; if(data===null || data===""){'));
$('.gdmui-searchBox button').click();
$('#search_zydm').bind('click', function(e) {
let zydm = $('#zydm').val();
let kkny = $('#kknyGroup').val();
let tmp01 = search_by_zydm(zydm);
let tmp02 = get_gckc(tmp01.rows[0].ZYDM, tmp01.rows[0].ZYYXDM, tmp01.rows[0].KCZDM);
let tmp03 = get_all_km_info(kkny, tmp02);
let tmp04 = sort_km(tmp03);
t_fn(tmp04);
});
}
function search_post(url, data) {
let result = null;
$.ajax({
type: 'post',
url: url,
data: JSON.stringify(data),
dataType: 'JSON',
contentType: 'application/json;charset=UTF-8',
async: false,
success: function(data) {
if (data.result != undefined) {
result = data.result;
}
},
error: function(data) {
// console.log('error');
console.log(data);
}
});
return result;
}
function search_by_kmdm(kkny, kmdm) {
let url = 'https://www.eeagd.edu.cn/zkselfec/gkcx/queryKkkccx.jsmeb';
let search_data = [{page: 1,rows: 20,kkny: kkny,kmdm: kmdm,kmmc: ""}, null, "desc"];
// let result = null;
return search_post(url, search_data);
}
function search_by_zydm(zydm) {
let url = 'https://www.eeagd.edu.cn/zkselfec/gkcx/queryZycx.jsmeb';
let search_data = [{page: 1,rows: 20,zydm: zydm,zymc: ""}, null, "desc"];
return search_post(url, search_data);
}
function get_gckc(zydm, zyyxdm, kczdm) {
let url = 'https://www.eeagd.edu.cn/zkselfec/gkcx/queryZykm.jsmeb';
let search_data = [{zydm: zydm,zyyxdm: zyyxdm,kczdm: kczdm}];
return search_post(url, search_data);
}
function get_all_km_info(kkny, km) {
let result = {rows: [],total: 0};
let tmp = null;
for (let i = 0; i < km.data.length; i++) {
tmp = search_by_kmdm(kkny, km.data[i]['kmdm']);
result.total = result.total + parseInt(tmp.total);
if (tmp.total > 0) {
result.rows = result.rows.concat(tmp.rows);
} else {
console.log(km.data[i]);
}
}
return result;
}
function sort_km(km) {
let tmp = km.rows;
let ksdate_num = 0;
let sxw_num = 0;
let tmp_v = null;
for (let i = 0; i < tmp.length; i++) {
ksdate_num = parseInt(tmp[i]['KSDATE'].replace(/.*月/, '').replace('日', ''));
sxw_num = tmp[i]['SXW'] == '上午' ? 1 : 2;
tmp[i]['sortnum'] = ksdate_num * 10000000 + sxw_num * 1000000 + parseInt(tmp[i]['KMDM']);
}
for (let i = 0; i < tmp.length; i++) {
for (let j = i + 1; j < tmp.length; j++) {
if (tmp[i]['sortnum'] > tmp[j]['sortnum']) {
tmp_v = km.rows[i];
km.rows[i] = km.rows[j];
km.rows[j] = tmp_v;
}
}
}
return km;
}
})();
|