// ==UserScript== // @name 浙江东方职业技术学院校园网自动登录 // @namespace https://docs.scriptcat.org/ // @version 1.1.0 // @description 轮询检查元素,适配document.write拦截导致的动态加载,复用验证过的填充逻辑 // @author You // @match http://10.0.189.200/a70.htm* // @grant none // @run-at document-start // ==/UserScript== // ========== 仅改这3处 ========== const CONFIG = { studentId: "", // 比如20230001 password: "", // 比如12345678 ispValue: 1 // 电信2/移动1/联通3 }; function typeText(inputEl, text) { if (!inputEl) return false; inputEl.focus(); inputEl.value = ''; for (let i = 0; i < text.length; i++) { inputEl.value += text[i]; inputEl.dispatchEvent(new Event('input', { bubbles: true, cancelable: true })); } inputEl.dispatchEvent(new Event('change', { bubbles: true })); inputEl.blur(); return true; } // ========== 轮询检查元素,直到找到为止 ========== let checkTimes = 0; const maxCheckTimes = 30; // 最多检查30次(30秒) const checkInterval = setInterval(() => { checkTimes++; console.log(`[调试] 第${checkTimes}次检查元素(已等${checkTimes}秒)`); // 复用你验证过的元素定位逻辑 const loginBox = document.querySelector('.edit_loginBox'); const userInput = loginBox ? loginBox.querySelector('input[name="DDDDD"]') : document.querySelector('input[name="DDDDD"]'); const pwdInput = loginBox ? loginBox.querySelector('input[name="upass"]') : document.querySelector('input[name="upass"]'); const ispSelect = loginBox ? loginBox.querySelector('select[name="ISP_select"]') : document.querySelector('select[name="ISP_select"]'); const loginBtn = loginBox ? loginBox.querySelector('input[name="0MKKey"]') : document.querySelector('input[name="0MKKey"]'); // 所有元素都找到,执行登录并停止轮询 if (userInput && pwdInput && ispSelect && loginBtn) { clearInterval(checkInterval); console.log(`[调试] ✅ 找到所有元素,开始填充登录`); // 执行你验证过的填充逻辑 const userSuccess = typeText(userInput, CONFIG.studentId); const pwdSuccess = typeText(pwdInput, CONFIG.password); ispSelect.value = CONFIG.ispValue; ispSelect.dispatchEvent(new Event('change', { bubbles: true })); if (userSuccess && pwdSuccess) { loginBtn.click(); console.log("✅ 自动登录完成!"); } } // 超过30秒没找到,停止轮询提示 if (checkTimes >= maxCheckTimes) { clearInterval(checkInterval); console.error("❌ 30秒未找到登录元素,手动执行代码试试"); } }, 1000); // 每1秒检查一次