opt: Optimize subtitle processing logic

This commit is contained in:
Gabe
2025-11-02 00:04:46 +08:00
parent 7f04000739
commit 0c49cf1af9
2 changed files with 11 additions and 1 deletions

View File

@@ -96,7 +96,7 @@ export const throttle = (
} }
} }
return function (...args) { const throttled = function (...args) {
const now = Date.now(); const now = Date.now();
if (!previous && options.leading === false) { if (!previous && options.leading === false) {
previous = now; previous = now;
@@ -121,6 +121,15 @@ export const throttle = (
} }
return result; return result;
}; };
throttled.cancel = () => {
clearTimeout(timeoutId);
previous = 0;
timeoutId = null;
lastThis = lastArgs = null;
};
return throttled;
}; };
/** /**

View File

@@ -240,6 +240,7 @@ export class BilingualSubtitleManager {
*/ */
onSeek() { onSeek() {
this.#currentSubtitleIndex = -1; this.#currentSubtitleIndex = -1;
this.#throttledTriggerTranslations.cancel();
this.onTimeUpdate(); this.onTimeUpdate();
} }