Fix calling clearTimeout instead of clearInterval in app script (no difference according to spec, but cleaner)

This commit is contained in:
chylex 2022-02-12 20:32:01 +01:00
parent 0662af9b1a
commit d772f7ed71
No known key found for this signature in database
GPG Key ID: 4DE42C8F19A80548
2 changed files with 4 additions and 4 deletions

View File

@ -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) {

View File

@ -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));
}
/**