Twitch, Fullscreen mode with chat

Enable fullscreen mode with chat when click fullscreen button or key down f key on theater mode

// ==UserScript==
// @name         Twitch, Fullscreen mode with chat
// @name:ja      Twitch, チャット付きフルスクリーンモード
// @namespace    http://tampermonkey.net/
// @version      0.1.3
// @description  Enable fullscreen mode with chat when click fullscreen button or key down f key on theater mode
// @description:ja シアターモードでフルスクリーンボタンを押すかFキーを押したとき、チャットありのフルスクリーンモードになります
// @author       You
// @match        https://www.twitch.tv/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=twitch.tv
// @grant        none
// @run-at       document-end
// @noframes
// ==/UserScript==

(function() {
    'use strict';

    var selectors = {
        fullscreenButton : `[data-a-target="player-fullscreen-button"]`,
        theaterModeButton: `[data-a-target="player-theatre-mode-button"]`,
        theaterModeStyle: ".channel-root__scroll-area--theatre-mode",
    }

    function setTheaterMode(enabled) {
        if (isTheaterMode() != enabled) {
            document.querySelector(selectors.theaterModeButton).click();
        }
    }

    function isTheaterMode () {
        return !!document.querySelector(selectors.theaterModeStyle);
    }

    function requestFullscreen() {
        setTheaterMode(true);
        document.documentElement.requestFullscreen();
    }

    function cancelEvent(event) {
        event.preventDefault();
        event.stopPropagation();
        event.stopImmediatePropagation();
    }

    document.addEventListener("click", ev => {
        if (ev.target && ev.target.closest(selectors.fullscreenButton) && !document.fullscreen) {
            cancelEvent(ev);
            requestFullscreen();
        }
    });

    document.addEventListener("keydown", ev => {
        if (ev.target.tagName == "INPUT" || ev.target.tagName == "TEXTAREA") return;
        if (ev.key == "f" && !document.fullscreen) {
            cancelEvent(ev);
            requestFullscreen();
        }
    });
})();