VK Volume Scroll

Shift + Scroll изменяет громкость плеера

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         VK Volume Scroll
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Shift + Scroll изменяет громкость плеера
// @author       wilovan
// @match        https://vk.com/*
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
  'use strict';

  function linearToVkVolume(linear) {
    return Math.pow(linear, 2.2);
  }

  function vkVolumeToLinear(vkVol) {
    return Math.pow(vkVol, 1 / 2.2);
  }

  let volumeLinear = 0;

  setTimeout(() => {
    try {
      const vkVol = getAudioPlayer()._userVolume ?? 0;
      volumeLinear = vkVolumeToLinear(vkVol);
      console.log('Начальная линейная громкость:', volumeLinear.toFixed(2));
    } catch {
      volumeLinear = 0;
      console.warn('Не удалось получить громкость, ставим 0');
    }
  }, 2000);

  document.addEventListener('wheel', function (e) {
    if (!e.shiftKey) return;

    const delta = e.deltaY < 0 ? 0.01 : -0.01; //0.01 шаг громкости - 1%
    volumeLinear = Math.min(1, Math.max(0, volumeLinear + delta));

    const vkVolToSet = linearToVkVolume(volumeLinear);

    try {
      getAudioPlayer().setVolume(vkVolToSet);
      console.log(`🔊 Громкость: ${volumeLinear.toFixed(2)} (VK: ${vkVolToSet.toFixed(3)})`);
    } catch (err) {
      console.error('❌ Ошибка при вызове getAudioPlayer().setVolume()', err);
    }

    e.preventDefault();
  }, { passive: false });
})();