autoLogin_aynu
// ==UserScript==
// @name autoLogin_aynu
// @namespace univeral
// @version 1.0.3
// @description try to take over the world!
// @author cczj_code
// @match *://*aynu.edu.cn/*
// @match *://*10.100.1.3*
// ==/UserScript==
// 全局账号管理
const Global_account = {
// 是否打开网页登录提示
isTips: false,
// 延迟脚本服务, 默认为500ms
delayTips: 500,
// 安阳师范学院官网
aynu_offical: {
username:"",
password:""
},
// 安阳师范学院校园网
aynu_network:{
username:"",
password:""
}
};
// 主要逻辑函数
(() => {
'use strict';
// 安阳师范学院官网
const aynu_offical = (username, password) => {
// handle something
setElmVal(getElmById('username'), username)
setElmVal(getElmById('password'), password)
return debounce(()=>{
if(href == 'https://jwglxt.aynu.edu.cn/cas/login.action') {
// 自动填写并且登录
checkrand();
}else {
startLogin();
}
})()
}
// 安阳师范学院校园网
const aynu_network = (username, password) => {
setElmVal(getElmById('username'), username)
setElmVal(getElmById('password'), password)
return debounce(()=>{
$('#login-account').click();
$('#login-token').click();
$('#login-sms').click();
setTimeout(() => {
window.close();
}, Global_account.delayTips)
})()
}
const getElmById = (id) => {
return document.getElementById(id)
}
const getElmByClassName = (className) => {
return document.getElementsByClassName(className)
}
// queryElmBySelector query Element By Selector, you wanna content Elm that you can input about them.
const queryElmBySelector = (selectContents) => {
return document.querySelectorAll(selectContents)
}
// 设置元素值
const setElmVal = (ele, val) => {
if(ele) {
ele.value = val
}
}
// 日志打印
const log = (param) => {
console.log(param + ': ', param)
}
// 第一个参数是需要进行防抖处理的函数,第二个参数是延迟时间,默认为1秒钟
const debounce = (fn, delay = 1000) => {
// 实现防抖函数的核心是使用setTimeout
// time变量用于保存setTimeout返回的Id
let time = null
return () => {
// 如果time不为0,也就是说有定时器存在,将该定时器清除
if (time !== null) {
clearTimeout(time)
}
time = setTimeout(() => {
fn()
}, delay)
}
}
const href = window.location.href
// 延迟开启
setTimeout(()=> {
if(href.includes('http://10.100.1.3/')) {
aynu_network(Global_account.aynu_network.username, Global_account.aynu_network.password)
}else if(href == 'https://www.aynu.edu.cn/') {
let judge = true
if(Global_account.isTips) {
judge = confirm('是否打开教务管理系统?')
}
if(judge) {
window.open(queryElmBySelector('.list16 a')[3].href);
}
} else if(href == 'https://jwglxt.aynu.edu.cn/cas/login.action' ||
href.includes('https://authserver.aynu.edu.cn/authserver/login')) {
aynu_offical(Global_account.aynu_offical.username, Global_account.aynu_offical.password)
}
}, Global_account.delayTips)
})();