Youtube Scroll Volume

Hold Right-Click and Scroll to Adjust Volume on Youtube. (MADE WITH CHATGPT)

  1. // ==UserScript==
  2. // @name Youtube Scroll Volume
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Hold Right-Click and Scroll to Adjust Volume on Youtube. (MADE WITH CHATGPT)
  6. // @author YIKIKRULES (or ChatGPT)
  7. // @match *://www.youtube.com/*
  8. // @license MIT
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. let rightClickHeld = false;
  16. let volumeTimeout;
  17.  
  18. // Function to adjust volume on mouse wheel scroll
  19. function adjustVolume(event) {
  20. if (rightClickHeld) {
  21. const videoPlayer = document.querySelector('.html5-video-player');
  22. if (videoPlayer) {
  23. const currentVolume = videoPlayer.getVolume(); // YouTube API volume range is 0-100
  24. const delta = event.deltaY;
  25.  
  26. // Adjust volume in the YouTube player (range 0-100)
  27. let newVolume = currentVolume + (delta < 0 ? 1 : -1);
  28. newVolume = Math.max(0, Math.min(100, newVolume));
  29. videoPlayer.setVolume(newVolume);
  30.  
  31. event.preventDefault(); // Prevent default scroll behavior
  32.  
  33. // Show volume indicator
  34. showVolumeIndicator(newVolume);
  35. }
  36. }
  37. }
  38.  
  39. function showVolumeIndicator(volume) {
  40. const player = document.querySelector(".html5-video-player");
  41. if (!player) return;
  42.  
  43. let existingIndicator = document.querySelector("#customVolumeIndicator");
  44. if (existingIndicator) {
  45. clearTimeout(volumeTimeout);
  46. existingIndicator.remove();
  47. }
  48.  
  49. let volumeIndicator = document.createElement("div");
  50. volumeIndicator.id = "customVolumeIndicator";
  51. volumeIndicator.textContent = `${volume}%`;
  52. volumeIndicator.style.cssText = `
  53. position: absolute;
  54. top: 15%;
  55. left: 50%;
  56. transform: translateX(-50%);
  57. padding: 10px 20px;
  58. font-size: 18px;
  59. font-weight: bold;
  60. background: rgba(0, 0, 0, 0.7);
  61. color: white;
  62. border-radius: 8px;
  63. z-index: 9999;
  64. pointer-events: none;
  65. `;
  66.  
  67. player.appendChild(volumeIndicator);
  68.  
  69. volumeTimeout = setTimeout(() => {
  70. volumeIndicator.remove();
  71. }, 2000);
  72. }
  73.  
  74. // Listen for mouse down event to detect right-click
  75. window.addEventListener('mousedown', function(event) {
  76. if (event.button === 2) { // Right mouse button
  77. rightClickHeld = true;
  78. }
  79. });
  80.  
  81. // Listen for mouse up event to stop adjusting volume when right-click is released
  82. window.addEventListener('mouseup', function(event) {
  83. if (event.button === 2) { // Right mouse button
  84. rightClickHeld = false;
  85. }
  86. });
  87.  
  88. // Attach event listener to the page to track scroll wheel events
  89. window.addEventListener('wheel', function(event) {
  90. if (event.target.tagName.toLowerCase() === 'video') {
  91. adjustVolume(event);
  92. }
  93. }, { passive: false });
  94.  
  95. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址