bili_optimizer

1.自动展开视频简介 2.点击宽屏模式自动将播放器和页面下边沿对齐

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         bili_optimizer
// @namespace    http://tampermonkey.net/
// @version      2024-12-05
// @description  1.自动展开视频简介 2.点击宽屏模式自动将播放器和页面下边沿对齐
// @author       Han Shuwang
// @match        https://www.bilibili.com/video/*
// @match        https://www.bilibili.com/list/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @license      MIT
// ==/UserScript==
// 添加WEBHOOK
(function() {
    'use strict';

    // Your code here...
    setTimeout(() => {
        // 获取播放器容器元素
        const playerContainer = document.getElementById('bilibili-player');

        // 获取目标按钮
        const targetButton = document.querySelector('.bpx-player-ctrl-btn.bpx-player-ctrl-wide');

        if (playerContainer && targetButton) {
            targetButton.addEventListener('click', () => {
                // console.log("点击了宽屏模式");
                // 获取播放器容器的位置和尺寸
                let rect = playerContainer.getBoundingClientRect();

                // 获取浏览器窗口的高度
                let viewportHeight = window.innerHeight;

                // 检查播放器下边沿是否在浏览器下边沿之上
                if (rect.bottom > viewportHeight) {
                    // 计算需要滚动的偏移量
                    const offset = rect.bottom - viewportHeight;

                    // 使用 smooth 滚动到目标位置
                    window.scrollBy({
                        top: offset,
                        behavior: 'smooth'
                    });
                    console.log("已对齐");
                }
            });
        }
        unfold_discription();

    }, 4000);//延时4秒,可自己修改,单位ms

function unfold_discription(){
    var unfold_flag = 0;
    let desciption_unfold = document.getElementsByClassName('toggle-btn');
    if(desciption_unfold&&unfold_flag==0){
        if(desciption_unfold[0].textContent == '展开更多')
        {
            desciption_unfold[0].click();
            unfold_flag = 1;
            console.log("已展开");
        }
    }
}
})();