Greasy Fork is available in English.
检测到校园网后自动打开认证页面,让 Chrome 处理自动填充登录
当前为
// ==UserScript==
// @name 校园网自动打开认证页面(南昌航空大学)
// @namespace http://tampermonkey.net/
// @version 1.0
// @description 检测到校园网后自动打开认证页面,让 Chrome 处理自动填充登录
// @match *://*/*
// @grant GM_xmlhttpRequest
// @run-at document-start
// @license MIT
// ==/UserScript==
(function() {
'use strict';
const loginPageURL = "http://10.1.88.4"; // 你的校园网认证页面地址
const checkURL = "http://10.1.88.4/cgi-bin/rad_user_info"; // 用于检测是否已登录
// 发送请求检查是否已登录
function checkLoginStatus() {
GM_xmlhttpRequest({
method: "GET",
url: checkURL,
timeout: 3000, // 3秒超时
onload: function(response) {
if (!response.responseText.includes("username")) {
console.log("未登录,打开认证页面...");
window.open(loginPageURL, "_blank");
} else {
console.log("已登录,无需操作。");
}
},
onerror: function() {
console.log("无法连接校园网,可能未连接 WiFi");
}
});
}
// 每隔 30 秒检测一次
setInterval(checkLoginStatus, 30000);
// 初次运行时立即检测
checkLoginStatus();
})();