YT - Volume Normalizer

Boosts maximum possible YT Volume to native 100%

Click here to install Browse More Scripts
// ==UserScript==
// @name         YT - Volume Normalizer
// @namespace    35cd4c7b6d76e33d5441207318dc73634097bd66
// @version      0.2
// @description  Boosts maximum possible YT Volume to native 100%
// @author       /u/AyrA_ch
// @match        https://www.youtube.com/*
// @grant        none
// ==/UserScript==

// Changelog
// 0.2 - Changed script title to be consistent with other YT scripts
// 0.1 - Initial version for old YT design
// =========

(function (q) {
	'use strict';
	var setVolume = function () {
		//This contains the volume slider value
		var element = q(".ytp-volume-panel");
		//Video Element
		var v = q("video");
		if (element && v) {
			var f = function (e) {
				//Override volume if it is different.
				//Only compare integers to prevent infinite loops due to rounding errors.
				var volNew = element.getAttribute("aria-valuenow") | 0;
				var volOld = v.volume * 100 | 0;
				if (volNew === volNew && volOld != volNew) {
					v.volume = volNew / 100;
				}
			};
			//attach event if it has not
			if (!v.onvolumechange) {
				v.onvolumechange = f;
			}
			//attach event if it has not
			if (!v.ontimeupdate) {
				v.ontimeupdate = f;
			}
		}
	};

	//Try to attach volume function on each change to the site
	//"subtree:true" is not needed because YT changes the main body content constantly.
	var observer = new MutationObserver(setVolume);
	var config = {
		attributes: true,
		childList: true,
		characterData: false
	};
	observer.observe(document.body, config);
})(document.querySelector.bind(document));

/*
LICENSE:
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
The full license text can be found here: http://creativecommons.org/licenses/by-nc-sa/4.0/
The link has an easy to understand version of the license and the full license text.

DISCLAIMER:
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
*/

Copyright © 2018 by Kevin Gut 📧 | More services | Generated for 54.236.62.49