Greasy Fork is available in English.

bilibilitools.js

bilibili

此脚本不应被直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://greasyfork.org/scripts/405933-bilibilitools-js/code/bilibilitoolsjs.js?version=841965

function addGlobalStyle(css) {
        var head, style;
        head = document.getElementsByTagName('head')[0];
        if (!head) { return; }
        style = document.createElement('style');
        style.type = 'text/css';
        style.innerHTML = css;
        head.appendChild(style);
    }

function videoxsyhnb() {
    var url = window.location.href;
    function createBtn(){
        addGlobalStyle('.a-link{text-decoration: none;color: white;}.a-link-div{padding:10px 20px;margin-bottom: 5px;background-color: #1E90FF;	}.btn-play{	background-color: #1E90FF;padding:10px;font-size: 18px;	height: fit-content;color: white;cursor: pointer;}.a-link-list{	padding-left: 5px;display: none;}.btn-play:hover + .a-link-list,.a-link-list:hover{display: block;}.a-link-div:hover{background-color: red;color:white;	} ');
        $('#videolinkparse').remove();
        var btn = `<div id="videolinkparse" style="position:fixed;z-index:999;top:20%;left:0;font-size:10px"><div style="display: flex;margin-bottom: 5px;"><div class="btn-play" >▶</div><div class="a-link-list"><a class="a-link" href="http://tv.wandhi.com/go.html?url=${url}" target='_blank'><div class="a-link-div">线路1</div></a><a class="a-link" href="https://z1.m1907.cn/?jx=${url}" target='_blank'><div class="a-link-div">线路2</div></a><a class="a-link" href="https://www.sounm.com/?url=${url}" target='_blank'><div class="a-link-div">线路3</div></a><a target='_blank' class="a-link" href="http://jx.598110.com/?url=${url}"><div class="a-link-div">线路4</div></a> <a target="_blank" class="a-link" style="width:40px;"><div class="a-link-div">解析失败,可前往在线影院搜索</div></a></div></div><a class="a-link" href="http://www.redbean.top" target='_blank' style='color:white'><div style="background-color: #1E90FF;color:#FFFFFF;padding:8px;width:20px;">在线影院</div></a></div>`
        if ($('#videolinkparse').length > 0) {} 
        else {
            $("body").append(btn);
        }
    }
    function checkurl(){
        if(location.href!=url){
            url = location.href;
            createBtn();
        }
        setTimeout(checkurl,500);
    }
    createBtn();
    checkurl();
    
}

function bilibili() {
    var localurl = location.href;
    var aid, cid

    function getvideourl() {
        var url, abtn;
        var data = __INITIAL_STATE__ || false;
        console.log(data)
        if (data) {
            if (data.p.length !== 0) {
                url = `https://xbeibeix.com/api/bilibili/biliplayer/?url=${data.bvid}?p=${data.p}`;
            } else {
                url = `https://xbeibeix.com/api/bilibili/biliplayer/?url=${data.bvid}`;
            }
            $('#dltext').remove();
            abtn = `<span id="dltext"><a style="background: red;color: white; padding: 5px;" target="_blank" href="${url}">解析链接</a></span>`;
            $('#download').append(abtn);
        } else {
            $('#dltext').remove();
            abtn = `<span id="dltext"><a style="background: red;color: white; padding: 5px;" target="_blank" href="javascript:void(0)">解析失败</a></span>`;
            $('#download').append(abtn);
        }
    }

    function addbtn() {
        $('#download').remove();
        //var ele1 = $('div.ops').children()[0].innerText;
        var isok = document.querySelectorAll('img.up-face').length;
        if (isok > 0) {
            $('div#arc_toolbar_report').before('<div id="download" style="padding:5px;">下載地址:<span id="dltext" style="color:red;">正在獲取下載地址</span></div>');
            getvideourl();

        } else {
            setTimeout(addbtn, 500)
        }
    }

    function addbagumi() {
        try {
            $('#download').remove();
            $('#download2').remove();
            var txt = $('.coin-info').children()[1].innerText;
            if (txt !== '--') {
                $('.media-wrapper').before('<div id="download" style="padding:5px;">下载地址:<span id="dltext" style="color:red;">暂不支持该类视频!</span></div>')
            } else {
                setTimeout(addbagumi, 500)
            }
        } catch (e) {}
    }

    function isbangumi() {
        if (localurl.search('bangumi') !== -1) {
            return true
        } else {
            return false
        }
    };

    function isvideo() {
        if (localurl.search('video') !== -1) {
            return true
        } else {
            return false
        }
    };
    if (isbangumi()) {
        addbagumi();
    }
    if (isvideo()) {
        addbtn();
    }

    function refresh() {
        if (localurl !== location.href) {
            localurl = location.href;
            if (isbangumi()) {
                addbagumi();
            }
            if (isvideo()) {
                addbtn();
            }
        }
    }
    setInterval(refresh, 500);
}

function adddlurl() {
    if (document.querySelectorAll('div#xibeidl').length == 0) {
        var url = document.querySelectorAll('iframe')[0].contentWindow.document.body.querySelector('video').src;
        var btn = `<div id="xibeidl" style="position:fixed;top:5%;"><a style="padding:5px 10px;background:red;color:white;text-decoration:none;" href="${url}" download>点击下载</a></div>`
        $('body').append(btn);
    } else {
        setTimeout(adddlurl, 500);
    }


}

function run() {
    var localurl = location.href;
    if (localurl.search('biliplayer') > 0) {
        adddlurl();
    } else if (localurl.search('www.bilibili.com') > 0) {
        bilibili();
        videoxsyhnb();
    }
}
run()