一、脚本
// 创建自动点击管理器
const inactivityAutoClicker = {
observer: null,
timer: null,
// 启动检测
start: function() {
// 检测函数
const check = () => {
// 查找所有<p>元素
const paragraphs = document.querySelectorAll('p');
let targetNotice = null;
// 遍历查找包含特定文本的元素
for (const p of paragraphs) {
if (p.textContent.includes('由于你长时间未操作,请点确定继续使用。')) {
targetNotice = p;
break;
}
}
if (targetNotice) {
// 向上查找最近的div容器
const container = targetNotice.closest('div');
if (!container) return;
// 查找按钮(优先按ID前缀匹配,其次按文本匹配)
const button = container.querySelector('button[id^="_mask_notice_id_"]') ||
Array.from(container.querySelectorAll('button')).find(
btn => btn.textContent.includes('确定')
);
if (button) {
button.click();
console.log('检测到未操作提示,已自动点击确定按钮');
}
}
};
// 启动监听DOM变化
this.observer = new MutationObserver(check);
this.observer.observe(document.body, {
childList: true,
subtree: true,
characterData: true
});
// 每秒检查一次(处理已存在的提示)
this.timer = setInterval(check, 1000);
console.log('自动检测已启动');
},
// 停止检测
stop: function() {
if (this.observer) {
this.observer.disconnect();
this.observer = null;
}
if (this.timer) {
clearInterval(this.timer);
this.timer = null;
}
console.log('自动检测已停止');
}
};
// 启动检测
inactivityAutoClicker.start();
/*
停止检测时执行:
inactivityAutoClicker.stop();
*/
二、执行说明
1、按 F12 快捷键打开开发者工具。
2、找到控制台Console。
3、粘贴脚本进入控制台,按下回车Enter键执行,打印“自动检测已启动”即为开始执行。
4、输入代码中的 inactivityAutoClicker.stop();即可立即停止执行,刷新页面也会停止执行,刷新后再次启动需要重新粘贴脚本运行。
三、问题说明
1、本代码使用deepseek生成,原理为识别弹窗并模拟点击。笔者实测,当前版本(2025/6/7)无需播放任何内容,只需要挂着页面即可计算时长。所以使用该逻辑即可顺利刷时长。
2、后续U校园版本可能会有更改,导致脚本不可用,比如提示文本更改等,需要自行调整。或者根据情况使用AI重新生成对应逻辑的代码。
3、网上存在循环播放视频等组件刷时长的脚本,当前版本实测会弹出超时提示,即不可用。
4、超时提示大概半小时触发(当前版本),检测频率可以自行根据代码内容调整。