diff --git a/app/Resources/Tracker/bootstrap.js b/app/Resources/Tracker/bootstrap.js index a4c03e3..b17d6b7 100644 --- a/app/Resources/Tracker/bootstrap.js +++ b/app/Resources/Tracker/bootstrap.js @@ -125,8 +125,7 @@ } }; - const callbackTimer = DISCORD.setupMessageCallback(onMessagesUpdated); - window.DHT_ON_UNLOAD.push(() => window.clearTimeout(callbackTimer)); + DISCORD.setupMessageCallback(onMessagesUpdated); STATE.onTrackingStateChanged(enabled => { if (enabled) { diff --git a/app/Resources/Tracker/scripts/discord.js b/app/Resources/Tracker/scripts/discord.js index 026b3af..a3e8531 100644 --- a/app/Resources/Tracker/scripts/discord.js +++ b/app/Resources/Tracker/scripts/discord.js @@ -26,14 +26,13 @@ class DISCORD { /** * Calls the provided function with a list of messages whenever the currently loaded messages change. - * Returns a setInterval handle. */ static setupMessageCallback(callback) { let skipsLeft = 0; let waitForCleanup = false; const previousMessages = new Set(); - return window.setInterval(() => { + const timer = window.setInterval(() => { if (skipsLeft > 0) { --skipsLeft; return; @@ -88,6 +87,8 @@ class DISCORD { callback(messages); }, 200); + + window.DHT_ON_UNLOAD.push(() => window.clearInterval(timer)); } /**