gdh1995 / vimium-c

A keyboard shortcut browser extension for keyboard-based navigation and tab operations with an advanced omnibar
https://chrome.google.com/webstore/detail/vimium-c/hfjbmagddngcpeloejdejnfgbamkjaeg
Other
3.41k stars 253 forks source link

Can we increase the volume of video more than %100 ? #1256

Open heissonly opened 1 week ago

heissonly commented 1 week ago

I want to increase the volume of the video to more than 100%. However, I'm not sure if this is possible with HTML5 video or what the correct JavaScript code would be. There is a thread below. Can we map the JavaScript code from the thread to a hotkey in Vimium?"

https://stackoverflow.com/questions/43794356/html5-volume-increase-past-100/43794379#43794379

I tried to implement below, even though it does work on youtube but not in some of the website. What could be the reason for that?

map openUrl url="javascript:if(!window.audioCtx||!window.gainNode){const\u0020a=document.querySelector('video');if(!a)return;window.audioCtx=new(AudioContext||webkitAudioContext)();const\u0020s=window.audioCtx.createMediaElementSource(a),g=window.audioCtx.createGain();s.connect(g);g.connect(window.audioCtx.destination);window.gainNode=g;}window.gainNode.gain.value=1.5;"

map openUrl url="javascript:if(window.gainNode){window.gainNode.gain.value=1.0;}"

heissonly commented 1 week ago

After some troubleshooting, I found a solution that works! Here’s the JavaScript code to incrementally increase the volume of HTML5 videos using Vimium key mappings. This could be added in a future update:

The code uses JavaScript to incrementally increase the volume of HTML5 videos through Vimium key mappings.

Code Details

  1. Initial Setup on <a-v> Press:

    map <a-v> openUrl url="javascript:if(!window.audioCtx||!window.gainNode){const\u0020a=document.querySelector('video');if(!a)return;window.audioCtx=new(AudioContext||webkitAudioContext)();const\u0020s=window.audioCtx.createMediaElementSource(a),g=window.audioCtx.createGain();s.connect(g);g.connect(window.audioCtx.destination);window.gainNode=g;}window.gainNode.gain.value+=1.0;"
    • Checks if audioCtx and gainNode exist; if not, it creates an AudioContext and a gainNode:
      • Connects the video’s audio to the gain node, and then routes the output to the destination.
    • Each <a-v> press then increments gainNode.gain.value by 1.0, increasing the volume by 100%.
  2. Volume Reset on <a-b> Press:

    map <a-b> openUrl url="javascript:if(window.gainNode){window.gainNode.gain.value=1.0;}"
    • Resets gainNode.gain.value to 1.0, returning the volume to 100%.

This setup allows each <a-v> press to boost volume incrementally, while <a-b> resets it.