// ==UserScript== // @name 泰安专技培训视频倍速控制 // @namespace http://tampermonkey.net/ // @version 1.0 // @description 为sdta-gxk和sdta-zyk网站的视频添加倍速控制按钮 // @author 您的用户名 // @match https://sdta-gxk.yxlearning.com/* // @match https://sdta-zyk.yxlearning.com/* // @grant none // ==/UserScript== (function() { 'use strict'; // 倍速选项配置 const speedOptions = [0.5, 0.75, 1, 1.25, 1.5, 2, 4, 8, 16]; let currentSpeed = 1; let speedButton = null; let video = null; // 创建倍速控制按钮 function createSpeedButton() { if (speedButton) return speedButton; const button = document.createElement('button'); button.textContent = '1x'; button.style.cssText = ` position: absolute; top: 10px; right: 10px; background: rgba(136, 181, 174, 0.8); color: white; border: none; border-radius: 4px; padding: 4px 8px; font-size: 14px; cursor: pointer; z-index: 10000; outline: none; `; button.addEventListener('click', () => { const nextIndex = (speedOptions.indexOf(currentSpeed) + 1) % speedOptions.length; currentSpeed = speedOptions[nextIndex]; updateSpeed(currentSpeed); }); return button; } // 更新视频播放速度 function updateSpeed(speed) { if (video && !isNaN(speed)) { video.playbackRate = speed; speedButton.textContent = `${speed}x`; } } // 主函数:查找视频元素并添加按钮 function main() { video = document.querySelector('video'); if (!video) { console.log('未找到视频元素,等待重试...'); setTimeout(main, 1000); return; } speedButton = createSpeedButton(); video.parentNode.appendChild(speedButton); // 监听视频变化 new MutationObserver(() => { const newVideo = document.querySelector('video'); if (newVideo && newVideo !== video) { video = newVideo; video.parentNode.appendChild(speedButton); } }).observe(document.body, { childList: true, subtree: true }); } // 等待页面加载完成 window.addEventListener('load', main); })();