您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Automaticaly switches to the chat view and closes the "Most Recent Video" and "Whatch now" popups when joining an offline channel.
// ==UserScript== // @name Auto switch to chat for offline channels // @namespace https://greasyforks.org/scripts?set=586259 // @version 1.3.2 // @description Automaticaly switches to the chat view and closes the "Most Recent Video" and "Whatch now" popups when joining an offline channel. // @author Sonyo // @match http*://www.twitch.tv/* // @grant none // @license MIT // ==/UserScript== function delay(milliseconds) { return new Promise(resolve => { setTimeout(resolve, milliseconds); }); } async function getElement(selector) { var element = document.querySelector(selector); let count = 0; while (element === null) { await delay(1000); element = document.querySelector(selector); count++; if (count > 15) { return null; } } return element; } async function getNthElement(selector, n) { var elements = document.querySelectorAll(selector); let count = 0; while (elements.length === 0) { await delay(1000); elements = document.querySelectorAll(selector); count++; if (count > 15) { return null; } } if (elements.length >= n - 1) return elements[n]; return null; } void async function () { 'use strict'; let prevUrl = undefined; setInterval(async () => { const currUrl = window.location.href; if (currUrl != prevUrl) { if (currUrl.includes(prevUrl)) // User switching to About or other page return; setup(prevUrl === undefined); prevUrl = currUrl; } }, 1000); }(); async function setup(firstTime) { let button = await getNthElement(".cmTyEs", 4); if (button === null) // channel is online return; button.click(); button = await getElement(".WDQCx"); if (button === null) // no videos return; button.lastChild.click(); button = await getElement(".cHbtnp"); button.lastChild.click(); }