diff --git a/src/libs/utils.js b/src/libs/utils.js index aa79cfb..5a74038 100644 --- a/src/libs/utils.js +++ b/src/libs/utils.js @@ -96,7 +96,7 @@ export const throttle = ( } } - return function (...args) { + const throttled = function (...args) { const now = Date.now(); if (!previous && options.leading === false) { previous = now; @@ -121,6 +121,15 @@ export const throttle = ( } return result; }; + + throttled.cancel = () => { + clearTimeout(timeoutId); + previous = 0; + timeoutId = null; + lastThis = lastArgs = null; + }; + + return throttled; }; /** diff --git a/src/subtitle/BilingualSubtitleManager.js b/src/subtitle/BilingualSubtitleManager.js index fe584e5..65a2c28 100644 --- a/src/subtitle/BilingualSubtitleManager.js +++ b/src/subtitle/BilingualSubtitleManager.js @@ -240,6 +240,7 @@ export class BilingualSubtitleManager { */ onSeek() { this.#currentSubtitleIndex = -1; + this.#throttledTriggerTranslations.cancel(); this.onTimeUpdate(); }