YouTube Volume Display

Display current YouTube volume level in the UI

  1. // ==UserScript==
  2. // @name YouTube Volume Display
  3. // @namespace typpi.online
  4. // @version 1.3
  5. // @description Display current YouTube volume level in the UI
  6. // @match *://www.youtube.com/*
  7. // @grant none
  8. // @author Nick2bad4u
  9. // @grant none
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
  11. // @license UnLicense
  12. // @tag youtube
  13. // ==/UserScript==
  14.  
  15. (function () {
  16. 'use strict';
  17.  
  18. const playerReady = setInterval(() => {
  19. const videoPlayer = document.querySelector('video');
  20. const leftControls = document.querySelector('.ytp-left-controls');
  21.  
  22. if (videoPlayer && leftControls) {
  23. clearInterval(playerReady);
  24.  
  25. // Create an input element to display volume level
  26. const volumeDisplay = document.createElement('input');
  27. volumeDisplay.type = 'text';
  28. volumeDisplay.value = videoPlayer.muted
  29. ? '0'
  30. : Math.round(videoPlayer.volume * 100);
  31. volumeDisplay.readOnly = true;
  32.  
  33. // Style the display element
  34. Object.assign(volumeDisplay.style, {
  35. width: '40px',
  36. marginLeft: '10px',
  37. backgroundColor: 'rgba(255, 255, 255, 0.0)',
  38. color: 'white',
  39. border: '0px solid rgba(255, 255, 255, 0.0)',
  40. borderRadius: '4px',
  41. zIndex: 9999,
  42. height: '24px',
  43. fontSize: '16px',
  44. padding: '0 4px',
  45. position: 'relative',
  46. top: '13px',
  47. });
  48.  
  49. // Update display when volume changes
  50. videoPlayer.addEventListener('volumechange', () => {
  51. volumeDisplay.value = videoPlayer.muted
  52. ? '0'
  53. : Math.round(videoPlayer.volume * 100);
  54. });
  55.  
  56. // Insert the display element into the left controls
  57. leftControls.appendChild(volumeDisplay);
  58. }
  59. }, 500);
  60. })();

QingJ © 2025

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