湖北专升本计科专业查询
// ==UserScript==
// @name 湖北专升本计科专业查询
// @namespace https://bbs.tampermonkey.net.cn/
// @version 0.1.1
// @description try to take over the world!
// @match *
//@require https://unpkg.com/sweetalert/dist/sweetalert.min.js
//@require https://cdn.jsdelivr.net/npm/echarts@5.3.2/dist/echarts.min.js
//@require https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.13.2/underscore-min.js
//@grant GM_xmlhttpRequest
//@grant GM_addStyle
//@grant GM_setValue
//@grant GM_getValue
//@grant GM_getResourceURL
// @resource img https://cdn.jsdelivr.net/gh/peterWang123589/picStore/picgo/123.webp
//@connect *
//@run-at document-start
//@grant unsafeWindow
// @author rubinTime
// ==/UserScript==
// 在此处键入代码……
// alert(1111548)
//https://zsb.e21.cn/oauth/token Basic Y2xpZW50LTAxOmNsaWVudC0wMS1zZWNyZXQ= POST
//https://zsb.e21.cn/api/v1/dic/dicVal/getDicValApply
//Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiIxNTA5NzA4MTYyNDkwNTY4NzA2Iiwic2NvcGUiOlsiYWxsIl0sImV4cCI6MTY0ODk3MjUwNiwidXNlciI6IjE1MDk3MDgxNjI0OTA1Njg3MDYiLCJhdXRob3JpdGllcyI6WyJST0xFX1VTRVIiXSwianRpIjoiZjc2NTA2OGUtNWUxYy00NWY3LWI0NzItZDA5MzA5MzZlNjQ2IiwiY2xpZW50X2lkIjoiY2xpZW50LTAxIn0.rHe0nvbDPhkjRJfYCCVVO6fJfHYoLk1xORsYHstoMws
//https://zsb.e21.cn/api/v1/statistics/applyNum?total=35&_page=1&_limit=50&universityId=&majorId=27&applyRate=
(function(){
let mychart
let account={token:"Y2xpZW50LTAxOmNsaWVudC0wMS1zZWNyZXQ=",account:{scope:'all','grant_type':'password'}}
let url=GM_getResourceURL('img')
console.log(GM_getResourceURL('img'))
const query_btn= document.createElement('div')
const total_num=document.createElement('div')
let mask
GM_addStyle(`.query{position:fixed;top:50%;right:20px;transform:translateY(-50%);width:40px;height:40px;border-radius:50%;color:#2c2c54;
border:3px solid currentColor;z-index:9999;font-size:14px;display:flex;justify-content:center;align-items:center;cursor:pointer}
`)
GM_addStyle(`.refresh{position:absolute;top:50%;right:20px;transform:translateY(-50%) rotate(0turn);width:40px;height:40px;cursor:pointer;z-index:9999;
transition:.5s transform ease-in-out;}
`)
GM_addStyle(`.rotate{
animation: .5s rotate ease-in-out
}`)
GM_addStyle(`.total{
position:absolute;bottom:10px;right:2px;width:10%;height:8%;color:#2c2c54;border-top:2px solid;border-left:2px solid;
display:flex;flex-direction:column;justify-content:center;align-items:center
}`)
GM_addStyle(`@keyframes rotate
{
from {transform:translateY(-50%) rotate(0turn);}
to {transform:translateY(-50%) rotate(-1turn)}
}
@-webkit-keyframes mymove /* Safari and Chrome */
{
from {transform:translateY(-50%) rotate(0turn);}
to {transform:translateY(-50%) rotate(-1turn)}
}`)
GM_addStyle(`.close_btn{
position:absolute;
top:5px;
right:5px;
z-index:9999;
width:2.5rem;
height:2.5rem;
color: #fff;
border-radius: 50%;
transform: rotate(
45deg
);
background: linear-gradient(to right,transparent 40%, currentColor 40%, currentColor 60%,transparent 60%), linear-gradient(to bottom,transparent 40%, currentColor 40%, currentColor 60%,transparent 60%), #000;
background-size: 100% 80%, 80% 100%,100% 100%;
background-repeat: no-repeat;
background-position: center;
cursor:pointer
}`)
const refresh=document.createElement('img')
const close_btn=document.createElement('div')
refresh.src=url
// refresh.style.display='none'
// close_btn.style.display='none'
let _directQuery = _.throttle(()=>{directQuery(account)},1500)
query_btn.className='query'
refresh.className='refresh'
close_btn.className='close_btn'
total_num.className='total'
query_btn.innerHTML=`<span>查询</span>`
query_btn.addEventListener('click',()=>{
query_btn.style.display='none'
_directQuery()
refresh.style.display='block'
close_btn.style.display='block'
})
refresh.addEventListener('click',()=>{
refresh.classList.remove('rotate')
void refresh.offsetHeight
refresh.classList.add('rotate')
_directQuery()
})
close_btn.addEventListener('click',()=>{
mask.style.display='none'
query_btn.style.display='flex'
})
window.addEventListener('resize',()=>{
mychart&& mychart.resize({
width:`${window.innerWidth *0.85 }px`,
height:`${window.innerHeight }px`
})
})
document.body.appendChild(query_btn)
// let formdata=new FormData()
// formdata.append('scope','all')
// formdata.append('grant_type','password')
generateGraph.times=1
function generateGraph(category_arr,plan_data,reserve_data,total_count){
let option
option = {
title: {
text: `${new Date().getFullYear()}年湖北计科专升本`
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
legend: {},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: {
type: 'value',
boundaryGap: [0, 0.01]
},
yAxis: {
type: 'category',
data: category_arr,
axisLabel :{
interval:0
},
},
series: [
{
name: '招生计划人数',
type: 'bar',
data: plan_data
},
{
name: '报名人数',
type: 'bar',
data: reserve_data
}
]
};
if(generateGraph.times==1){
GM_addStyle(`.cs_mask{position:fixed;left:0;bottom:0;right:0;top:0;background:#fff;z-index:9999}`)
GM_addStyle(`main{position:absolute;left:0;bottom:0;right:0;top:0;overflow:scroll;display:flex;justift-content:center;align-items:center}`)
mask =document.createElement('div')
const main=document.createElement('div')
main.id='csmain'
console.log(echarts)
mask.className='cs_mask'
main.style.width=`${window.innerWidth *0.75 }px`
main.style.height=`${window.innerHeight }px`
mask.appendChild(main)
document.body.appendChild(mask)
mask.appendChild(refresh)
mask.appendChild(close_btn)
mask.appendChild(total_num)
}
mask.style.display='block'
total_num.innerHTML=`<p>总报名人数:</p>${total_count}`
mychart= echarts.init(document.getElementById('csmain'))
mychart.clear()
option&& mychart.setOption(option)
generateGraph.times++
}
function monkey(url,method="GET",options={}){
return new Promise((resolve,reject)=>{
GM_xmlhttpRequest(
{
method,
url,
timeout:1e4,
onload(xhr){
console.log(xhr)
if(xhr.status == 200){
let res=JSON.parse(xhr.response)
resolve(res.data)
}else{
reject(`HTTPCODE:${xhr.status}\nfinalUrl:${xhr.finalUrl}\nerrInfo:${xhr.responseText}`)
// throw Error(`HTTPCODE:${xhr.status}\nfinalUrl:${xhr.finalUrl}\nerrInfo:${xhr.responseText}`)
}
},
ontimeout: function (err) {
reject(err)
},
...options
}
)
})
}
function total(cs_records){
return cs_records.reduce((prev,cur)=>prev+cur.count,0);
}
async function directQuery(account){
// console.log(account)
try{
//可能会报错的两种情况
//1.不具备access_token 2.有token但token失效了
const access_token=GM_getValue('access_token');
if(!access_token) throw Error('不具备access_token');
let stu_data=await monkey("https://zsb.e21.cn/api/v1/dic/dicVal/getDicValApply","GET",{
headers:{
"Authorization":`Bearer ${access_token}`
}
})
let cs_data=await monkey('https://zsb.e21.cn/api/v1/statistics/applyNum?total=35&_page=1&_limit=50&universityId=&majorId=27&applyRate=',
"GET",{
headers:{
"Authorization":`Bearer ${access_token}`
}
})
console.log(stu_data,cs_data)
const cs_records=cs_data.records
const category_arr=cs_records.map(record=>record.universityName)
const plan_data=cs_records.map(record=>record.number)
const reserve_data=cs_records.map(record=>record.count)
const total_count=total(cs_records)
console.log(`报名总人数为:${total_num}`)
generateGraph(category_arr,plan_data,reserve_data,total_count)
}catch(e){
console.log(e)
console.log(123456)
// debugger;
await indirectQuery(account)
await directQuery(account)
}
}
async function getAccessToken(){
let arr=[]
for(let [key,val] of Object.entries(account.account)){
arr.push(`${key}=${val}`)
}
let data_str=arr.join("&")
try{
const res= await monkey('https://zsb.e21.cn/oauth/token',"POST",{
data:data_str,
headers:{
"Authorization":`Basic ${account.token}`,
"Content-Type":"application/x-www-form-urlencoded"
}
})
res.access_token && GM_setValue('access_token',res.access_token)
}catch(e){
console.log(e)
}
}
async function indirectQuery(account){
if(account.account.username && account.account.password){
try{
await getAccessToken()
return
}catch(e){
console.log(e)
}
}
try{
const username= await swal({
content: {
element: "input",
attributes: {
placeholder: "输入你的账户(手机号)",
type: "text",
},
},
})
const password=await swal({
content: {
element: "input",
attributes: {
placeholder: "输入你的密码",
type: "password",
},
},
})
account.account.username=username
account.account.password=password
await getAccessToken()
// GM_setValue('username')
// GM_setValue('password')
}catch(e){
console.log(e)
}
}
// directQuery(account)
})()