opt: Optimize subtitle processing logic
This commit is contained in:
@@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -240,6 +240,7 @@ export class BilingualSubtitleManager {
|
|||||||
*/
|
*/
|
||||||
onSeek() {
|
onSeek() {
|
||||||
this.#currentSubtitleIndex = -1;
|
this.#currentSubtitleIndex = -1;
|
||||||
|
this.#throttledTriggerTranslations.cancel();
|
||||||
this.onTimeUpdate();
|
this.onTimeUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user