Greasy Fork

Greasy Fork is available in English.

BiliBili一键关灯

点击按钮可使视频实现一键关灯模式

当前为 2024-06-23 提交的版本,查看 最新版本

// ==UserScript==
// @name         BiliBili一键关灯
// @version      0.0.8
// @description  点击按钮可使视频实现一键关灯模式
// @author       GSK
// @include      *://*.bilibili.com/*
// @ico          https://www.bilibili.com/favicon.ico?v=1
// @grant    GM_setValue
// @grant    GM_getValue
// @license      MIT License
// @namespace http://greasyfork.icu/users/1321187
// ==/UserScript==


(function() {

    'use strict';
    // 键盘操作
    document.onkeydown = hotkey;
    function hotkey() {
        // 接收指令
        var a = window.event.keyCode;
        // 判断是否与目标码相同
        // 按键A:视频关灯
        if (a == 65) {
            // 通过标签拿资源
            var inputLight = document.querySelector('[aria-label="关灯模式"]');
            // 元素存在对其进行操作
            inputLight.click();

            // 关灯or开灯
            // document.getElementsByClassName("bui-checkbox-input")[3].click();
        }

        // 按键S:番剧关灯
        //if (a == 83) {
        //    // 关灯or开灯
        //    document.getElementsByClassName("bui-checkbox-input")[1].click();
        //}

        // 按键Z:删除头部
        if (a == 90) {
            // 获取div
            var div = document.getElementsByClassName("fixed-header")[0];
            // 删除div
            div.parentNode.removeChild(div);

        }
    }

    // 鼠标操作
    document.onmousedown = function(event) {
        // 通过标签拿资源
        var inputLight = document.querySelector('[aria-label="关灯模式"]');
        // var event = event || window.event//兼容ie低版本的

        // 鼠标侧键3:后退按键
        if(event.button == 3) {
            // 元素存在对其进行操作
            inputLight.click();
        }

        // 鼠标侧键4:前进按键
        if(event.button == 4) {
            // 获取div
            var div = document.getElementsByClassName("fixed-header")[0];
            // 删除div
            div.parentNode.removeChild(div);
        }
    }

    // Your code here...
})();