// ==UserScript== // @name:en-US bilibili-Danmaku-Gate // @name B站弹幕关闭 // @description:en-US Auto disable bilibili HTML5 player danmaku. // @description 自动关闭哔哩哔哩 HTML5 播放器弹幕. // @namespace https://greasyfork.org/users/135090 // @version 2022.02.16 // @author Akatsuki Rui // @license MIT License // @grant GM_info // @run-at document-idle // @description fork from 374051,https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js // @match *://www.bilibili.com/*video/* // @match *://www.bilibili.com/bangumi/play/* // @match *://www.bilibili.com/blackboard/* // @match *://www.bilibili.com/html/player.html* // @match *://player.bilibili.com/* // @downloadURL none // ==/UserScript== "use strict"; const SELECTOR_NATIVE = { on: "input:checked[class='bui-switch-input']", off: "input:not(:checked)[class='bui-switch-input']", }; const SELECTOR_EMBED = { on: "div[class~='bilibili-player-video-btn-danmaku'][data-text='打开弹幕']", off: "div[class~='bilibili-player-video-btn-danmaku'][data-text='关闭弹幕']", }; const IS_EMBED = document.location.hostname === "player.bilibili.com"; const SELECTOR = IS_EMBED ? SELECTOR_EMBED : SELECTOR_NATIVE; // Skip Charge Support function skipCharge() { const skip = () => { setTimeout(() => { document .getElementsByClassName("bilibili-player-electric-panel-jump")[0] .click(); }, 10); }; const videoElementA = document.querySelector("video"); const videoElementB = document.querySelector("bwp-video"); if (videoElementA) { videoElementA.onended = skip; } else if (videoElementB) { videoElementB.onended = skip; } } // Disable danmaku function disableDanmaku() { const button = document.querySelector(SELECTOR.on); if (button) { button.click(); skipCharge(); } if (!document.querySelector(SELECTOR.off)) { setTimeout(disableDanmaku, 500); } } // Disable danmaku with PJAX detector function disableDanmakuPJAX() { const obServer = new MutationObserver(disableDanmaku); const obTarget = document.getElementById("bilibili-player"); const obOption = { childList: true }; disableDanmaku(); obServer.observe(obTarget, obOption); } // Redirect `bilibili.com/s/video/*` to `bilibili.com/video/*` if (location.href.includes("/s/video/")) { location.replace(location.href.replace("/s/video/", "/video/")); } // Run disabler IS_EMBED ? disableDanmaku() : disableDanmakuPJAX();