Greasy Fork

Greasy Fork is available in English.

哔哩哔哩去除 6 分钟限制及 APP 下载

去除手机版 6 分钟限制,添加网页跳转

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

// ==UserScript==
// @name         哔哩哔哩去除 6 分钟限制及 APP 下载
// @namespace    http://tampermonkey.net/
// @version      0.6.0
// @description  去除手机版 6 分钟限制,添加网页跳转
// @author       sl00p
// @match        https://m.bilibili.com/video/*
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';
    function httpReq(url, callBack) {
        let xHttp = new XMLHttpRequest();
        xHttp.onreadystatechange = function () {
            if(this.readyState === 4 && this.status === 200) {
                callBack(xHttp.responseText);
            }
        };
        xHttp.open("Get", url, true);
        xHttp.send();
    }

    // inject wechat cookie
    (function injectCookie() {
        if(window.localStorage && window.localStorage.getItem("window.bsource") !== "wechat") {
            window.localStorage.setItem("window.bsource", "wechat");
        }
        if(document.cookie.indexOf("wechat") === -1) {
            document.cookie = "bsource=wechat";
        }
    })();

    setTimeout(function () {
        let url = document.location.href.split("/");
        let bVid = url[url.length - 1];
        let relateUrl = "https://api.bilibili.com/x/web-interface/archive/related?bvid=" + bVid;
        httpReq(relateUrl, function (res) {
            let data = JSON.parse(res).data;
            let tidMap = {};
            for(let i = 0; i < data.length; ++i) {
                if(tidMap.hasOwnProperty(data[i].tid)) {
                    tidMap[data[i].tid] += 1;
                } else {
                    tidMap[data[i].tid] = 1;
                }
            }
            // parse relate video path
            setInterval(function() {
                let nodes = document.getElementsByClassName("v-card-toapp");
                if (nodes !== undefined) {
                    for(let i = 0; i < nodes.length; ++i) {
                        nodes[i].getElementsByClassName('title')[0].innerHTML="<p><a href=\""
                            + data[i].bvid + "\" style=\"color:blue\">" + data[i].title + "</a></p>";
                    }
                }
            }, 1000);
            // parse owner name and remove app download tip
            setInterval(function() {
                let nodeList = ["m-video-openapp", "openapp", "m-video2-openapp", "m-video2-float-openapp", "m-related-openapp report-scroll-module"];
                let appList = ["v-card-toapp"];
                for(let i = 0; i < appList.length; ++i) {
                    let app = document.getElementsByClassName(appList[i]);
                    for(let j = 0; j < app.length; ++j) {
                        let ownerNameApp = app[j].getElementsByClassName('open-app');
                        if(ownerNameApp && ownerNameApp.length > 0) {
                            ownerNameApp[0].innerText = data[j].owner.name;
                        }
                    }
                    if (app && app.length > 0) {
                        app.onclick = function() { return false };
                        for(let k = 0; k < nodeList.length; ++k) {
                            if(document.getElementsByClassName(nodeList[k]).length > 0) {
                                document.getElementsByClassName(nodeList[k])[0].remove();
                            }
                        }
                    }
                }
            }, 1000);
            // parse end relate video
            setInterval(function() {
                let relateVideo = document.getElementsByClassName("player-ending-panel-title");
                let app = document.getElementsByClassName("player-ending-panel-button");
                if(relateVideo !== undefined && relateVideo.length > 0) {
                    for(let i = 0; i < data.length; ++i) {
                        if(relateVideo[0].textContent === data[i].title) {
                            relateVideo[0].innerHTML="<p><a href=\"" + data[i].bvid + "\" style=\"color:blue\">" + data[i].title + "</a></p>";
                            if(app !== undefined && app.length > 0) {
                                app[0].innerText = data[i].owner.name;
                            }
                        }
                    }
                }
            }, 500);
        })
    }, 1000);

})();