Bilibili 干净链接

去除bilibili链接中不需要的参数,如spm_id_from/from_sourse/from/等,还地址栏以清白干净

目前為 2020-05-20 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Bilibili 干净链接
// @namespace    Motoori Kashin
// @version      1.2.1
// @description  去除bilibili链接中不需要的参数,如spm_id_from/from_sourse/from/等,还地址栏以清白干净
// @author       Motoori Kashin
// @match        *://*.bilibili.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // 参数可自行添加
    let word = ["spm_id_from","from_source","msource","bsource","seid","from","source","session_id"];
    let url = [];

    let handle = {
        relink(link) {
            let last = link.split('?');
            let search = [];
            if (last[1]) {
                let dot = "";
                if (last[1].match("#")) {
                    dot = last[1].split('#')[1];
                    last[1] = last[1].split('#')[0];
                }
                search = last[1].split('&');
                for (let i=0;i<search.length;i++){
                    let key = search[i].split('=');
                    if (word.includes(key[0])) search[i] = "";
                }
                search = search.filter((e) => {return e});
                last[1] = search.join("&");
                last = last.filter((e) => {return e});
                link = last.join("?");
                if (dot) link = link + "#" + dot;
            }
            return link;
        },
        link(){
            let links = document.getElementsByTagName("a");
            url[1] = window.location.href;
            if (url[0] != url[1]) {
                window.history.replaceState(null,null,handle.relink(url[1]));
            }
            for (let i=0;i<links.length;i++){
                if (links[i].href) links[i].href = handle.relink(links[i].href);
            }
        }
    }
    url[0] = window.location.href;
    window.history.replaceState(null,null,handle.relink(url[0]));
    setTimeout(()=>{window.onclick = () => {handle.link()}},1000)
})();

QingJ © 2025

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