Greasy Fork

Greasy Fork is available in English.

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.

当前为 2022-08-02 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name          Auto expand and/or darken
// @version       2.0.0
// @description   The script auto expands, and/or darkens, the video player when the page loads, without the need for clicking anything.
// @namespace     Gotenks
// @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.onclick = () => switches();
    nextBtn.onclick = () => switches();
  };

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


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

  addSwitchToSeekButtons();

  setTimeout(addSwitchToEpisodeButtons, 1000 * secondsToWait);
};



start();