Youtube Scroll Volume

Use the scroll wheel to adjust volume of youtube videos

目前為 2018-12-31 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Youtube Scroll Volume
  3. // @namespace https://greasyfork.org/users/649
  4. // @version 1.0.0
  5. // @description Use the scroll wheel to adjust volume of youtube videos
  6. // @author Adrien Pyke
  7. // @match *://www.youtube.com/*
  8. // @grant GM_getValue
  9. // @grant GM_setValue
  10. // @grant GM_registerMenuCommand
  11. // @require https://gitcdn.link/repo/kufii/My-UserScripts/fa4555701cf5a22eae44f06d9848df6966788fa8/libs/gm_config.js
  12. // @require https://gitcdn.link/repo/fuzetsu/userscripts/b38eabf72c20fa3cf7da84ecd2cefe0d4a2116be/wait-for-elements/wait-for-elements.js
  13. // ==/UserScript==
  14.  
  15. (() => {
  16. 'use strict';
  17.  
  18. const Config = GM_config([
  19. { key: 'reverse', label: 'Reverse Scroll', default: false, type: 'bool' },
  20. { key: 'step', label: 'Change By', default: 5, type: 'number', min: 1, max: 100 }
  21. ]);
  22. GM_registerMenuCommand('Youtube Scroll Volume Settings', Config.setup);
  23.  
  24. waitForElems({
  25. sel: 'ytd-player',
  26. onmatch(node) {
  27. node.onwheel = e => {
  28. const player = node.getPlayer();
  29. const config = Config.load();
  30. const dir = (e.deltaY > 0 ? -1 : 1) * (config.reverse ? -1 : 1);
  31.  
  32. const vol = player.getVolume() + (config.step * dir);
  33. player.setVolume(vol);
  34. if (vol > 0) player.unMute();
  35.  
  36. e.preventDefault();
  37. e.stopImmediatePropagation();
  38. };
  39. }
  40. });
  41. })();