Auto expand and/or darken

The script auto expands, and/or darkens, the video player when the page loads, without the need for clicking anything.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name          Auto expand and/or darken
// @version       2.1.0
// @description   The script auto expands, and/or darkens, the video player when the page loads, without the need for clicking anything.
// @namespace     JustGotenks
// @license       MIT
// @match         https://zoro.to/watch/*
// @grant         GM_addStyle
// @run-at        document-idle
// ==/UserScript==


const autoExpand = true;

const autoDark = true;

const secondsToWait = 4;



// Sets the background color when the light is switched to 'off'.
// You can change it to any color.
GM_addStyle(`
#mask-overlay {
  background-color: black;
}
`);


const start = async () => {

  const element = (selector) => {
    return new Promise(resolve => {
      const ele = document.querySelector(selector);
      // if element already exists, return it. (no need for observer)
      if(ele) {
        resolve(ele);
        return;
      }
      // starts observing the document for "ele".
      new MutationObserver((_, observer) => {
        // if "ele" found, then return it and stop observer.
        if(ele) {
          resolve(ele);
          observer.disconnect();
        }
      })
      .observe(document.documentElement, {
        childList: true,
        subtree: true
      });

    });
  };

  const switches = () => {
    if(autoExpand && resizeBtn.textContent === 'Expand') {
      resizeBtn.click();
    }
    if(autoDark && !switchBtn.classList.contains('off')) {
      switchBtn.click();
    }
  };

  const addSwitchToSeekButtons = async () => {
    const prevBtn = await element('.block-prev');
    const nextBtn = await element('.block-next');
    prevBtn.addEventListener('click', switches);
    nextBtn.addEventListener('click', switches);
  };

  const addSwitchToEpisodeButtons = async () => {
    const episodeBtnsContainer = await element('#detail-ss-list');
    const episodeBtns = episodeBtnsContainer.querySelectorAll('.ep-item');
    for(let btn of episodeBtns) {
      btn.addEventListener('click', switches);
    }
  };


  const resizeBtn = await element('#media-resize');
  const switchBtn = await element('#turn-off-light');
  switches();

  addSwitchToSeekButtons();

  setTimeout(addSwitchToEpisodeButtons, 1000 * secondsToWait);
};



start();