Greasy Fork

Greasy Fork is available in English.

chinahrt继续教育;chinahrt全自动刷课;解除系统限制;

【❤全自动刷课❤】功能可自由配置,只需将视频添加到播放列表,后续刷课由系统自动完成;使用教程:https://yikuaibaiban.github.io/chinahrt-autoplay-docs/

< 脚本 chinahrt继续教育;chinahrt全自动刷课;解除系统限制; 的反馈

评价:好评 - 脚本运行良好

§
发布于:2025-06-04

我也用ai写了一个小脚本,可以检测到视频暂停15秒就自动刷新网页。

// ==UserScript==
// @name chinahrt CKPlayer 视频控制 + 状态浮窗 卡顿时自动刷新网页
// @namespace http://tampermonkey.net/
// @version 1.7
// @description 首次尝试播放(静音规避限制),卡顿自动刷新,状态浮窗,系统通知支持与回退提示。
// @author
// @match *://*.chinahrt.com/*
// @grant GM_notification
// ==/UserScript==

(function () {
'use strict';

let video = null;
let firstCheckDone = false;
let lastPlayTime = Date.now();
let pendingReload = false;
const scriptName = 'chinahrt-player-assistant';

// 状态浮窗
const statusBox = document.createElement('div');
statusBox.id = `${scriptName}-status`;
Object.assign(statusBox.style, {
position: 'fixed',
top: '20px',
right: '20px',
zIndex: '99999',
background: 'rgba(0, 0, 0, 0.7)',
color: '#0f0',
padding: '10px 15px',
borderRadius: '8px',
fontSize: '14px',
fontFamily: 'monospace',
maxWidth: '300px',
lineHeight: '1.5',
whiteSpace: 'pre-wrap',
cursor: 'pointer',
border: '1px solid #00ff00'
});
statusBox.textContent = '🚀 脚本启动中,正在查找视频...';
document.body.appendChild(statusBox);

function updateStatus(text, color = '#0f0') {
statusBox.innerHTML = text;
statusBox.style.color = color;
statusBox.style.borderColor = color;
}

function notify(title, message) {
if (typeof GM_notification !== 'undefined') {
GM_notification({ title, text: message, silent: true, timeout: 5000 });
return;
}

if ('Notification' in window && Notification.permission === 'granted') {
new Notification(title, { body: message });
return;
}

if ('Notification' in window && Notification.permission !== 'denied') {
Notification.requestPermission().then(permission => {
if (permission === 'granted') {
new Notification(title, { body: message });
}
});
}

// 最终回退:状态框显示提示
const originalColor = statusBox.style.color;
const originalBG = statusBox.style.background;
updateStatus(`🔔 ${title}: ${message}`, '#ff0');
statusBox.style.background = 'rgba(255, 0, 0, 0.9)';
statusBox.style.transform = 'scale(1.05)';
statusBox.style.transition = 'all 0.5s';

setTimeout(() => {
updateStatus(statusBox.textContent, originalColor);
statusBox.style.background = originalBG;
statusBox.style.transform = 'scale(1)';
}, 2000);
}

// 等待用户交互后播放(用于回退)
function waitForUserInteractionThenPlay() {
const handler = () => {
document.removeEventListener('click', handler);
document.removeEventListener('keydown', handler);
video.play().then(() => {
updateStatus("▶️ 用户交互后播放成功");
notify("播放恢复", "用户点击后播放成功");
}).catch(err => {
updateStatus(`❌ 用户交互播放失败: ${err.message}`, "#f00");
});
};
document.addEventListener('click', handler);
document.addEventListener('keydown', handler);
}

// 自动播放逻辑(带静音绕过)
function tryInitialAutoPlayOnce() {
if (!video || !video.paused || firstCheckDone) return;
firstCheckDone = true;

updateStatus("⏳ 检测到视频未播放,3秒后尝试播放...", "#ff0");
setTimeout(() => {
if (video && video.paused) {
video.muted = true; // 静音尝试规避浏览器限制
video.play().then(() => {
updateStatus("▶️ 视频已自动播放(静音)");
notify("播放启动", "视频已自动播放(静音)");
}).catch(err => {
updateStatus(`❌ 自动播放失败: ${err.message}`, "#f00");

// 点击播放按钮尝试
const playBtn = document.querySelector('.ckplayer .videoPlay, .ckplayer .playButton');
if (playBtn) {
playBtn.click();
updateStatus("🔄 尝试点击播放按钮...");
}

waitForUserInteractionThenPlay(); // 等待交互后播放
});
}
}, 3000);
}

function checkVideoStatus() {
if (!video) return;

const isPlaying = !video.paused && !video.ended && video.readyState >= 2;
const statusText = `⏱️ 位置: ${video.currentTime.toFixed(1)}s / ${video.duration.toFixed(1)}s\n📶 状态: ${isPlaying ? '▶️ 播放中' : '⏸️ 暂停中'}`;

if (isPlaying) {
lastPlayTime = Date.now();
pendingReload = false;
updateStatus(statusText);
} else {
updateStatus(`${statusText}\n🔴 视频卡顿或暂停`, "#ff0");
tryInitialAutoPlayOnce();
}

const idleSeconds = (Date.now() - lastPlayTime) / 1000;
if (idleSeconds >= 15 && !pendingReload) {
pendingReload = true;
updateStatus(`⏱️ 卡顿时间: ${Math.floor(idleSeconds)}秒\n🔁 2秒后自动刷新页面...`, "#f00");
notify("视频卡顿", "检测到视频卡顿超过15秒,即将刷新页面");
setTimeout(() => {
updateStatus("🔄 正在刷新页面...", "#f00");
window.location.reload();
}, 2000);
}
}

function initMonitor() {
const findVideo = () => {
const found = document.querySelector('video');
if (found) {
video = found;
updateStatus("✅ 检测到视频元素,开始监控播放状态...");

video.addEventListener('playing', () => lastPlayTime = Date.now());
video.addEventListener('ended', () => updateStatus("🏁 视频播放结束", "#0ff"));
video.addEventListener('error', (e) => {
updateStatus(`❌ 播放错误: ${video.error?.message || '未知错误'}`, "#f00");
});

setInterval(checkVideoStatus, 3000);
return true;
}
return false;
};

if (findVideo()) return;

const observer = new MutationObserver(() => findVideo() && observer.disconnect());
observer.observe(document.body, { childList: true, subtree: true });

setTimeout(() => {
if (!video) {
updateStatus("⚠️ 未找到视频元素,稍后继续检测", "#f90");
observer.disconnect();
}
}, 10000);
}

statusBox.addEventListener('click', () => {
updateStatus("🔄 手动刷新页面中...", "#0ff");
setTimeout(() => location.reload(), 500);
});

statusBox.oncontextmenu = (e) => {
e.preventDefault();
if (!video) return;
if (video.paused) {
video.play();
updateStatus("▶️ 手动恢复播放");
} else {
video.pause();
updateStatus("⏸️ 手动暂停播放", "#ff0");
}
};

statusBox.title = '左键: 刷新页面\n右键: 播放/暂停';

if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initMonitor);
} else {
setTimeout(initMonitor, 1000);
}
})();

发布留言

登录以发布留言。