// ==UserScript==
// @name 文理专用
// @namespace http://tampermonkey.net/
// @version 2.1
// @description 文理专用
// @author YourName
// @match *://*.ytccr.com/*
// @grant GM_addStyle
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
(function() {
'use strict';
// 添加 CSS 样式
GM_addStyle(`
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.control-panel {
position: fixed;
top: 20px;
right: 20px;
background: rgba(0, 0, 0, 0.85);
border-radius: 15px;
padding: 20px;
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5);
z-index: 1000;
width: 320px;
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 215, 0, 0.3);
transition: all 0.3s ease;
}
.control-panel:hover {
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.7);
transform: translateY(-5px);
}
.panel-title {
font-size: 1.4rem;
margin-bottom: 15px;
color: #ffd700;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
}
.panel-title i {
font-size: 1.6rem;
}
.status-indicator {
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 20px;
}
.status-light {
width: 15px;
height: 15px;
border-radius: 50%;
background: #ff4b4b;
margin-right: 10px;
box-shadow: 0 0 10px #ff4b4b;
}
.status-light.active {
background: #4bff4b;
box-shadow: 0 0 10px #4bff4b;
}
.status-text {
font-size: 1.1rem;
font-weight: 500;
}
.timer-display {
background: rgba(50, 50, 100, 0.5);
border-radius: 10px;
padding: 10px;
text-align: center;
margin-bottom: 20px;
}
.highlight {
color: #ffd700;
font-weight: bold;
font-size: 1.3rem;
}
.action-buttons {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 10px;
margin-bottom: 15px;
}
.btn {
padding: 10px 20px;
font-size: 1rem;
border: none;
border-radius: 50px;
cursor: pointer;
transition: all 0.3s ease;
background: linear-gradient(45deg, #ff8c00, #ffd700);
color: #1a1a2e;
font-weight: bold;
box-shadow: 0 4px 8px rgba(0,0,0,0.3);
display: flex;
align-items: center;
gap: 8px;
flex: 1;
min-width: 120px;
justify-content: center;
}
.btn:hover {
transform: translateY(-3px);
box-shadow: 0 6px 12px rgba(0,0,0,0.4);
}
.btn:active {
transform: translateY(1px);
}
.btn-stop {
background: linear-gradient(45deg, #ff416c, #ff4b2b);
}
.btn-auto-jump {
background: linear-gradient(45deg, #1e90ff, #00bfff);
}
.speed-control {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 15px;
}
.speed-input {
flex: 1;
padding: 10px;
border-radius: 5px;
border: 1px solid #ffd700;
background: rgba(0,0,0,0.5);
color: white;
text-align: center;
font-size: 1rem;
}
.speed-label {
color: #ffd700;
font-weight: bold;
min-width: 80px;
}
.auto-jump-control {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 15px;
}
.auto-jump-input {
flex: 1;
padding: 10px;
border-radius: 5px;
border: 1px solid #00bfff;
background: rgba(0,0,0,0.5);
color: white;
text-align: center;
font-size: 1rem;
}
.auto-jump-label {
color: #00bfff;
font-weight: bold;
min-width: 80px;
}
`);
// 创建控制面板 HTML
const controlPanelHTML = `
`;
// 插入到页面
document.body.insertAdjacentHTML('afterbegin', controlPanelHTML);
// 存储当前状态
let isSpeedUpEnabled = false;
let isAutoJumpEnabled = false;
let targetSpeed = GM_getValue('targetSpeed', 2.0);
let autoJumpInterval = GM_getValue('autoJumpInterval', 30);
let autoJumpTimer = null;
// 初始化输入框值
document.getElementById('speed-input').value = targetSpeed;
document.getElementById('auto-jump-input').value = autoJumpInterval;
// 获取所有视频元素
function getAllVideos() {
return document.querySelectorAll('video');
}
// 应用速度到所有视频
function applySpeedToVideos(speed) {
const videos = getAllVideos();
videos.forEach(video => {
try {
video.playbackRate = speed;
} catch (e) {
console.log('设置播放速度失败:', e);
}
});
}
// 跳至视频结尾
function jumpToEnd() {
const videos = getAllVideos();
videos.forEach(video => {
if (!isNaN(video.duration)) {
video.currentTime = video.duration - 0.5;
}
});
}
// 开始/停止自动跳转
function toggleAutoJump(enable) {
if (enable) {
// 停止现有定时器
if (autoJumpTimer) clearInterval(autoJumpTimer);
// 设置新定时器
autoJumpTimer = setInterval(() => {
jumpToEnd();
console.log(`自动跳转至结尾 (间隔: ${autoJumpInterval}秒)`);
}, autoJumpInterval * 1000);
// 立即执行一次
jumpToEnd();
// 更新UI
document.getElementById('toggle-auto-jump').textContent = '关闭';
document.getElementById('toggle-auto-jump').classList.add('btn-stop');
document.getElementById('toggle-auto-jump').classList.remove('btn-auto-jump');
} else {
// 停止定时器
if (autoJumpTimer) clearInterval(autoJumpTimer);
autoJumpTimer = null;
// 更新UI
document.getElementById('toggle-auto-jump').textContent = '开启';
document.getElementById('toggle-auto-jump').classList.add('btn-auto-jump');
document.getElementById('toggle-auto-jump').classList.remove('btn-stop');
}
}
// 监听DOM变化(动态加载的视频)
const observer = new MutationObserver((mutations) => {
mutations.forEach(mutation => {
if (mutation.addedNodes.length) {
if (isSpeedUpEnabled) {
applySpeedToVideos(targetSpeed);
}
}
});
});
// 开始监听整个文档
observer.observe(document, {
childList: true,
subtree: true
});
// 应用自定义速度
document.getElementById('apply-speed').addEventListener('click', () => {
const newSpeed = parseFloat(document.getElementById('speed-input').value);
if (!isNaN(newSpeed)) {
targetSpeed = Math.max(0.1, Math.min(16, newSpeed));
document.getElementById('speed-input').value = targetSpeed.toFixed(1);
GM_setValue('targetSpeed', targetSpeed);
if (isSpeedUpEnabled) {
applySpeedToVideos(targetSpeed);
}
alert(`已设置播放速度为 ${targetSpeed}x`);
} else {
alert('请输入有效的数字');
}
});
// 切换自动跳转
document.getElementById('toggle-auto-jump').addEventListener('click', () => {
const newInterval = parseInt(document.getElementById('auto-jump-input').value);
if (!isNaN(newInterval) && newInterval >= 5 && newInterval <= 300) {
autoJumpInterval = newInterval;
GM_setValue('autoJumpInterval', autoJumpInterval);
isAutoJumpEnabled = !isAutoJumpEnabled;
toggleAutoJump(isAutoJumpEnabled);
alert(isAutoJumpEnabled
? `已开启自动跳转 (每 ${autoJumpInterval} 秒)`
: '已关闭自动跳转');
} else {
alert('请输入5-300之间的整数');
}
});
// 加速按钮
document.getElementById('speed-up').addEventListener('click', () => {
isSpeedUpEnabled = true;
applySpeedToVideos(targetSpeed);
document.querySelector('.status-light').classList.add('active');
document.querySelector('.status-text').textContent = '加速中';
alert(`已加速至 ${targetSpeed}x`);
});
// 正常速度按钮
document.getElementById('normal-speed').addEventListener('click', () => {
isSpeedUpEnabled = false;
applySpeedToVideos(1.0);
document.querySelector('.status-light').classList.remove('active');
document.querySelector('.status-text').textContent = '运行中';
alert('已恢复正常速度');
});
// 跳至视频结尾
document.getElementById('jump-to-end').addEventListener('click', () => {
jumpToEnd();
alert('已跳至视频结尾!');
});
// 停止播放
document.getElementById('stop-video').addEventListener('click', () => {
const videos = getAllVideos();
videos.forEach(video => {
video.pause();
});
alert('已停止播放!');
});
// 输入框回车事件
document.getElementById('speed-input').addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
document.getElementById('apply-speed').click();
}
});
document.getElementById('auto-jump-input').addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
document.getElementById('toggle-auto-jump').click();
}
});
// 更新时间显示
setInterval(() => {
const timeDisplay = document.querySelector('.highlight');
if (timeDisplay) {
timeDisplay.textContent = new Date().toLocaleTimeString();
}
}, 1000);
})();