From c32eec1bb2e25c01cbc209d0380beab6cbe7029b Mon Sep 17 00:00:00 2001 From: Chad Bailey Date: Sat, 7 Mar 2020 18:23:55 -0600 Subject: [PATCH] Moved ratechange listener into its own function Placed call for adding listener after call to document ready/disabled check Placed setupListener within try/catch block --- inject.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/inject.js b/inject.js index 3c7c308..15ecb5f 100644 --- a/inject.js +++ b/inject.js @@ -374,11 +374,7 @@ function refreshCoolDown() { log("End refreshCoolDown", 5); } -function initializeWhenReady(document) { - log("Begin initializeWhenReady", 5); - if (isBlacklisted()) { - return; - } +function setupListener() { document.body.addEventListener( "ratechange", function(event) { @@ -391,6 +387,13 @@ function initializeWhenReady(document) { }, true ); +} + +function initializeWhenReady(document) { + log("Begin initializeWhenReady", 5); + if (isBlacklisted()) { + return; + } window.onload = () => { initializeNow(window.document); }; @@ -449,6 +452,11 @@ function initializeNow(document) { if (!document.body || document.body.classList.contains("vsc-initialized")) { return; } + try { + setupListener(); + } catch { + // no operation + } document.body.classList.add("vsc-initialized"); log("initializeNow: vsc-initialized added to document body", 5);