bilibili Danmaku Disabler

Auto disable bilibili HTML5 player danmaku.

目前為 2019-08-09 提交的版本,檢視 最新版本

// ==UserScript==
// @name                bilibili Danmaku Disabler
// @name:zh-CN          bilibili 弹幕关闭
// @description         Auto disable bilibili HTML5 player danmaku.
// @description:zh-CN   自动关闭哔哩哔哩 HTML5 播放器弹幕.
// @namespace           bilibili-danmaku-disabler
// @version             2019.06.19
// @author              Akatsuki (akiirui)
// @license             MIT License
// @run-at              document-idle
// @noframes
// @require             https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
// @require             https://greasyfork.org/scripts/48306-waitforkeyelements/code/waitForKeyElements.js?version=275769
// @include             *://www.bilibili.com/video/*
// @include             *://www.bilibili.com/bangumi/play/*
// ==/UserScript==

'use strict';

var selector = {
    "player": "div[class|='feedback']",
    // true -> new player
    true: {
        "on": "input[class='bui-checkbox']:checked",
        "off": "input[class='bui-checkbox']:not(:checked)"
    },
    // false -> old player
    false: {
        "on": "div[name='ctlbar_danmuku_on']",
        "off": "div[name='ctlbar_danmuku_close']"
    }
};

// Disable danmaku when player loaded

function disable_danmaku(player) {
    player[0].click ();
};

waitForKeyElements(selector.true.on, disable_danmaku, false);
waitForKeyElements(selector.false.on, disable_danmaku, false);

// Detect 'm' or 'M' key to control danmaku on/off

function switch_danmaku(player) {
    if (document.querySelector(player.on) != null) {
        // Switch danmaku on -> off
        document.querySelector(player.on).click();
    }
    else if (document.querySelector(player.off) != null){
        // Switch danmaku off -> on
        document.querySelector(player.off).click();
    }
};

$(document).keypress(function(key) {
    var version = document.querySelector(selector.player) != null;
    // detect 'm' or 'M' key
    if (key.which === 77 || key.which === 109) {
        switch_danmaku(selector[version]);
    }
});