B站大会员影视+弹幕

解除B站大会员观影限制

目前为 2021-07-03 提交的版本,查看 最新版本

// ==UserScript==
// @name         B站大会员影视+弹幕
// @namespace    http://tampermonkey.net/
// @version      1.4
// @description  解除B站大会员观影限制
// @author       Polygon
// @match        https://www.cuan.la/m3u8.php*
// @match        https://vip.parwix.com/*
// @require      https://gf.qytechs.cn/scripts/407985-ajax-hook/code/Ajax-hook.js?version=940269
// @grant        GM_xmlhttpRequest
// @grant        unsafeWindow
// @include      https://www.bilibili.com/bangumi/play/*
// @include      https://www.bilibili.com/video/BV*
// @connect      *
// @run-at       document-end
// ==/UserScript==
;
(function () {
    'use strict'
    const origin = [{ regex: 'dmku', api: 'https://vip.parwix.com:4433/player/?url=' },
    { regex: 'barrage', api: 'https://www.cuan.la/m3u8.php?url=' }]
    const which = 1
    async function get_danmu(url) {
        let res, restxt, cid, api
        var danmu = { code: 23, msg: "success", dannum: 0, danmuku: [], name: "" }
        res = await fetch(url, { method: 'GET', mode: 'cors' })
        restxt = await res.text()
        cid = /cid.:(\d{8,9}),/g.exec(restxt)[1]
        api = `https://api.bilibili.com/x/v1/dm/list.so?oid=${cid}`
        res = await fetch(api, { method: 'GET', mode: 'cors' })
        restxt = await res.text()
        let matchObj = restxt.match(/<d p=".+?">.+?<\/d>/g)
        matchObj.forEach(ele => {
            let r = /<d p="(.+?)">(.+?)<\/d>/g.exec(ele)
            let params = r[1].split(',')
            let content = r[2]
            let time = params[0]
            let direction = parseInt(params[1])
            let fontsize = params[2]
            let color = '#' + parseInt(params[3]).toString(16)
            let direction_info
            if (direction <= 3) {
                direction_info = 'right'
            } else if (direction == 4) {
                direction_info = 'bottom'
            } else if (direction == 5) {
                direction_info = 'top'
            } else {
                direction_info = 'right'
            }
            danmu.danmuku.push([time, direction_info, color, "", content, "", "", `${fontsize}px`])
        })
        danmu.dannum = danmu.danmuku.length
        danmu.danmuku.push([0, 'bottom', '#FF616D', "", `替换弹幕源成功,前方共有${danmu.danmuku.length}条弹幕,请做好准备哟`, "", "", `30px`])
        return danmu
        }
    // 替换弹幕
    ah.proxy({
        onRequest: (config, handler) => {
            if (config.url.search(origin[which].regex) !== -1) {
                let bili_url = /https:\/\/www.bilibili.com.+/g.exec(document.URL)[0]
                get_danmu(bili_url).then(danmu => {
                    handler.resolve({
                        config: config,
                        status: 200,
                        headers: { 'content-type': 'text/text' },
                        response: JSON.stringify(danmu)
                    })
                })
            } else handler.next(config);
        }
    })
    // 解析视频替换iframe
    let bangumi = /bilibili.com\/bangumi\/play\//g.test(window.location.href)
    let parentId = bangumi ? 'toolbar_module' : 'arc_toolbar_report'
    //添加样式
    let style = document.createElement("style")
    style.innerHTML = (".coldrainf-get-dm{float:right;}.coldrainf-get-dm>div{display:inline-block;}.coldrainf-get-dm a{font-size:15px;color:#00a1d6;margin:0 12px;line-height:28px;}.coldrainf-get-dm a:hover{cursor:pointer;color:#f25d8e;}")
    document.head.appendChild(style)
    let addElement = cid => {
        // 防止匹配到解析网址,控制台会输出错误
        if (!document.URL.startsWith('https://www.bilibili.com/')) return
        let parent = document.getElementById(parentId)
        let old = document.querySelector('.coldrainf-get-dm')
        if (old) parent.removeChild(old)
        let ele = document.querySelector('#toolbar_module')
        let iframeTmp = document.querySelector('#coldrainf-iframe')
        if (iframeTmp) document.querySelector('.plp-l').removeChild(iframeTmp)
        let bfq = document.getElementById('player_module')
        if (bfq) bfq.style.display = 'block'
        // 创建新源
        console.log(bfq)
        let iframeDiv = bfq.cloneNode(true)
        // 避免右偏
        iframeDiv.style['padding-left'] = '0px'
        iframeDiv.style.display = 'none'
        iframeDiv.innerHTML = ""
        let iframe = document.createElement("iframe")
        iframe.id = 'coldrainf-iframe'
        iframe.style.height = bfq.style.height
        iframeDiv.append(iframe)
        let read_url = document.querySelector('meta[property="og:url"]').content
        iframe.src = origin[which].api + read_url
        console.log(iframe.src)
        if (document.body.className.includes('player-mode-widescreen')) {
            iframe.style.position = 'absolute'
            iframe.style.top = '0px'
        }
        iframe.height = '0%'
        iframe.width = '100%'
        iframe.setAttribute('frameborder', 'no')
        iframe.setAttribute('border', '0')
        iframe.setAttribute('allowfullscreen', 'allowfullscreen')
        iframe.setAttribute('webkitallowfullscreen', 'webkitallowfullscreen')
        document.querySelector('.plp-l').insertBefore(iframeDiv, document.querySelector('.media-wrapper'))
        // 切换按钮
        let switchButton = document.createElement("div")
        switchButton.setAttribute('class', 'share-info')
        switchButton.setAttribute('id', 'switch')
        switchButton.innerHTML = '<i class="iconfont"></i><span style="background-color: #FB7299; border: 1px solid #FB7299; color: #fff; border-radius: 16px; text-align: center;">切换</span> <!---->'
        ele.appendChild(switchButton)
        switchButton.addEventListener('click', function () {
            let players = document.querySelectorAll('#player_module')
            let biliEle = players[0]
            let switchEle = players[1]
            if (biliEle.style.display !== 'none') {
                // 切换前状态,点击切换
                switchButton.querySelector('span').style['background-color'] = '#a62aee'
                switchButton.querySelector('span').style['border-color'] = '#a62aee'
                if (window.player) { window.player.pause() }
                biliEle.style.display = 'none'
                switchEle.style.display = 'block'
                if (document.querySelector('#bofang')) { document.querySelector('#bofang').click() }
            } else {
                // 切换后状态,点击恢复原始
                switchButton.querySelector('span').style['background-color'] = '#fb7299'
                switchButton.querySelector('span').style['border-color'] = '#fb7299'
                biliEle.style.display = 'block'
                if (window.player) { window.player.play(); console.log('播放原始') }
                if (document.querySelector('#bofang')) { document.querySelector('#bofang').click() }
                switchEle.style.display = 'none'
            }
        })
        $(switchButton).hover(function () {
            switchButton.querySelector('span').style['background-color'] = '#505050'
            switchButton.querySelector('span').style['border-color'] = '#505050'
        }, function () {
            let biliEle = document.querySelectorAll('#player_module')[0]
            if (biliEle.style.display !== 'none') {
                switchButton.querySelector('span').style['background-color'] = '#fb7299'
                switchButton.querySelector('span').style['border-color'] = '#fb7299'
            } else {
                switchButton.querySelector('span').style['background-color'] = '#a62aee'
                switchButton.querySelector('span').style['border-color'] = '#a62aee'
            }
        })
    }
    let init = () => {
        addElement(cid)
    }
    let obs = bangumi ? document.querySelector('#toolbar_module') : document.querySelector('.ops')
    if (!obs) setTimeout(init, 600)
    else {
        new MutationObserver(function (mutations, observer) {
            observer.disconnect();
            setTimeout(init, 600)
        }).observe(obs, { childList: true, subtree: true });
    }
})()



QingJ © 2025

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