Greasy Fork is available in English.
支持国家开放大学、成人本科、继续教育、教师、会计、医生等平台的视频自动播放和倍速控制。
当前为
// ==UserScript==
// @name 🏆 网页继续教育万能自动播放视频倍数
// @namespace 一只蚂蚁而已
// @version 1.3
// @license MIT
// @description 支持国家开放大学、成人本科、继续教育、教师、会计、医生等平台的视频自动播放和倍速控制。
// @author 各种继续教育学习
// @match *://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// 检查是否已经运行过脚本
if (window.hasVideoControlScriptRun) {
return; // 如果已经运行,则直接退出
}
window.hasVideoControlScriptRun = true; // 标记脚本已运行
let currentRate = 1.0; // 当前倍速
let isMinimized = false; // 窗口是否最小化
let isClosed = false; // 窗口是否关闭
// 设置视频播放倍速
function setPlaybackRate(rate) {
const videos = document.querySelectorAll('video');
videos.forEach(video => {
video.playbackRate = rate;
if (!video.playing) {
video.play().catch(err => {}); // 尝试自动播放,忽略错误
}
});
}
// 检查并自动播放视频
function checkAndPlayVideo() {
const videos = document.querySelectorAll('video');
videos.forEach(video => {
if (video.paused && !video.ended) {
video.play().catch(err => {}); // 如果视频暂停,则尝试继续播放
}
});
}
// 监听视频元素的变化(动态加载的视频)
function observeVideoChanges() {
const observer = new MutationObserver((mutations) => {
mutations.forEach(mutation => {
if (mutation.type === 'childList') {
setPlaybackRate(currentRate); // 新视频加载后设置倍速
checkAndPlayVideo(); // 尝试自动播放
}
});
});
observer.observe(document.body, {
childList: true,
subtree: true
});
}
// 创建控制窗口
function createControlModal() {
const modal = document.createElement('div');
modal.id = 'videoControlModal';
modal.style.position = 'fixed';
modal.style.left = '10px';
modal.style.top = '10px';
modal.style.backgroundColor = '#f9f9f9';
modal.style.padding = '10px';
modal.style.zIndex = '1000';
modal.style.borderRadius = '5px';
modal.style.boxShadow = '0 4px 8px rgba(0, 0, 0, 0.1)';
modal.style.width = '250px';
modal.style.fontFamily = 'Arial, sans-serif';
modal.style.border = '1px solid #ccc';
modal.style.transition = 'all 0.3s ease';
// 标题
const title = document.createElement('h3');
title.textContent = '视频倍速控制';
title.style.margin = '0 0 10px 0';
title.style.textAlign = 'center';
modal.appendChild(title);
// 倍速输入框
const rateInput = document.createElement('input');
rateInput.type = 'number';
rateInput.min = '0.1';
rateInput.max = '16';
rateInput.step = '0.1';
rateInput.value = currentRate;
rateInput.style.width = '100%';
rateInput.style.padding = '5px';
rateInput.style.marginBottom = '10px';
modal.appendChild(rateInput);
// 确认按钮
const confirmButton = document.createElement('button');
confirmButton.textContent = '设置倍速';
confirmButton.style.width = '100%';
confirmButton.style.padding = '5px';
confirmButton.style.marginBottom = '10px';
confirmButton.onclick = function() {
const newRate = parseFloat(rateInput.value);
if (newRate >= 0.1 && newRate <= 16) {
currentRate = newRate;
setPlaybackRate(currentRate);
} else {
alert('倍速必须在 0.1 到 16 之间');
}
};
modal.appendChild(confirmButton);
// 最小化按钮
const minimizeButton = document.createElement('button');
minimizeButton.textContent = isMinimized ? '恢复' : '最小化';
minimizeButton.style.width = '48%';
minimizeButton.style.marginRight = '4%';
minimizeButton.style.padding = '5px';
minimizeButton.onclick = function() {
isMinimized = !isMinimized;
if (isMinimized) {
modal.style.height = '30px';
modal.style.overflow = 'hidden';
minimizeButton.textContent = '恢复';
} else {
modal.style.height = 'auto';
modal.style.overflow = 'visible';
minimizeButton.textContent = '最小化';
}
};
modal.appendChild(minimizeButton);
// 关闭按钮
const closeButton = document.createElement('button');
closeButton.textContent = '关闭';
closeButton.style.width = '48%';
closeButton.style.padding = '5px';
closeButton.onclick = function() {
isClosed = true;
modal.style.display = 'none'; // 隐藏窗口
createLogo(); // 创建 Logo
};
modal.appendChild(closeButton);
// 提示信息
const infoText = document.createElement('p');
infoText.style.marginTop = '10px';
infoText.style.fontSize = '12px';
infoText.style.color = '#666';
infoText.innerHTML = `
<strong>提示:</strong><br>
1. 倍速范围:0.1x - 16x<br>
2. 部分平台可能不支持倍速播放<br>
3. 视频会自动尝试播放<br>
<span style="color: red;">联系 v:study-088</span>
`;
modal.appendChild(infoText);
return modal;
}
// 创建 Logo 图标
function createLogo() {
const logo = document.createElement('img');
logo.id = 'videoControlLogo';
logo.src = 'https://img.icons8.com/color/48/000000/doraemon.png'; // 机器猫图标
logo.style.position = 'fixed';
logo.style.left = '10px';
logo.style.top = '10px';
logo.style.width = '40px';
logo.style.height = '40px';
logo.style.cursor = 'pointer';
logo.style.zIndex = '1000';
logo.style.transition = 'transform 0.3s ease';
logo.style.borderRadius = '50%';
logo.style.boxShadow = '0 4px 8px rgba(0, 0, 0, 0.1)';
// 点击 Logo 重新打开窗口
logo.onclick = function() {
const modal = document.getElementById('videoControlModal');
if (modal) {
modal.style.display = 'block'; // 显示窗口
logo.remove(); // 移除 Logo
isClosed = false;
}
};
document.body.appendChild(logo);
}
// 初始化
function init() {
// 检查是否已经存在控制窗口
if (document.querySelector('#videoControlModal')) {
return; // 如果已经存在,则不再创建
}
// 创建并添加控制窗口到页面
const modal = createControlModal();
document.body.appendChild(modal);
// 初始化倍速
setPlaybackRate(currentRate);
// 监听视频元素的变化
observeVideoChanges();
// 定时检查并自动播放视频
setInterval(checkAndPlayVideo, 1000); // 每秒检查一次
}
// 页面加载完成后初始化
if (document.readyState === 'complete' || document.readyState === 'interactive') {
init();
} else {
window.addEventListener('DOMContentLoaded', init);
}
})();