// ==UserScript== // @name 抖音优化: 强制最高画质+自动跳过直播 // @namespace http://tampermonkey.net/ // @version 6.1 // @description V6.1美化版:右上方胶囊开关。优先检测并自动跳过直播,非直播视频自动强制切换到最高画质 (4K/2K/1080P)。 // @author You // @match https://www.douyin.com/* // @match https://live.douyin.com/* // @grant none // @run-at document-idle // @license All Rights Reserved // @downloadURL https://update.greasyfork.icu/scripts/557986/%E6%8A%96%E9%9F%B3%E4%BC%98%E5%8C%96%3A%20%E5%BC%BA%E5%88%B6%E6%9C%80%E9%AB%98%E7%94%BB%E8%B4%A8%2B%E8%87%AA%E5%8A%A8%E8%B7%B3%E8%BF%87%E7%9B%B4%E6%92%AD.user.js // @updateURL https://update.greasyfork.icu/scripts/557986/%E6%8A%96%E9%9F%B3%E4%BC%98%E5%8C%96%3A%20%E5%BC%BA%E5%88%B6%E6%9C%80%E9%AB%98%E7%94%BB%E8%B4%A8%2B%E8%87%AA%E5%8A%A8%E8%B7%B3%E8%BF%87%E7%9B%B4%E6%92%AD.meta.js // ==/UserScript== (function() { 'use strict'; // ========================================== // 全局配置参数 // ========================================== const MAIN_INTERVAL = 1000; // 主循环检测频率 (毫秒) const SKIP_COOLDOWN = 1500; // 跳过直播后的冷却时间 const QUALITIES = ["超清 4K", "超清 2K", "高清 1080P"]; // 画质优先级 // ========================================== // 全局状态变量 // ========================================== let isSkipping = false; // 读取开关状态,默认开启 let isSkipEnabled = localStorage.getItem('dy_skip_live_enabled') !== 'false'; let lastVideoSrc = ""; let isQualityChecked = false; // ========================================== // 工具函数库 // ========================================== // 1. 模拟按键 function simulateKeyDown() { const event = new KeyboardEvent('keydown', { key: 'ArrowDown', code: 'ArrowDown', keyCode: 40, which: 40, bubbles: true, cancelable: true }); document.dispatchEvent(event); console.log('【抖音助手】执行跳过'); } // 2. 元素可视检测 function isElementInViewport(el) { const rect = el.getBoundingClientRect(); const windowHeight = (window.innerHeight || document.documentElement.clientHeight); const windowWidth = (window.innerWidth || document.documentElement.clientWidth); return (rect.top >= 0 && rect.bottom <= windowHeight) && (rect.left < windowWidth * 0.75); } // 3. 提示 Toast function showToast(text) { const existing = document.getElementById('dy-helper-toast'); if(existing) existing.remove(); const div = document.createElement('div'); div.id = 'dy-helper-toast'; div.innerText = text; div.style.cssText = ` position: fixed; top: 20%; left: 50%; transform: translate(-50%, -50%); background-color: rgba(0, 0, 0, 0.85); color: #fff; padding: 12px 24px; border-radius: 50px; z-index: 100000; font-size: 15px; pointer-events: none; box-shadow: 0 5px 15px rgba(0,0,0,0.4); transition: opacity 0.3s; font-weight: bold; backdrop-filter: blur(5px); `; document.body.appendChild(div); setTimeout(() => { div.style.opacity = '0'; setTimeout(() => div.remove(), 500); }, 1500); } // 4. 指针事件 function triggerPointerEvent(element, eventType) { if (!element) return; element.dispatchEvent(new PointerEvent(eventType, { bubbles: true, cancelable: true, view: window, pointerId: 1, width: 1, height: 1, isPrimary: true, pointerType: 'mouse' })); } // 5. 查找画质按钮 function findResolutionButton() { const keywords = ["智能", "标清", "高清", "超清", "4K", "1080P", "720P"]; const tags = ['span', 'div']; for (let tag of tags) { const els = document.getElementsByTagName(tag); for (let i = els.length - 1; i >= 0; i--) { const el = els[i]; if (!el.innerText) continue; const txt = el.innerText.trim(); if (keywords.some(k => txt.includes(k))) { if (el.clientHeight > 10 && el.clientHeight < 50 && el.clientWidth < 150) { return el; } } } } return null; } // ========================================== // UI 界面模块 (美化版) // ========================================== function initUI() { // 主容器 const btn = document.createElement('div'); // 样式:右上方,胶囊形状,鲜艳配色 const updateStyle = () => { const bgColor = isSkipEnabled ? 'linear-gradient(135deg, #00C853, #69F0AE)' : '#333'; // 开启绿色渐变,关闭深灰 const textColor = isSkipEnabled ? '#004D40' : '#888'; const icon = isSkipEnabled ? '⚡' : '🚫'; const shadow = isSkipEnabled ? '0 0 15px rgba(0, 230, 118, 0.6)' : 'none'; btn.style.background = bgColor; btn.style.boxShadow = shadow; btn.innerHTML = ` ${icon} 跳过直播