Greasy Fork

Greasy Fork is available in English.

哔哩哔哩网页视频速度右键菜单

在哔哩哔哩网页视频右键菜单中添加视频播放速度选项

当前为 2020-08-14 提交的版本,查看 最新版本

// ==UserScript==
// @name         哔哩哔哩网页视频速度右键菜单
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  在哔哩哔哩网页视频右键菜单中添加视频播放速度选项
// @author       beibeibeibei
// @match        *.bilibili.com/video/*
// @match        *.bilibili.com/bangumi/play/*
// @grant        none
// @require      http://code.jquery.com/jquery-1.12.4.min.js

// ==/UserScript==

(function() {
    'use strict';
    // Your code here...
    var speed_before  = ["加速", "加速", "加速","原速", "减速","减速" ];
    var speed         = ["2.00", "1.50", "1.25","1.00", "0.75","0.50" ];
    var speed_display = true;
    var speed_after   = ["★★★★★★",
                         "★★★★★",
                         "★★★★",
                         "★★★",
                         "★★",
                         "★"
                        ];
    var $=jQuery.noConflict(); //省得一堆未定义错误
    var longClass = "3a4fb3de-e139-4738-864f-acca6bb8b398";
    var b_width = 165;//和原来一样宽
    var bg_color = "background-color";
    var color = ["rgba(255,255,255,0.12)", //鼠标悬停时颜色
                 "rgba(0,0,0,0)",          //未悬停颜色
                ];
    function isbangumi(){if(location.href.search('bangumi')!==-1){return true;}else{return false;}}
    function isvideo(){if(location.href.search('video')!==-1){return true;}else{return false;}}
    function change_speed(videoSpeed){
        document.querySelector("li[data-value='" + videoSpeed + "']").click();
    }
    function s(str){
        var speed_index = speed.map(parseFloat).lastIndexOf(parseFloat(str));
        var s2 = [];
        s2[0] = 'id="' + speed_before[speed_index] + str.replace('.',' ') + speed_after[speed_index] + '" class="' + longClass + '"';
        s2[1] = '<a>' + speed_before[speed_index] + str + speed_after[speed_index] + '</a>';
        s2[2] = parseFloat(str);
        s2[3] = '[id="' + speed_before[speed_index] + str.replace('.',' ') + speed_after[speed_index] + '"]'; //[id='加速2 0']
        if (speed_display === false){
            s2[1] = '<a>' + speed_before[speed_index] + speed_after[speed_index] + '</a>';
        }
        return s2;
    }
    function add_buttom_style(contextMenu_ul, str){
        contextMenu_ul.append('<li '+s(str)[0]+'>'+s(str)[1]+'</li>');
        $(s(str)[3]).bind("click",function(){change_speed(s(str)[2]);});
        $(s(str)[3]).hover(function(){$(s(str)[3]).css(bg_color,color[0]);},function(){$(s(str)[3]).css(bg_color,color[1]);});
        $(s(str)[3]).css("min-width", b_width);
    }
    function add_buttom(e){
        var contextMenu_ul = $(".bilibili-player-context-menu-container.black.bilibili-player-context-menu-origin ul");
        var first_added = '[id="' + speed_before[0] + speed[0].replace('.',' ') + speed_after[0] + '"]';
        if(contextMenu_ul.length == 1 && $(first_added).length === 0){
            for(var count = 0; count < speed.length; count++){
                add_buttom_style(contextMenu_ul,speed[count]);
            }
            //             add_buttom_style(contextMenu_ul,speed[0]);
            //             add_buttom_style(contextMenu_ul,speed[1]);
            //             add_buttom_style(contextMenu_ul,speed[2]);
            //             add_buttom_style(contextMenu_ul,speed[3]);
            //             add_buttom_style(contextMenu_ul,speed[4]);
            //             add_buttom_style(contextMenu_ul,speed[5]);
        }
        var contextMenu_ul_li = $(".bilibili-player-context-menu-container.black.bilibili-player-context-menu-origin ul li");
        if(contextMenu_ul_li.length > speed.length){
            contextMenu_ul_li.first().remove();
        }
    }

    if(isvideo()){
        $("#bilibiliPlayer").on("DOMNodeInserted",add_buttom);
    }
    if(isbangumi()){
        $("#bofqi").on("DOMNodeInserted",add_buttom);
    }

    // Your code here...
})();
//查找(CTRL+F)窗口占位
//
//查找(CTRL+F)窗口占位