VK Volume Scroll

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

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         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 });
})();