BILIBILI MoeUseHelper

BBMUH - 一键开关弹幕|播放暂停|调整倍速|开关全屏|能让你用bilibili更加愉快的助手

目前為 2020-08-10 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         BILIBILI MoeUseHelper
// @version      0.0.2
// @description  BBMUH - 一键开关弹幕|播放暂停|调整倍速|开关全屏|能让你用bilibili更加愉快的助手
// @author       萌萌哒丶九灬书
// @namespace    https://space.bilibili.com/1501743
// @license      GNU General Public License v3.0
// @create       2020-03-25
// @lastmodified 2020-08-10
// @note         感谢R君发布的基础版本,在他的基础上修改、增加了部分实现内容。
// @match        *://www.bilibili.com/*
// @require      https://cdn.staticfile.org/jquery/1.12.4/jquery.min.js
// ==/UserScript==

// 小键盘8、2分别是增加音量、减少音量(B站自带)
// 小键盘4、6分别是后退、前进(B站自带)
var 播放暂停 = 101; //小键盘数字键5
var 开关弹幕 = 103; //小键盘数字键7
var 全屏模式 = 105; //小键盘数字键9
var 网页全屏 = 111; //小键盘“/”键
var 宽屏模式 = 106; //小键盘“*”键
var 增加倍速 = 107; //小键盘“+”键
var 减少倍速 = 109; //小键盘“-”键
var 清空倍速 = 97;  //小键盘数字键1
// 以上每一个按键都可以自定义,可以按照自己的喜好自行对照键盘键位对应编码来修改
// 笔记本电脑或者是没有小键盘的同学,请参考下面的键盘编码表更改键位
// 对照修改的键盘编码表链接,复制右边的链接到地址栏打开https://jingyan.baidu.com/article/fedf073780e16335ac8977a4.html

//这里设置倍速
var video_speed = [0.1, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 4, 8, 16];

//jq重定义,避免冲突
var jq = jQuery.noConflict();

function tips_video_speed(speed){
    var get_tips_div = jq("#tips_div");
    if(get_tips_div.val() == undefined){
    var tips_div = '<div id="tips_div" style="border-radius: 20px;'+
            'background:#000;'+
            'width: 120px;'+
            'height: 40px;'+
            'position:fixed;'+
            'left:50%; top:50%;'+
            'margin-left:-60px;'+
            'margin-top:-20px;'+
            'text-align:center;'+
            'line-height:40px;'+
            'font-size:20px;'+
            'color:#FFF;'+
            'opacity:0.8;'+
            'z-index:9999999999;">倍数:'+speed+'</div>';
        jq(".bilibili-player-video").append(tips_div);
        jq("#tips_div").animate({opacity:"0.8"},1000).animate({opacity:"0"},500);
    }else{
        if(!get_tips_div.is(":animated")){
            get_tips_div.text("倍数:"+speed);
            get_tips_div.css("opacity","0.8").animate({opacity:"0.8"},1000).animate({opacity:"0"},500);
        }else{
            get_tips_div.stop(true, true);
            get_tips_div.text("倍数:"+speed);
            get_tips_div.css("opacity","0.8").animate({opacity:"0.8"},1000).animate({opacity:"0"},500);
        }
    }

}
var video_speed_control = jq(".bilibili-player-video video")[0];
var video_speed_num = 0;
for(var i = 0; i< video_speed.length; i++){
    if(video_speed[i] == 1.0){
        video_speed_num = i;
        break;
    }
}
function add_video_speed(){
    if(++video_speed_num >= video_speed.length){
        video_speed_num--;
    }
    video_speed_control.playbackRate = video_speed[video_speed_num];
    tips_video_speed(video_speed[video_speed_num]);
}
function sub_video_speed(){
    if(--video_speed_num < 0){
        video_speed_num++;
    }
    video_speed_control.playbackRate = video_speed[video_speed_num];
    tips_video_speed(video_speed[video_speed_num]);
}
function reset_video_speed(){
    video_speed_num = 0;
    for(var i = 0; i< video_speed.length; i++){
        if(video_speed[i] == 1.0){
            video_speed_num = i;
            break;
        }
    }
    video_speed_control.playbackRate = video_speed[video_speed_num];
    tips_video_speed(video_speed[video_speed_num]);
}
function click_wide_screen(){
    jq("button[data-text='宽屏模式']").click();
}
function click_web_Full_screen(){
    jq("button[data-text='网页全屏']").click();
}
function click_Full_screen(){
    jq("button[data-text='进入全屏']").click();
}
function click_Barrage(){
    jq(".bui-switch-input").click();
}
function stop_video(){
    jq("button[aria-label='播放']").click();
}
jq(document).ready(function() {
    jq(document).keydown(function(event){
        //调用键盘编码,按了键盘回调keydown里的function(event)函数,event就是你按的那个按键的code码
        switch(event.keyCode){
            case 播放暂停:
                stop_video();
                break;
            case 开关弹幕:
                click_Barrage();
                break;
            case 全屏模式:
                click_Full_screen();
                break;
            case 网页全屏:
                click_web_Full_screen();
                break;
            case 宽屏模式:
                click_wide_screen();
                break;
            case 增加倍速:
                add_video_speed();
                break;
            case 减少倍速:
                sub_video_speed();
                break;
            case 清空倍速:
                reset_video_speed();
                break;
        };
    });
});