Twitch 自動劇院模式

auto click theatre mode button

目前為 2021-09-05 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name               Twitch Auto Theatre
// @name:zh-TW         Twitch 自動劇院模式
// @namespace          http://tampermonkey.net/
// @version            0.6
// @description        auto click theatre mode button
// @description:zh-tw  進入頁面自動啟動劇院模式
// @author             Long
// @match              https://www.twitch.tv/*
// @icon               https://www.google.com/s2/favicons?domain=twitch.tv
// @grant              none
// ==/UserScript==

(function () {
  "use strict";

  // method 1
  // window.onload = function() {
  //   var twitchAutoTheatreIntervalRetry = 100;
  //   var twitchAutoTheatreInterval = setInterval(function () {
  //     let $theatreModeButton = document.querySelector('[data-a-target="player-theatre-mode-button"]');
  //     // console.log($theatreModeButton);
  //     if ($theatreModeButton) {
  //       $theatreModeButton.click();
  //       clearInterval(twitchAutoTheatreInterval);
  //       console.log("[Twitch-Auto-Theatre] theatre-mode-button clicked.");
  //     } else if (!twitchAutoTheatreIntervalRetry) {
  //       clearInterval(twitchAutoTheatreInterval);
  //       console.warn("[Twitch-Auto-Theatre] theatre-mode-button not found.");
  //     }
  //     twitchAutoTheatreIntervalRetry--;
  //   }, 500);
  // };

  // method 2
  let observer = new MutationObserver(mutations => {
    for(let mutation of mutations) {
      let node = mutation.target;
      if (node.matches('.player-controls__right-control-group')) {
        observer.disconnect();
        let $theatreModeButton = document.querySelector('[data-a-target="player-theatre-mode-button"]');
        if ($theatreModeButton) {
          $theatreModeButton.click();
          console.log("[Twitch-Auto-Theatre] theatre-mode-button clicked.");
        } else {
          console.warn("[Twitch-Auto-Theatre] control-group found. but button not found.")
        }
      }
    }
  });
  observer.observe(document.getElementById('root'), {
    childList: true,
    subtree: true,
  });
})();