// ==UserScript==
// @name 华医网课程自动切换工具
// @namespace https://91huayi.com/
// @version 3.2.0
// @description 自动播放、静音、关闭弹窗、点击继续学习、自动下一课 | 带控制面板
// @author auto
// @match https://cme1.91huayi.com/cme/*
// @match https://cme1.91huayi.com/*
// @match *://*.91huayi.com/*
// @grant none
// @run-at document-end
// ==/UserScript==
(function() {
'use strict';
let enabled = true;
let logBox = null;
// 延迟启动保证页面加载完
setTimeout(() => {
createPanel();
startLoop();
}, 1600);
// 创建控制面板(可拖动)
function createPanel() {
const panel = document.createElement('div');
panel.id = 'huayi-auto-panel';
panel.style.cssText = `
position:fixed; top:20px; right:20px; z-index:999999;
width:260px; background:#fff; border-radius:10px;
box-shadow:0 5px 20px rgba(0,0,0,0.15); padding:12px;
font-size:12px; font-family:system-ui; cursor:move;
`;
panel.innerHTML = `
华医网全自动 v5.0
状态:运行中
`;
document.body.appendChild(panel);
makeDraggable(panel);
logBox = document.getElementById('log');
addLog('脚本已启动');
// 按钮事件
document.getElementById('start-btn').onclick = () => {
enabled = true;
document.getElementById('status-text').innerHTML = '运行中';
document.getElementById('status-text').style.color = '#060';
addLog('已启动');
};
document.getElementById('stop-btn').onclick = () => {
enabled = false;
document.getElementById('status-text').innerHTML = '已停止';
document.getElementById('status-text').style.color = '#c00';
addLog('已停止');
};
}
// 拖动面板
function makeDraggable(el) {
let drag = false, x, y;
el.addEventListener('mousedown', e => {
drag = true;
x = e.clientX - el.getBoundingClientRect().left;
y = e.clientY - el.getBoundingClientRect().top;
});
document.addEventListener('mousemove', e => {
if (!drag) return;
el.style.left = (e.clientX - x) + 'px';
el.style.top = (e.clientY - y) + 'px';
el.style.right = 'auto';
});
document.addEventListener('mouseup', () => drag = false);
}
// 日志输出
function addLog(text) {
if (!logBox) return;
const d = new Date();
const time = `${d.getHours().toString().padStart(2,'0')}:${d.getMinutes().toString().padStart(2,'0')}:${d.getSeconds().toString().padStart(2,'0')}`;
logBox.innerHTML += `[${time}] ${text}\n`;
logBox.scrollTop = logBox.scrollHeight;
}
// 主循环
function startLoop() {
setInterval(() => {
if (!enabled) return;
// 1. 自动静音 + 自动播放
const videos = document.querySelectorAll('video');
videos.forEach(v => {
v.muted = true;
if (v.paused && v.duration > 0) {
v.play().catch(() => {});
}
});
// 2. 自动关闭弹窗
autoClosePopup();
// 3. 自动点【继续学习】按钮(视频弹窗必备)
autoClickContinue();
// 4. 视频播完 → 下一课
autoPlayNext();
}, 700);
}
// 自动关闭弹窗
function autoClosePopup() {
const closeButtons = document.querySelectorAll(`
.close, .btn-close, [class*="close"], [id*="close"],
button:contains("确定"), button:contains("知道了")
`);
closeButtons.forEach(btn => {
if (btn.offsetParent) {
btn.click();
addLog('已关闭弹窗');
}
});
}
// ============== 你要的【自动点继续学习】 ==============
function autoClickContinue() {
const buttons = document.querySelectorAll(`
button:contains("继续学习"),
button:contains("继续"),
button:contains("继续观看"),
.continue, .btn-continue,
[class*="continue"], [id*="continue"]
`);
buttons.forEach(btn => {
if (btn.offsetParent && btn.textContent.includes('继续')) {
btn.click();
addLog('已点击【继续学习】');
}
});
}
// ============== 视频播完自动下一课 ==============
function autoPlayNext() {
const videos = document.querySelectorAll('video');
videos.forEach(v => {
if (v.duration > 0 && v.currentTime / v.duration >= 0.96) {
setTimeout(() => {
goNext();
addLog('视频已完成 → 跳转到下一课');
}, 1200);
}
});
}
function goNext() {
const nextSelectors = [
'.next', '.btn-next', '.next-lesson', '.lesson-next',
'button:contains("下一课")',
'button:contains("下一步")',
'button:contains("继续学习")',
'.course-item:not(.finished) .title',
'.lesson-item:not(.played) .name'
];
for (const sel of nextSelectors) {
const list = document.querySelectorAll(sel);
for (const el of list) {
if (el.offsetParent) {
el.click();
addLog('已点击下一课');
return;
}
}
}
}
})();