哔哩哔哩轻量化

哔哩哔哩播放器轻量化工具

目前为 2023-01-29 提交的版本。查看 最新版本

// ==UserScript==
// @name         哔哩哔哩轻量化
// @namespace    https://ez118.github.io/
// @version      3.3
// @description  哔哩哔哩播放器轻量化工具
// @author       ZZY_WISU
// @match        https://*.bilibili.com/*
// @match        http://*.bilibili.com/*
// @icon         https://static.hdslb.com/images/favicon.ico
// @license      GNU GPLv3
// @grant        GM_xmlhttpRequest
// @grant        GM_download
// @grant        GM_registerMenuCommand
// @grant        GM_unregisterMenuCommand
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_addStyle
// @run-at document-start
// ==/UserScript==

/* Config*/
var ReplySumMax = 40; /* 作者提示:将"最多可显示的评论数"增加, 可能会使评论加载过程变慢 */

var VideoDetail = "";
/* Final */


function GetAjax(url,func) {
    GM_xmlhttpRequest({
        method: "GET", url: url, data:"",
        headers: {"Content-Type": "application/x-www-form-urlencoded;charset=utf-8"},
        onload: function(response){func(response.responseText);}, onerror: function(response){alert("[错误]\n请求失败");}
    });
}

function $GET(name){
    var reg = new RegExp('(^|&)'+name+'=([^&]*)(&|$)', 'i');
    var r = window.location.search.substr(1).match(reg);
    if (r != null) { return unescape(r[2]); }
    return "";
}

function GetRedirect(){
    var str = window.location.href;
    str = str.replace("/s/", "/");
    if(str.indexOf("?") !== -1){}else{ str += "?";}
    str = str.split("/")[4].replace(str.substring(str.lastIndexOf("?")), "").replace("/", "");
    if(str[1] == "v"){
        return {"type":"aid", "id":str.replace("av", "")};
    } else {
        return {"type":"bvid", "id":str};
    }
}

function GetVideoReplies(aid){
    GetAjax("https://api.bilibili.com/x/v2/reply?jsonp=jsonp&pn=1&type=1&sort=2&oid=" + aid,function(result){
        let UserShow = "";
        result = eval("(" + result + ")");
        if(result.code == 0){
            for(let i = 0; i <= ReplySumMax; i ++) {
                try {
                    UserShow += "【" + result.data.replies[i].member.uname + "】 " + result.data.replies[i].content.message + "\n";
                } catch(e){console.log("Reply Sum Less Than expected (" + i + "/" + ReplySumMax + ")");}
            }
            //alert(UserShow);
            ShowVideoReplies(UserShow);
        } else {
            alert("获取评论失败!");
        }
    });
}

function ShowVideoReplies(content){
    content = content.replace(/\[.*?\]/g,"").replace(/\r?\n/g,'<br/>').replace(/\【/g, "<b>【").replace(/\】/g, "】</b>");

    GM_addStyle(".userscript-bilibili-replies-close { width:100%; border-radius:12px; background:#f25d8e; color:#FFF; padding:8px; border:none; margin:5px 0 5px 0; }");
    GM_addStyle(`.userscript-bilibili-replies-hide { width:25%; height:100%; overflow-x:auto; background:#FFF; color:#000; padding:10px; border:1px solid #CCC; line-height:20px; font-size:15px; position:fixed; top:0px; left:98%; bottom:0px; z-index:999; transition: all 0.3s; }
                 .userscript-bilibili-replies-hide:hover { left:75%; }`);
    GM_addStyle(".userscript-bilibili-replies-show { width:25%; height:100%; overflow-x:auto; background:#FFF; color:#000; padding:10px; border:1px solid #CCC; line-height:20px; font-size:15px; position:fixed; top:0px; left:75%; bottom:0px; z-index:999; }");
    GM_addStyle(".userscript-bilibili-reptitle { font-size:20px; font-weight:bold; margin-bottom:10px; color:#FFFFFF; background-color:#000000;}");

    let MDiv = document.createElement('div');
    document.body.appendChild(MDiv);
    MDiv.setAttribute("class", "userscript-bilibili-replies-show");
    MDiv.setAttribute("id", "userscript-bilibili-replies");

    MDiv.innerHTML = `<b class="userscript-bilibili-reptitle">&nbsp;视频详情&nbsp;</b><br/>` + VideoDetail.replace(/\r?\n/g,'<br/>') + `<br/><hr/>
        <b class="userscript-bilibili-reptitle">&nbsp;视频评论&nbsp;</b><br/>` + content + `<br/>
        <button onclick='document.getElementById("userscript-bilibili-replies").remove()' class="userscript-bilibili-replies-close">关闭浏览栏</button><br/><br/>`;

    setTimeout(function(){
        document.getElementById('userscript-bilibili-replies').setAttribute('class','userscript-bilibili-replies-hide');
    }, 3000)
}

