Skip to content

Commit

Permalink
Moved ratechange listener into its own function
Browse files Browse the repository at this point in the history
Placed call for adding listener after call to document ready/disabled check
Placed setupListener within try/catch block
  • Loading branch information
ChadBailey committed Mar 8, 2020
1 parent ff3ea31 commit c32eec1
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -391,6 +387,13 @@ function initializeWhenReady(document) {
},
true
);
}

function initializeWhenReady(document) {
log("Begin initializeWhenReady", 5);
if (isBlacklisted()) {
return;
}
window.onload = () => {
initializeNow(window.document);
};
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit c32eec1

Please sign in to comment.