YoutubeMonolyse

Create's a button in the settings menu on a youtube video page that disables/enables stereo/mono audio.

  1. // ==UserScript==
  2. // @name YoutubeMonolyse
  3. // @namespace mailto:help.christopherlovell@gmail.com
  4. // @version 0.3.1
  5. // @description Create's a button in the settings menu on a youtube video page that disables/enables stereo/mono audio.
  6. // @author Christopher M. Lovell
  7. // @include https://www.youtube.com/watch?v*
  8. // @grant none
  9. // @run-at document-end
  10. // ==/UserScript==
  11.  
  12. var buttonSrc = '<div id="ytmid-toggle-btn"class="ytp-menuitem" role="menuitem" tabindex="0">' +
  13. ' <div class="ytp-menuitem-label">Toggle Mono</div>' +
  14. ' <div class="ytp-menuitem-content">' +
  15. ' <button class="ytp-button"><span id="ytmid-toggle-span" class="ytp-menu-label-secondary">Stereo</span></button>' +
  16. ' </div>' +
  17. '</div>';
  18.  
  19. var context = new AudioContext();
  20. var videos = document.getElementsByTagName("video");
  21. var audioElement;
  22.  
  23. var isMono = false;
  24. var btnSettingSvg;
  25. var insertBtnParent;
  26. var text;
  27.  
  28. window.toggleMono = () => {
  29. if(audioElement == null)
  30. {
  31. audioElement = context.createMediaElementSource(videos[0]);
  32. }
  33.  
  34. context.destination.channelCount = isMono? 2 : 1;
  35. audioElement.connect(context.destination);
  36. isMono = !isMono;
  37. return isMono;
  38. }
  39. window.initialiseTMYoutubeMonolyse = () =>{
  40. console.log("Initialising -- YoutubeMonolyse by Christopher Lovell")
  41. btnSettingSvg = document.querySelector("#movie_player > div.ytp-chrome-bottom > div.ytp-chrome-controls > div.ytp-right-controls > button.ytp-button.ytp-settings-button");
  42. // Youtube's setting menu by default has no elements in it, so we open it up then instantly close it using dispatchEvents.
  43. btnSettingSvg.dispatchEvent(new MouseEvent('click'));
  44. btnSettingSvg.dispatchEvent(new MouseEvent('click'));
  45. insertBtnParent = document.querySelector("#ytp-id-18 > div > div");
  46. window.initButtons();
  47. }
  48. window.initButtons = () => {
  49. console.log("Initialising Buttons")
  50. insertBtnParent.insertAdjacentHTML('beforeend',buttonSrc);
  51. var button = document.querySelector("#ytmid-toggle-btn");
  52. console.log(button.innerHTML);
  53. text = button.querySelector("#ytmid-toggle-span");
  54. console.log(text.innerHTML);
  55.  
  56. button.onclick = function(){
  57. console.log("Setting audio to mono!");
  58. window.toggleMono();
  59. text.innerHTML = isMono ? "Mono" : "Stereo";
  60. };
  61.  
  62. }
  63. window.initialiseTMYoutubeMonolyse();
  64.  
  65. // VERSION HISTORY
  66. // 0.1 Initial release
  67. // 0.2 Fixed bug with video that don't have an enable annotation options
  68. // 0.3 Fixed issue with mono option not showing up on non-hd videos
  69.  

QingJ © 2025

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