// ==UserScript== // @name bilibili-哔哩哔哩关灯 // @namespace http://tampermonkey.net/ // @description bilibili-哔哩哔哩关灯添加到视频右键 // @version 0.2 // @author tomiaa // @match *://www.bilibili.com/video/* // @downloadURL none // ==/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, }) })();