滚动音量Dx版

新增自定义修饰键微调音量功能。滚轮、013速度、28音量、46+-5sec、5(空白键)播放暂停、enter全萤幕切换、小键盘+-增减10%进度。完整支援:YouTube、B站、Steam。B站直播(局部)

< 脚本 滚动音量Dx版 的反馈

评价:好评 - 脚本运行良好

§
发布于:2025-08-24

由AI协助编码 我个人的想法
新增Ctrl 细调音量


// 原代码:
const DEFAULT_CONFIG = {
stepTime: 5,
stepTimeLong: 30,
stepVolume: 10,
key7Function: ['YOUTUBE', 'BILIBILI'].includes(PLATFORM) ? 4 : 1,
key9Function: ['YOUTUBE', 'BILIBILI'].includes(PLATFORM) ? 4 : 1
};

// 新代码:
const DEFAULT_CONFIG = {
stepTime: 5,
stepTimeLong: 30,
stepVolume: 10,
stepVolumeFine: 1, // 新增:微调步长,默认1%
key7Function: ['YOUTUBE', 'BILIBILI'].includes(PLATFORM) ? 4 : 1,
key9Function: ['YOUTUBE', 'BILIBILI'].includes(PLATFORM) ? 4 : 1
};


// 新增:設定微調音量步進
GM_registerMenuCommand("🎚️ 設定微調音量步進", () => {
const newVal = prompt("設定微調音量幅度 (%)", CONFIG.stepVolumeFine);
if (newVal && !isNaN(newVal)) {
CONFIG.stepVolumeFine = parseFloat(newVal);
saveConfig(CONFIG);
}
});


// 原代码:
function commonAdjustVolume(video, delta) {
if (delta < 0 && video.muted) {
video.muted = false;
}
const newVolume = Math.max(0, Math.min(100,
(video.volume * 100) +
(delta > 0 ? -CONFIG.stepVolume : CONFIG.stepVolume)
));
video.volume = newVolume / 100;
showVolume(newVolume);
return newVolume;
}

// 新代码:
function commonAdjustVolume(video, delta, step = CONFIG.stepVolume) {
if (delta < 0 && video.muted) {
video.muted = false;
}
const newVolume = Math.max(0, Math.min(100,
(video.volume * 100) +
(delta * step) // 使用传入的步长
));
video.volume = newVolume / 100;
showVolume(newVolume);
return newVolume;
}


// YouTube平台
adjustVolume: (video, delta, step = CONFIG.stepVolume) => {
// ... 使用 step 参数
}

// 其他平台(BILIBILI、TWITCH、STEAM、GENERIC)
adjustVolume: (video, delta, step = CONFIG.stepVolume) => commonAdjustVolume(video, delta, step),


// 原代码:
function handleVideoWheel(e) {
e.preventDefault();
e.stopPropagation();
const video = e.target;
PLATFORM_HANDLERS[PLATFORM].adjustVolume(video, e.deltaY);
}

// 新代码:
function handleVideoWheel(e) {
e.preventDefault();
e.stopPropagation();

const video = e.target;
const useFineAdjustment = e.ctrlKey; // 检测Ctrl键
const step = useFineAdjustment ? CONFIG.stepVolumeFine : CONFIG.stepVolume;
const delta = e.deltaY > 0 ? -1 : 1;

// ... 计算和设置音量
const mode = useFineAdjustment ? "微调" : "正常";
showVolume(newVolume, mode); // 显示模式信息
}


// 原代码:
PLATFORM_HANDLERS.TWITCH.adjustVolume(video, e.deltaY);

// 新代码:
const useFineAdjustment = e.ctrlKey;
const step = useFineAdjustment ? CONFIG.stepVolumeFine : CONFIG.stepVolume;
const delta = e.deltaY > 0 ? -1 : 1;
PLATFORM_HANDLERS.TWITCH.adjustVolume(video, delta, step);


// 原代码:
function showVolume(vol) {
display.textContent = `${Math.round(vol)}%`;
}

// 新代码:
function showVolume(vol, mode = "") {
const modeText = mode ? `[${mode}模式] ` : "";
display.textContent = `${modeText}${Math.round(vol)}%`;
}

xzy D作者
§
发布于:2025-08-26

當初考慮到用戶習慣所以添加了步進自定義,
如果真有人時常需要粗/細兩者兼具的的調整,那可能分貝上限高得可怕吧。

发布留言

登录(不可用)以发布留言。

QingJ © 2025

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