B-HTML5-Live

Fork from https://greasyfork.org/users/24167

当前为 2022-01-10 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        B-HTML5-Live
// @version     0.9.5
// @description Fork from https://greasyfork.org/users/24167
// @author      esterTion-28135
// @match      https://live.bilibili.com/blanc/*
// @match      https://live.bilibili.com/*
// @exclude    https://live.bilibili.com/
// @exclude    https://live.bilibili.com/*/*
// @exclude    https://live.bilibili.com/h5/*
// @run-at      document-idle
// @connect   bilibili.com
// @grant       unsafeWindow
// @license     no-license
// @grant       GM_xmlhttpRequest
// @namespace https://greasyfork.org/zh-CN/users/135090
// ==/UserScript==
setTimeout(function(){
    var room_id=(typeof __NEPTUNE_IS_MY_WAIFU__ == "undefined")?unsafeWindow.__statisObserverConfig.pvConfig.selfDefMsg.room_id:unsafeWindow.__NEPTUNE_IS_MY_WAIFU__.baseInfoRes.data.room_id;
    var infobar=document.querySelector(".room-info-ctnr.dp-i-block");
    var jsontag =document.createElement("a");
    var jsonlink="https://api.live.bilibili.com/room/v1/Room/playUrl?platform=h5&otype=json&quality=4&cid="+room_id;
    var response;
    GM_xmlhttpRequest({
        url: jsonlink,
        method: "GET",
        onload: function(res) {
            console.info('BilibiliHLS', 'NetworkResponse', res, JSON.parse(res.response));
            try {
                response = JSON.parse(res.responseText);
            } catch (e) {
                response = false;
            }
            var data=false;
            if (response){
                data = response.data;
            }else{
                console.log("data false");
            }
            if (data) {
                jsontag.href=data.durl[0].url;
            } else {
                jsontag.href=jsonlink;
                console.log("get false");
            }
        }
    });
    jsontag.style.display.margin="2px 2px";
    jsontag.innerText=document.title;
    jsontag.target="_self";
    infobar.insertBefore(jsontag,infobar.lastChild);
},1000);
var sidead = document.querySelector("#sections-vm");
var imgnode = document.createElement("span");
imgnode.setAttribute("id", "user_cover");
imgnode.setAttribute("style", "display:block;margin:2px auto;");
if (typeof __NEPTUNE_IS_MY_WAIFU__ =="undefined"){
    var apiurl="https://api.live.bilibili.com/room/v1/Room/get_info?device=phone&platform=ios&scale=3&build=10000&room_id=";
    var sn=location.pathname.lastIndexOf("/")+1;
    var roomid=location.pathname.substring(sn);
    var webapi = apiurl + roomid;
    var response;
    GM_xmlhttpRequest({
        url: webapi,
        method: "GET",
        onload: function(res) {
            console.info('BilibiliCover', 'NetworkResponse', res, JSON.parse(res.response));
            try {
                response = JSON.parse(res.responseText);
            } catch (e) {
                response = false;
            }
            var data;
            if (response){
                data = response.data;
            }else{
                data =false;
                console.log("data false");
            }
            if (data) {
                var cover = data.user_cover;
                var i=cover.indexOf(":")+1;
                cover=cover.substring(i);
                var coverhtml= "<hr /><a href=\""+cover+"\" target=_blank >查看封面</a><hr />";
                imgnode.innerHTML=coverhtml;
                sidead.insertBefore(imgnode,sidead.firstChild);
            } else {
                console.log("get false");
            }
        }
    });
} else {
    var data=unsafeWindow.__NEPTUNE_IS_MY_WAIFU__.baseInfoRes.data;
    if (data){
        var cover = data.user_cover;
        var i=cover.indexOf(":")+1;
        cover=cover.substring(i);
        var coverhtml= "<hr /><a href=\""+cover+"\" target=_blank >查看封面</a><hr />";
        imgnode.innerHTML=coverhtml;
        sidead.insertBefore(imgnode,sidead.firstChild);
    } else {
        console.log("get false");
    }
}