Greasy Fork is available in English.

Twitch聊天室自動展開v2

非全螢幕時自動展開聊天室

// ==UserScript==
// @name         Twitch聊天室自動展開v2
// @version      1.4
// @description  非全螢幕時自動展開聊天室
// @author      BaconEgg
// @match        https://www.twitch.tv/*
// @run-at       document-end
// @grant        none
// @namespace https://greasyfork.org/users/735944
// ==/UserScript==

const buttonSelectors = {
    expand: 'button[aria-label="展開聊天"]',
    collapse: 'button[aria-label="摺疊聊天"]',
    exitFullScreen: 'button[aria-label="離開全螢幕 (f)"]',
};

let isInFullScreen = false;

const handleMutations = function () {
    const exitFullScreenButton = document.querySelector(buttonSelectors.exitFullScreen);
    isInFullScreen = exitFullScreenButton !== null;

    const expandButton = document.querySelector(buttonSelectors.expand);
    const collapseButton = document.querySelector(buttonSelectors.collapse);
    const below = document.querySelector('.right-column').classList.contains('right-column--below');
    const isPageVisible = document.visibilityState === 'visible';

    if (expandButton && !isInFullScreen && isPageVisible && !below) {
        expandButton.click();
    } else if (collapseButton && isInFullScreen) {
        collapseButton.click();
    }
};

const observer = new MutationObserver(handleMutations);
observer.observe(document.body, { childList: true, subtree: true });