let menu1 = GM_registerMenuCommand('查看视频详情&评论', function () {
    let domain = window.location.href.split("/")[2];
    if(domain == "player.bilibili.com"){
        let DataStr = "";
        if($GET("bvid") != ""){ DataStr = "bvid=" + $GET("bvid"); }
        else { DataStr = "aid=" + $GET("aid"); }
        GetAjax("https://api.bilibili.com/x/web-interface/view?" + DataStr, function(aid){
            aid = eval("("+aid+")");
            GetVideoReplies(aid.data.aid);
            try{ VideoDetail = aid.data.desc; } catch(e){ console.log("[USERSCRIPT/哔哩哔哩轻量化] 获取视频详情文本失败"); }
        });
    } else {
        let cb = GetRedirect();
        if(cb.type == "bvid"){
            GetAjax("https://api.bilibili.com/x/web-interface/view?bvid=" + cb.id, function(aid){
                aid = eval("("+aid+")");
                GetVideoReplies(aid.data.aid);
            });
        } else {
            GetVideoReplies(cb.id);
        }
    }
}, 'R');


let menu2 = GM_registerMenuCommand('在BiliBili客户端中查看视频', function () {
    let PageUrl = window.location.href;
    let domain = PageUrl.split("/")[2];
    if(domain == "www.bilibili.com" && ( PageUrl.split("/")[3] == "video" || PageUrl.split("/")[3] == "s")){
        let cb = GetRedirect();
        if(cb.type == "bvid"){
            GetAjax("https://api.bilibili.com/x/web-interface/view?bvid=" + cb.id, function(aid){
                aid = eval("("+aid+")");
                location.href = "bilibili://video/" + aid.data.aid;
            });
        } else {
            location.href = "bilibili://video/" + cb.id;
        }
    } else if(domain == "player.bilibili.com") {
        if($GET("bvid") != ""){
            GetAjax("https://api.bilibili.com/x/web-interface/view?bvid=" + $GET("bvid"), function(aid){
                aid = eval("("+aid+")");
                location.href = "bilibili://video/" + aid.data.aid;
            });
        } else {
            location.href = "bilibili://video/" + $GET("aid");
        }
    }
}, 'O');



(function() {
    'use strict';
    GM_setValue('TinyMode', {'state':'true'});

    var PageUrl = window.location.href;
    var domain = PageUrl.split("/")[2];

    if(domain == "www.bilibili.com" && ( PageUrl.split("/")[3] == "video" || PageUrl.split("/")[3] == "s")){
        var str = PageUrl;
        if(GM_getValue('TinyMode').state == "true"){
            let cb = GetRedirect();
            top.location.href="https://player.bilibili.com/player.html?" + cb.type + "=" + cb.id + "&page=1&danmaku=0";
        } else {
            var nstr = str.replace("www.bilibili.com/video", "www.bilibili.com/s/video");
            if(nstr != str) top.location.href = nstr;
        }
    } else if(domain == "player.bilibili.com") {
        setTimeout(function() {
            document.getElementsByClassName("bilibili-player-video-sendjumpbar")[0].remove();
            document.getElementsByClassName("bilibili-player-video-pause-panel-container-qrcode")[0].remove();
            document.getElementsByTagName("title")[0].innerText = document.getElementsByClassName("bilibili-player-video-suspension-bar-title-text")[0].innerText + "_哔哩哔哩_bilibili";
        }, 3000);
    }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址