您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
自动检测特定元素并刷新页面,同时优化观看体验,删除多余元素并点击提升画质
// ==UserScript== // @name Douyin live stream optimization(优化网页) // @namespace http://tampermonkey.net/ // @version 1.0.5 // @description 自动检测特定元素并刷新页面,同时优化观看体验,删除多余元素并点击提升画质 // @match https://*.douyin.com/* // @grant none // @license MIT // @run-at document-idle // ==/UserScript== (function () { 'use strict'; /** ==================== 工具函数定义 ==================== */ function simulateBKeyPress() { try { const event = new KeyboardEvent('keydown', { key: 'b', code: 'KeyB', keyCode: 66, which: 66, bubbles: true }); document.dispatchEvent(event); console.log('[优化] 模拟按下 B 键'); } catch (e) { console.warn('[异常] 模拟按键失败:', e); } } function clickButton() { try { const button = document.querySelector('.psKR9RS0 .WoNKVQmY.Z20k_Nsy'); if (button) { button.click(); console.log('[优化] 画质按钮已点击'); } else { console.log('[优化] 未找到画质按钮'); } } catch (e) { console.warn('[异常] 点击画质按钮失败:', e); } } let hasClickedButton2 = false; function clickButton_2() { if (hasClickedButton2) return; try { const button = document.querySelector('.xMYYJi25'); if (button) { button.click(); console.log('[优化 清晰度] 按钮已点击'); hasClickedButton2 = true; } else { console.log('[优化 清晰度] 按钮未找到'); } } catch (e) { console.warn('[异常] 点击清晰度按钮失败:', e); } } function clickCloseGiftEffect() { try { const toggle = document.querySelector('[data-e2e="effect-switch"]'); if (toggle) { toggle.click(); console.log('[优化] 已点击“屏蔽礼物特效”开关'); } else { console.log('[优化] 未找到“屏蔽礼物特效”开关'); } } catch (e) { console.warn('[异常] 点击关闭礼物特效失败:', e); } } function removeElement(selector, message) { try { const element = document.querySelector(selector); if (element) { element.remove(); console.log(`[优化] ${message} 已删除`); } else { console.log(`[优化] 未找到 ${message}`); } } catch (e) { console.warn(`[异常] 删除 ${message} 失败:`, e); } } function removeSpecialContent() { try { document.querySelectorAll('div._192Y0el > div.ljM5iqdR').forEach(e => e.remove()); console.log('[优化] 礼物删除成功~'); removeElement('.mDjtvQMS.GiftEffectPlugin', '礼物特效元素'); removeElement('.aqK_4_5U.R7IW3rpb', '礼物栏'); removeElement('.NMfqnFm5', '礼物特效元素'); } catch (e) { console.warn('[异常] 删除礼物内容失败:', e); } } function clickNewElement() { try { const newElement = document.querySelector('.D7UhJyco'); if (newElement) { newElement.click(); console.log('[优化] 画质切换成功~'); } else { console.log('[优化] 未找到新的指定元素'); } } catch (e) { console.warn('[异常] 点击新的画质按钮失败:', e); } } function runOptimization() { simulateBKeyPress(); clickButton(); clickButton_2(); removeSpecialContent(); clickNewElement(); clickCloseGiftEffect(); } /** ==================== 轮询检测并删除._D4WLewc.GDP2iTsQ,删除后点击.xJMJ5DRo ==================== */ let notFoundCount = 0; const maxMisses = 3; const optimizationInterval = setInterval(() => { const targetElement = document.querySelector('._D4WLewc.GDP2iTsQ'); if (targetElement) { targetElement.remove(); console.log('[轮询] 删除 ._D4WLewc.GDP2iTsQ'); const clickElem = document.querySelector('.xJMJ5DRo'); if (clickElem) { clickElem.click(); console.log('[轮询] 点击 .xJMJ5DRo'); simulateBKeyPress(); } notFoundCount = 0; } else { notFoundCount++; console.log(`[轮询] 第 ${notFoundCount} 次未检测到`); if (notFoundCount >= maxMisses) { console.log(`[轮询] 连续 ${maxMisses} 次未检测到,停止轮询`); clearInterval(optimizationInterval); } } }, 3000); /** ==================== 修改后的 无限轮询(最多10次)==================== */ let refreshCount = 0; const maxRefreshCount = 10; const refreshInterval = setInterval(() => { refreshCount++; const blockElement = document.querySelector('.ej6cQnWN'); const refreshTarget = document.querySelector('.CkKPEcld'); if (blockElement) { console.log('[刷新检测] 检测到 .ej6cQnWN,停止刷新轮询'); clearInterval(refreshInterval); } else if (refreshTarget) { console.log('[刷新检测] 检测到 .CkKPEcld,刷新页面'); clearInterval(refreshInterval); location.reload(); } else { console.log('[刷新检测] 未检测到关键元素,继续轮询...'); } if (refreshCount >= maxRefreshCount) { console.log(`[刷新检测] 已达最大轮询次数 ${maxRefreshCount},停止轮询`); clearInterval(refreshInterval); } }, 3000); /** ==================== 页面加载后延迟任务(5 秒执行) ==================== */ setTimeout(() => { runOptimization(); }, 5000); /** ==================== 重复性任务(最多执行 10 次) ==================== */ let counter = 0; const maxTries = 10; const interval = setInterval(() => { removeElement('.LE4P00KT', '优化元素 LE4P00KT'); clickNewElement(); counter++; if (counter >= maxTries) clearInterval(interval); }, 1000); })();