Greasy Fork is available in English.
网上学院函数库:自动登录
当前为
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greasyfork.icu/scripts/395952/770463/wsxy_autoLogin.js
// ==UserScript==
// @name wsxy_autoLogin
// @namespace Vionlentmonkey
// @version 0.3
// @description 网上学院函数库:自动登录
// ==/UserScript==
// 从 QQ 等打开地址后会被加上奇葩后缀 http://218.94.1.179:8087/sfxzwsxy/#?tdsourcetag=s_pctim_aiomsg
const uniformURLs = () => {
const tracks = [
// QQ
'?tdsourcetag=s_pctim_aiomsg',
// Weixin
'?from=groupmessage',
'&from=groupmessage',
'?from=singlemessage',
'&from=singlemessage',
'?from=timeline',
'&from=timeline',
'/type/WeixinReadCount'
];
for (const track of tracks) {
if (location.href.endsWith(track)) {
location.href = location.href.replace(track, '');
}
}
if (location.host.endsWith('.sft.ipv6.jiangsu.gov.cn:8087')) {
location.host = location.host.replace('.sft.ipv6.jiangsu.gov.cn', '').replace('-', '.');
}
};
const autoServerSelect = () => {
const servers = document.getElementsByClassName('num');
if (servers.length > 0) {
let servers_str = [];
let notificationText = '自动选择最空闲的服务器!';
for (const s of servers) {
servers_str.push(s.textContent);
notificationText += `\n服务器${servers_str.length}使用程度:${s.textContent}%`;
}
// 将字符串元素转为数字
const servers_num = servers_str.map(Number);
// 全满则自动刷新,否则选择最空服务器
const mostFree = Math.min(...servers_num);
if (mostFree === 100) {
if (GM_config.get('reload')) {
// https://developer.mozilla.org/docs/Web/API/Location/reload
location.reload(true);
}
} else {
document.getElementsByClassName('entrybtn')[servers_num.indexOf(mostFree)].click();
GM_notification(notificationText);
}
}
};
// 在原函数的基础上,去掉验证码识别,去除 isBlank 函数依赖
const check = () => {
if (document.getElementById('loginName').value === '') {
alert('请输入用户名');
document.getElementById('loginName').focus();
return;
}
if (document.getElementById('pwd').value === '') {
alert('请输入密码');
document.getElementById('pwd').focus();
return;
}
document.getElementById('form1').submit();
};
const autoLogin = () => {
// 重新绑定点击事件
document.getElementById('Submit').onclick = check;
// 移除验证码并提示
document.getElementById('verifyCode').remove();
document.getElementById('imgCode').value = '已去除验证码可直接登录';
// 以下尝试自动登录
document.getElementById('loginName').value = GM_config.get('loginName'); // 写入预先设置的用户名
document.getElementById('pwd').value = GM_config.get('pwd'); // 写入预先设置的密码
// 自动获取用户名密码输入框焦点
if (document.getElementById('loginName').value === '') {
document.getElementById('loginName').focus();
} else if (document.getElementById('pwd').value === '') {
document.getElementById('pwd').focus();
} else {
// 用户名密码均已填写时才自动登录
document.getElementById('Submit').click();
}
};