// ==UserScript==
// @name 国家开放大学智能倍速助手 --有问题扫下方二维馬文客服
// @namespace http://tampermonkey.net/
// @version 2.1
// @description 国家开放大学自动刷课,专业视频加速解决方案,支持快捷键/记忆速度,登陆后进入学习空间“我的课程”自动开始学习 客服V:wkwk796
// @author wkwk796
// @match *://*.ouchn.cn/*
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_registerMenuCommand
// @license MIT
// @license MIT
// @downloadURL none
// ==/UserScript==
(function() {
'use strict';
// 配置参数
const CONFIG = {
defaultSpeed: GM_getValue('lastSpeed', 1.5),
speedSteps: [0.5, 1.0, 1.5, 2.0, 2.5, 3.0],
hotkeys: {
speedUp: 'ArrowRight',
speedDown: 'ArrowLeft',
reset: 'KeyR'
}
};
// 创建专业控制面板
const panel = createControlPanel();
let currentSpeed = CONFIG.defaultSpeed;
// 初始化核心功能
function init() {
document.body.appendChild(panel);
registerHotkeys();
initSpeedMemory();
startVideoMonitor();
applyCurrentSpeed();
}
// 创建专业级控制面板
function createControlPanel() {
const panel = document.createElement('div');
panel.style = `
position: fixed;
bottom: 30px;
right: 30px;
background: linear-gradient(145deg, #2c3e50, #34495e);
color: #ecf0f1;
padding: 15px;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
z-index: 2147483647;
font-family: 'Segoe UI', system-ui;
min-width: 180px;
`;
// 标题栏
const header = document.createElement('div');
header.innerHTML = `
⚡ 倍速控制
v2.1
`;
panel.appendChild(header);
// 速度控制区
const controls = document.createElement('div');
controls.style.display = 'flex';
controls.style.gap = '8px';
controls.style.alignItems = 'center';
// 减速按钮
const slowBtn = createButton('-', () => adjustSpeed(-0.5));
controls.appendChild(slowBtn);
// 速度显示
const speedDisplay = document.createElement('span');
speedDisplay.id = 'currentSpeed';
speedDisplay.style.minWidth = '40px';
speedDisplay.style.textAlign = 'center';
speedDisplay.style.fontWeight = 'bold';
updateSpeedDisplay();
// 加速按钮
const fastBtn = createButton('+', () => adjustSpeed(0.5));
controls.append(slowBtn, speedDisplay, fastBtn);
panel.appendChild(controls);
// 技术支持信息
const footer = document.createElement('div');
footer.style.marginTop = '12px';
footer.style.fontSize = '0.9em';
footer.innerHTML = `
技术支持:wkwk796
左右方向键调节速度 | R键重置
`;
panel.appendChild(footer);
function updateSpeedDisplay() {
speedDisplay.textContent = `${currentSpeed.toFixed(1)}x`;
}
function createButton(text, onClick) {
const btn = document.createElement('button');
btn.textContent = text;
btn.style = `
padding: 6px 12px;
background: #3498db;
border: none;
border-radius: 4px;
color: white;
cursor: pointer;
transition: all 0.2s;
`;
btn.addEventListener('mouseover', () => btn.style.background = '#2980b9');
btn.addEventListener('mouseout', () => btn.style.background = '#3498db');
btn.addEventListener('click', onClick);
return btn;
}
return panel;
}
// 核心功能逻辑
function adjustSpeed(step) {
currentSpeed = Math.max(0.5, Math.min(3.0, currentSpeed + step));
applyCurrentSpeed();
GM_setValue('lastSpeed', currentSpeed);
updateSpeedDisplay();
}
function applyCurrentSpeed() {
document.querySelectorAll('video').forEach(video => {
try {
video.playbackRate = currentSpeed;
video.defaultPlaybackRate = currentSpeed;
} catch (e) {
console.error('速度设置失败:', e);
}
});
}
// 智能视频监控
function startVideoMonitor() {
const observer = new MutationObserver(mutations => {
if (mutations.some(m => [...m.addedNodes].some(n => n.tagName === 'VIDEO'))) {
applyCurrentSpeed();
}
});
observer.observe(document.body, { childList: true, subtree: true });
// 定时检测防止漏检
setInterval(() => {
if ([...document.querySelectorAll('video')].some(v => v.playbackRate !== currentSpeed)) {
applyCurrentSpeed();
}
}, 3000);
}
// 快捷键系统
function registerHotkeys() {
document.addEventListener('keydown', (e) => {
if (e.code === CONFIG.hotkeys.speedUp) {
adjustSpeed(0.5);
e.preventDefault();
} else if (e.code === CONFIG.hotkeys.speedDown) {
adjustSpeed(-0.5);
e.preventDefault();
} else if (e.code === CONFIG.hotkeys.reset) {
currentSpeed = 1.0;
applyCurrentSpeed();
GM_setValue('lastSpeed', currentSpeed);
updateSpeedDisplay();
}
});
}
// 初始化记忆功能
function initSpeedMemory() {
if (GM_getValue('lastSpeed')) {
currentSpeed = GM_getValue('lastSpeed');
applyCurrentSpeed();
}
}
// 启动脚本
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})();