From 618ce3150305ecf7f01e59b2772ec2c9f1fc9b0a Mon Sep 17 00:00:00 2001 From: Victor Savinov Date: Wed, 17 Feb 2021 23:31:49 +0300 Subject: [PATCH] Improved Loudness normalization --- manifest.json | 4 ++-- youtube-scripts.js | 23 ++++++++++++++--------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/manifest.json b/manifest.json index ccc2ecc8d..8279d6012 100644 --- a/manifest.json +++ b/manifest.json @@ -3,8 +3,8 @@ "name": "Improve YouTube! (testing)", "short_name": "ImprovedTube", "description": "Make YouTube tidy & powerful! YouTube Player Size Theme Quality Colors ad-block Playback Speed Style Playlist Channel H.264 Auto HD", - "version": "3.162", - "version_name": "3.162-testing", + "version": "3.163", + "version_name": "3.163-testing", "default_locale": "en", "icons": { "128": "assets/icons/128.png", diff --git a/youtube-scripts.js b/youtube-scripts.js index 249ad2a30..dcb7bb2b9 100644 --- a/youtube-scripts.js +++ b/youtube-scripts.js @@ -1637,15 +1637,20 @@ ImprovedTube.playerVolume = function(node) { 4.13 LOUDNESS NORMALIZATION ------------------------------------------------------------------------------*/ +ImprovedTube.onvolumechange = function(event) { + if (document.querySelector('.ytp-volume-panel') && ImprovedTube.storage.player_loudness_normalization === false) { + var volume = Number(document.querySelector('.ytp-volume-panel').getAttribute('aria-valuenow')); + + this.volume = volume / 100; + } +}; + ImprovedTube.playerLoudnessNormalization = function() { - if (document.querySelector('video')) { - document.querySelector('video').onvolumechange = function(event) { - if (document.querySelector('.ytp-volume-panel') && ImprovedTube.storage.player_loudness_normalization === false) { - var volume = Number(document.querySelector('.ytp-volume-panel').getAttribute('aria-valuenow')); + var video = document.querySelector('video'); - document.querySelector('video').volume = volume / 100; - } - }; + if (video) { + video.removeEventListener('volumechange', ImprovedTube.onvolumechange); + video.addEventListener('volumechange', ImprovedTube.onvolumechange); } if (ImprovedTube.storage.player_loudness_normalization === false) { @@ -1658,9 +1663,9 @@ ImprovedTube.playerLoudnessNormalization = function() { local_storage = JSON.parse(JSON.parse(local_storage).data); local_storage = Number(local_storage.volume); - document.querySelector('video').volume = local_storage / 100; + video.volume = local_storage / 100; } else { - document.querySelector('video').volume = 100; + video.volume = 100; } } catch (err) {} }