shumin-Bilibili

视频结束时自动关全屏,添加获取视频封面按钮,修改为彩虹进度条,缩窄顶栏,简化动态页,不显示视频页面的弹幕盒子、广告等右栏杂物,直接显示推荐视频。

目前為 2024-09-08 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name            shumin-Bilibili
// @namespace       https://www.tampermonkey.net/
// @version         1.6.0
// @description     视频结束时自动关全屏,添加获取视频封面按钮,修改为彩虹进度条,缩窄顶栏,简化动态页,不显示视频页面的弹幕盒子、广告等右栏杂物,直接显示推荐视频。
// @author          庶民player
// @license         MIT
// @match           *.bilibili.com/*
// @icon            https://static.hdslb.com/images/favicon.ico
// @require         https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
// @grant           none
// @run-at          document-idle
// ==/UserScript==
 
 
 
function go_dn(elem_name){
    for(
        let cur_li = $(elem_name) , next_li = cur_li.next();
        next_li.length > 0;
        next_li = cur_li.next()
    ){
        next_li.after(cur_li);
    }
}
function thin_top(){
    let set_h = 42

    function thin_topbar(){
        $(".bili-header.fixed-header")[0].style.cssText += 'height: '+set_h+'px !important; min-height: '+set_h+'px !important;';
        $(".bili-header__bar.mini-header")[0].style.cssText += 'height: '+set_h+'px !important; min-height: '+set_h+'px !important;';

        $(".bili-header__bar.mini-header").css({
            "padding-left": "7px",
            "padding-right": "0px",
        });
    }

    thin_topbar();
    const observer = new MutationObserver(() => {
        $("#biliMainHeader")[0].style.cssText += 'height: '+ set_h +'px !important; min-height: '+set_h+'px !important; top: '+( (set_h-64)/2 )+'px !important;';

        thin_topbar();
    });
    observer.observe(document.body, { childList: true, subtree: true });// 开始观察特定的DOM节点
}
 
 
$(document).ready(function () {
     thin_top();
 
 
//-=-=-=-=-=-=-=-=-=-=-=-=-t.bili-=-=-=-=-=-=-=-=-=-=-=-
    
    if (window.location.href.indexOf("t.bilibili.com") >= 0 ){
 
        if(window.location.href.indexOf("tab=video") < 0)
            $(".bili-dyn-list-tabs__item:nth-child(2)").click();
        //window.location.href = "https://t.bilibili.com/?tab=video";
 
        $(".right").hide();
        $(".left").hide();
 
        $(".bili-backtop").css({
            "right": "0px",
            "bottom": "300px",
        });
 
        $(document.body).css({'overflow-x':'hidden'});
        //$(".left-entry").remove();
        //$(".offset-center-search").remove();
 
        return;
    }
 
//-=-=-=-=-=-=-=-=-=-=-=-=-自动关全屏-=-=-=-=-=-=-=-=-=-=-=-
 
    if (window.location.href.indexOf("bilibili.com/video/") >= 0 ){
        let cycle_id = setInterval(() => {
            if(
                $(".bpx-player-ending").is(":visible") ||
                $(".bpx-player-electric-box").is(":visible") ||
                false
            ) {
                document.webkitCancelFullScreen();
                document.exitFullscreen();
                document.cancelFullScreen();
            }
        }, 1000);
    }
 
//-=-=-=-=-=-=-=-=-=-=-=-=-下移-=-=-=-=-=-=-=-=-=-=-=-
    
    window.onload = function(){
        setTimeout(
            () => {
                go_dn('.video-card-ad-small');
                go_dn('.video-page-game-card-small');
                go_dn('#paybar_module');
                go_dn('#danmukuBox');
 
                if (window.location.href.indexOf("bilibili.com/video/") >= 0 )
                    window.history.replaceState( null, null, window.location.pathname);
            },
            5000
        )
    }
 
//-=-=-=-=-=-=-=-=-=-=-=-=-=-彩虹条=-=-=-=-=-=-=-=-=-=-=-=-=
    var css = `
    /* 进度条样式 */
    .bpx-player-progress-schedule-current {
        background: linear-gradient(
            to left,
            #FF0000 0%,
            #FF7F00 16.5%,
            #FFFF00 33%,
            #00FF00 50%,
            #0000FF 66%,
            #4B0082 83.5%,
            #9400D3 100%
        ) !important;
    }
    /* 缓冲条样式*/
    .bpx-player-progress-schedule-buffer {
        background: repeating-linear-gradient(
            45deg,
            #888888 0,
            #888888 20px,
            #000000 20px,
            #000000 40px
        );
        background-size: 200% 200%;
        animation: barberPole 10s linear infinite;
    }
    @keyframes barberPole {
        0% { background-position: 0% 0%; }
        100% { background-position: 100% 100%; }
    }
    `;
    if (typeof GM_addStyle != "undefined") {
        GM_addStyle(css);
    } else if (typeof PRO_addStyle != "undefined") {
        PRO_addStyle(css);
    } else if (typeof addStyle != "undefined") {
        addStyle(css);
    } else {
        var node = document.createElement("style");
        node.type = "text/css";
        node.appendChild(document.createTextNode(css));
        var heads = document.getElementsByTagName("head");
        if (heads.length > 0) {
            heads[0].appendChild(node);
	} else {
		// no head yet, stick it whereever
		document.documentElement.appendChild(node);
	}
}

//-=-=-=-=-=-=-=-=-=-=-=-=封面-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
    if (window.location.href.indexOf("bilibili.com/video/") < 0 ) return;
    const openInNew = true; //是否在新标签页中打开图片地址
    const item = document.createElement('item');
    item.id = 'SIR';
    item.innerHTML = `
        <button class="SIR-button">获取封面</button>
    `;
    document.body.append(item)
 
    const style = document.createElement('style');
 
    var ss = `
      #SIR * {
          box-sizing: border-box;
          padding: 0;
          margin: 0;
      }
      #SIR .SIR-button {
          cursor: pointer;
          display: inline-block;
          height: 26px;
          margin-right: 10px;
          border: solid 1px ;
          border-radius: 3px;
          font-size: 13px;
          padding:0 5px;
          z-index: 5;
          opacity: 0.5;
          position:absolute;
    `;/*
 
          color: #FB7299;
          background: #66CCFF;
    */
 
    style.innerHTML = ss
        +"top:"
        +($('#arc_toolbar_report').offset().top + $('#arc_toolbar_report').height()*-0.2)//17
        +"px; left:"
        +($('#arc_toolbar_report').offset().left + $('#arc_toolbar_report').width()*0.58)
        +"px;}";
    const button = item.querySelector('.SIR-button')
    button.onclick = () => {
        if(openInNew) {
        window.open(getUrl());
        } else {
        self.location = getUrl();
        }
    }
    document.head.append(style)
 
    function getUrl() {
        // 获取当前视频的 BV 号
        var source_url = window.location.href;
        var video_BV = /https:\/\/www\.bilibili\.com\/video\/(BV\w+)/i;

        var match = source_url.match(video_BV);
        if (!match) {
            console.error("无法获取BV号");
            return;
        }

        var bvid = match[1]; // 提取 BV 号
        var api_url = `https://api.bilibili.com/x/web-interface/view?bvid=${bvid}`;

        // 创建 XMLHttpRequest 对象并发送 API 请求
        var xhr = new XMLHttpRequest();
        xhr.open('GET', api_url, false);
        xhr.send();

        // 解析 API 响应
        if (xhr.status === 200) {
            var response = JSON.parse(xhr.responseText);

            // 检查响应中是否包含封面地址
            if (response.code === 0 && response.data && response.data.pic) {
                return response.data.pic; // 返回封面图片地址
            } else {
                console.error("未能获取封面信息");
                return;
            }
        } else {
            console.error("请求失败,状态码: " + xhr.status);
            return;
        }
    }



});