Auto switch to chat for offline channels

Automaticaly switches to the chat view and closes the "Most Recent Video" and "Whatch now" popups when joining an offline channel.

Verze ze dne 16. 05. 2023. Zobrazit nejnovější verzi.

// ==UserScript==
// @name         Auto switch to chat for offline channels
// @namespace    https://greasyfork.dpdns.org/scripts?set=586259
// @version      1.0
// @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;
}

void async function () {
    'use strict';

    let prevUrl = undefined;
    setInterval(async () => {
        const currUrl = window.location.href;
        if (currUrl != prevUrl) {
            setup(prevUrl === undefined);
            prevUrl = currUrl;
        }
    }, 1000);
}();

async function setup(firstTime) {
    let button = await getElement(".dsPxpS");
    if (button === null) // channel is online
        return;
    button.click();
    button = (await getElement(".lcxkII")).lastChild;
    button.click();
    button = (await getElement(".msxZI")).lastChild;
    button.click();
}
长期地址
遇到问题?请前往 GitHub 提 Issues,或加Q群1031348184

赞助商

Fishcpy

广告

Rainyun

注册一下就行

Rainyun

一年攒够 12 元