Skip to content

Instantly share code, notes, and snippets.

@Onurtag
Last active June 18, 2020 00:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Onurtag/28d8826e2f7e369a3fe57bd69bb61f8f to your computer and use it in GitHub Desktop.
Save Onurtag/28d8826e2f7e369a3fe57bd69bb61f8f to your computer and use it in GitHub Desktop.
Prevent Youtube Audio Normalization with a Userscript.
// ==UserScript==
// @name Prevent Youtube Audio Normalization
// @namespace asdcawdcawcdkacja2333332
// @version 1.5
// @description Prevent Youtube Audio Normalization
// @author asdcawdcawcdkacja2333332
// @match https://www.youtube.com/*
// @grant none
// ==/UserScript==
//Background tabs are throttled so sometimes it takes a second to apply the value which is annoying as hell.
//Not sure if requestanimationframe is better than an interval for the above reason. requestanimationframe doesn't make the sound pop on volume change though.
//https://webapps.stackexchange.com/questions/90995/how-can-i-change-a-youtube-videos-volume-beyond-the-normal-limits/103665#103665
//There should be a better way to do this using the "loudnessDb" and the "perceptualLoudnessDb" values within the video/player configs, but I have no idea how.
//Try both methods together
var theVideo, barVolume;
function repeatonFrame() {
trytoFix();
requestAnimationFrame(repeatonFrame);
}
function trytoFix() {
try {
theVideo = document.getElementsByTagName('video')[0];
barVolume = document.getElementsByClassName("ytp-volume-panel")[0].attributes["aria-valuenow"].value / 100;
if (theVideo.volume != barVolume) {
console.log("Fixed the video volume from " + theVideo.volume + " to " + barVolume);
theVideo.volume = barVolume;
}
//document.getElementsByTagName('video')[0].volume = document.getElementsByClassName("ytp-volume-panel")[0].attributes["aria-valuenow"].value / 100;
} catch (e) {}
}
//SETINTERVAL METHOD
var TheInterval = setInterval(trytoFix, 100);
//REQUESTANIMATIONFRAME METHOD
requestAnimationFrame(repeatonFrame);
/*
//backup (useless)
document.getElementById("player-wrap").children[2].innerHTML.replace(/([lL])oudnessDb(.*?):(.*?)([,}])/g, "$1oudnessDb$2:0$4");
*/
@abec2304
Copy link

@Onurtag
Copy link
Author

Onurtag commented Nov 18, 2019

Here's an alternative implementation: https://gist.github.com/abec2304/2782f4fc47f9d010dfaab00f25e69c8a

Thanks for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment