Boost Volume

Boost video volume on any site. Shortcuts: Alt-Shift-[+/-]

  1. // ==UserScript==
  2. // @name Boost Volume
  3. // @namespace http://greasyfork.org/
  4. // @version 0.3
  5. // @description Boost video volume on any site. Shortcuts: Alt-Shift-[+/-]
  6. // @author rix
  7. // @match *://*/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (() => {
  12. const boostVolume = (() => {
  13. const sources = {};
  14. const context = new AudioContext();
  15. return (gain) => {
  16. for (let video of document.querySelectorAll('video')) {
  17. try {
  18. const source = context.createMediaElementSource(video);
  19. const gainNode = context.createGain(source);
  20. source.connect(gainNode);
  21. gainNode.connect(context.destination);
  22. sources[video] = gainNode;
  23. } catch(e) {}
  24. }
  25. for (let [video, gainNode] of Object.entries(sources)) {
  26. try {
  27. gainNode.gain.value = gain;
  28. } catch(e) {}
  29. }
  30. };
  31. })();
  32. let gain = 1;
  33. document.body.addEventListener('keyup', e => {
  34. if (!(e instanceof KeyboardEvent && e.type === 'keyup')) return;
  35. if (e.composed && e.altKey && !e.ctrlKey && !e.metaKey && e.shiftKey) {
  36. if (e.keyCode === 187) { // +
  37. gain++;
  38. }
  39. else if (e.keyCode === 189) { // -
  40. gain = Math.max(gain - 1, 1);
  41. }
  42. else return;
  43. boostVolume(gain);
  44. }
  45. });
  46. })();