Greasy Fork is available in English.
使用方向键↑↓以5%步进调节Bilibili音量,支持全屏并在屏幕中央显示提示框。
// ==UserScript==
// @name Bilibili 音量调节步进修改(AI生成)(5% + 居中提示 + 全屏支持)
// @name:en Bilibili Volume Step Modifier (5% + Centered Indicator + Fullscreen Support)
// @namespace https://bilibili.com/
// @version 1.3.1
// @description 使用方向键↑↓以5%步进调节Bilibili音量,支持全屏并在屏幕中央显示提示框。
// @description:en Adjust Bilibili video volume in 5% steps using ↑↓ keys, with centered on-screen display and fullscreen support.
// @author chuangzaoh666
// @license MIT
// @match *://www.bilibili.com/video/*
// @match *://bilibili.tv/video/*
// @grant none
// @homepageURL http://greasyfork.icu/scripts/553208
// @supportURL http://greasyfork.icu/users/1528875
// @icon https://static.hdslb.com/images/favicon.ico
// @source Script created with assistance from ChatGPT (GPT-5)
// ==/UserScript==
(function () {
'use strict';
function waitForVideo(callback) {
const timer = setInterval(() => {
const video = document.querySelector('video');
if (video) {
clearInterval(timer);
callback(video);
}
}, 500);
}
waitForVideo((video) => {
console.log('[音量步进修改脚本] 已加载');
// 创建中心提示元素
const hint = document.createElement('div');
hint.style.cssText = `
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) scale(1);
background: rgba(0, 0, 0, 0.65);
color: #fff;
padding: 20px 30px;
border-radius: 16px;
font-size: 20px;
font-weight: bold;
text-align: center;
z-index: 999999;
opacity: 0;
transition: opacity 0.25s ease, transform 0.25s ease;
pointer-events: none;
backdrop-filter: blur(4px);
font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
`;
// 查找播放器容器
function getPlayerContainer() {
return (
document.querySelector('.bpx-player-container') ||
document.querySelector('.bilibili-player') ||
document.body
);
}
let container = getPlayerContainer();
container.appendChild(hint);
// 监听DOM变化(切换全屏时自动跟随)
const observer = new MutationObserver(() => {
const newContainer = getPlayerContainer();
if (newContainer !== container) {
container = newContainer;
if (!hint.isConnected) container.appendChild(hint);
}
});
observer.observe(document.body, { childList: true, subtree: true });
// 提示动画
let hideTimer = null;
function showVolumeHint(vol) {
hint.textContent = `音量:${Math.round(vol * 100)}%`;
hint.style.opacity = 1;
hint.style.transform = 'translate(-50%, -50%) scale(1.05)';
clearTimeout(hideTimer);
hideTimer = setTimeout(() => {
hint.style.opacity = 0;
hint.style.transform = 'translate(-50%, -50%) scale(1)';
}, 800);
}
// 键盘控制
document.addEventListener(
'keydown',
(e) => {
const active = document.activeElement;
if (
active &&
(active.tagName === 'INPUT' ||
active.tagName === 'TEXTAREA' ||
active.isContentEditable)
)
return;
if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
e.stopImmediatePropagation();
e.preventDefault();
let delta = 0.05;
if (e.key === 'ArrowDown') delta = -delta;
video.volume = Math.min(1, Math.max(0, video.volume + delta));
showVolumeHint(video.volume);
}
},
true
);
});
})();