BilibiliPotPlayer

用 PotPlayer 打开 Bilibili 链接进行播放

// ==UserScript==
// @name         BilibiliPotPlayer
// @icon         https://www.bilibili.com/favicon.ico?v=1
// @namespace    https://github.com/chen310
// @version      1.0.3
// @description  用 PotPlayer 打开 Bilibili 链接进行播放
// @author       chen310
// @match        https://www.bilibili.com/*
// @match        https://space.bilibili.com/*
// @match        https://live.bilibili.com/*
// @match        https://link.bilibili.com/*
// @match        https://search.bilibili.com/*
// @match        https://t.bilibili.com/*
// @grant        none
// ==/UserScript==

// 需要配合 PotPlayer 插件 https://github.com/chen310/BilibiliPotPlayer 进行使用

(function () {
    "use strict";

    if (window.location.href.indexOf("live.bilibili.com/blanc") != -1) {
        return;
    }

    const protocol = "potplayer";
    const img = document.createElement("img");
    img.id = "btnPotplayer"
    img.src = 'data:image/webp;base64,UklGRm4PAABXRUJQVlA4WAoAAAAQAAAA/wAA/wAAQUxQSJMGAAABoIZs2+pG4uVwOIRQwuCWWQ3jMwyl6+7j7jMopWsllDFKGQ2Dl7K+Jay7bxkp6zLGSiglhJEQQimlZK2EUkI4HN4f8XO+731+LUTEBJBuzeC9G1qOvdV1IZ76eyjLRYeGBlO9P30VjTSvuXMi4Tr24ede+SZpc83zV8+0N947CozxyyLnBtjl6a/angxgMK3xvRR79mp0S1B2gVXRfvZ88qVFfqHNav3FZkXmvmm5RVzT9idYsb/tCgrqptYeVvKl8HgRmau6HVa2/dmThnRCJzKs+PT+yZJ5+Bzr0P6oXijmlhhr86dlhjx8u/pZq9d3WrKwwoOs3XSTJQerqZ+1nN5qCGFDmrWdWCCBO6+w1rtn6W7iGw5r3n5hlM7MfcMswL+b9NXQw0K8ME1P/lM2izG339TQoykWZfxO3VgdLE07YmplVi8LNDZDI8/lWKQj23Ux+gyL9YM6LTT0sWCvztJAU55FO7xOdVYni/eEobSxF1jA5+oUNiPFIo7fpKyHh1jImQZFrcuzmIcXKKmZJW1vUdBBFnZYOe0s7jbFvMICP6qUThb5CYW8xEKPKKOdxX5QE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j4COXIKMwY8xmtnApMChFUwyeA4Aq/MDGGOAATH7E+QCosFyX+vdjQ21aEw8SL/dNBP2bs1ViCDlHgHeyHNpNsx/6Y20VRGcuig+5SX/tTujpXuUbRRuOVzUNHhsQoDfeLbapfeHyU2nNI24pAMdmTeLWbg2Qw7CuTisQBfbRaktTLH/KrJEmWDQpo+vlFhjOobNAxiQA97a48qslkUbl9KUA48i7HlZ9KSnW1Rosz2yz0Qac44kuYRL4xHAyltJbUehVrGL0pA3KpWnaOOOgyR3qfbXZeRWfJAhFfEV0CR4EH50JhxQAAAA==';

    img.style.width = "50px";
    img.style.height = "50px";
    img.style.position = "fixed";
    img.style.cursor = "pointer";
    img.style.right = "30px";
    img.style.bottom = "70px";
    img.style.zIndex = "9999";

    img.onclick = function () {
        let url = window.location.href;
        if (url.indexOf("space.bilibili.com") != -1) {
            if (url.indexOf("/video") != -1 || url.indexOf("/audio") != -1) {
                let order = document.querySelector('.is-active input')?.value || "";
                if (url.search("order=") != -1) {
                    url = url.replace(/order=([a-zA-Z]+)/, "order=" + order);
                } else {
                    if (url.indexOf("?") != -1) {
                        url += "&order=" + order;
                    } else {
                        url += "?order=" + order;
                    }
                }
            }
        }
        url = protocol + "://" + url;
        window.open(url, "_self");
    }

    document.body.appendChild(img)

    function getparameter(s) {
        var p = window.location.href.split("?"+s+"=");
        if (p.length >= 2) {
            p = p[1].split("&")[0];
        } else {
            p = window.location.href.split("&"+s+"=");
            if (p.length >= 2) {
                p = p[1].split("&")[0];
            } else {
                p = "";
            }
        }
        return p;
    }
})();