bili_optimizer

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

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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("已展开");
        }
    }
}
})();