YoutubeMonolyse

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         YoutubeMonolyse
// @namespace    mailto:[email protected]
// @version      0.3.1
// @description  Create's a button in the settings menu on a youtube video page that disables/enables stereo/mono audio.
// @author       Christopher M. Lovell
// @include      https://www.youtube.com/watch?v*
// @grant        none
// @run-at document-end
// ==/UserScript==

var buttonSrc = '<div id="ytmid-toggle-btn"class="ytp-menuitem" role="menuitem" tabindex="0">' +
'    <div class="ytp-menuitem-label">Toggle Mono</div>' +
'    <div class="ytp-menuitem-content">' +
'        <button class="ytp-button"><span id="ytmid-toggle-span" class="ytp-menu-label-secondary">Stereo</span></button>' +
'    </div>' +
'</div>';

var context = new AudioContext();
    var videos = document.getElementsByTagName("video");
    var audioElement;

var isMono = false;
var btnSettingSvg;
var insertBtnParent;
var text;

window.toggleMono = () => {
  if(audioElement == null)
  {
      audioElement = context.createMediaElementSource(videos[0]);
  }

  context.destination.channelCount = isMono? 2 : 1;
  audioElement.connect(context.destination);
  isMono = !isMono;
  return isMono;
}
window.initialiseTMYoutubeMonolyse = () =>{
    console.log("Initialising -- YoutubeMonolyse by Christopher Lovell")
    btnSettingSvg = document.querySelector("#movie_player > div.ytp-chrome-bottom > div.ytp-chrome-controls > div.ytp-right-controls > button.ytp-button.ytp-settings-button");
    // Youtube's setting menu by default has no elements in it, so we open it up then instantly close it using dispatchEvents.
    btnSettingSvg.dispatchEvent(new MouseEvent('click'));
    btnSettingSvg.dispatchEvent(new MouseEvent('click'));
    insertBtnParent = document.querySelector("#ytp-id-18 > div > div");
    window.initButtons();
}
window.initButtons = () => {
    console.log("Initialising Buttons")
    insertBtnParent.insertAdjacentHTML('beforeend',buttonSrc);
    var button = document.querySelector("#ytmid-toggle-btn");
    console.log(button.innerHTML);
    text = button.querySelector("#ytmid-toggle-span");
    console.log(text.innerHTML);

    button.onclick = function(){
        console.log("Setting audio to mono!");
        window.toggleMono();
        text.innerHTML = isMono ? "Mono" : "Stereo";
    };

}
window.initialiseTMYoutubeMonolyse();

// VERSION HISTORY
// 0.1 Initial release
// 0.2 Fixed bug with video that don't have an enable annotation options
// 0.3 Fixed issue with mono option not showing up on non-hd videos