Greasy Fork

Greasy Fork is available in English.

bilibili-哔哩哔哩关灯

bilibili-哔哩哔哩关灯添加到视频右键

当前为 2021-08-22 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         bilibili-哔哩哔哩关灯
// @namespace    http://tampermonkey.net/
// @description  bilibili-哔哩哔哩关灯添加到视频右键
// @version      0.2
// @author       tomiaa
// @match        *://www.bilibili.com/video/*

// ==/UserScript==
; (() => {
    console.clear()
    const doc = document;
    let isAppend = false;
    const player = doc.getElementById('bilibiliPlayer')
    let observer = new MutationObserver(() => {
      if(isAppend) return observer.disconnect();
      
      let menu = player.getElementsByClassName('bilibili-player-context-menu-container');

      if(!menu.length ) return;
      if(!Array.from(menu[1].classList).includes('active')) return;

      let ul = menu[1].children[0]; 

      let li = doc.createElement('li');
      li.className = 'context-line context-menu-function';
      let a = doc.createElement('a');
      a.className = 'context-menu-a js-action';
      a.innerHTML = '关 灯';
      li.appendChild(a);
      let isGuandeng = false;
      li.addEventListener('click', () => {
        let mask = doc.getElementById('heimu')
        let player = doc.getElementById('bilibiliPlayer');
        doc.getElementById('bilibili-player').style.zIndex = '99999';
        if(!isGuandeng){
          a.innerHTML = '开 灯';
          mask.style.display = 'block';
          player.classList.add('mode-light-off');
        }else{
          a.innerHTML = '关 灯';
          mask.style.display = 'none';
          player.classList.remove('mode-light-off');
        }
        isGuandeng = !isGuandeng;
      })
      
      ul.appendChild(li);
      isAppend = true;

    });
    observer.observe(player,{
      childList: true,
      subtree: true,
    })
})();