Skip to content

Commit eac2caa

Browse files
committed
Fix document script sending events when video id not changed
1 parent 8d0a4ec commit eac2caa

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/document.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type WindowMessage = StartMessage | FinishMessage | AdMessage | VideoData;
3333
// global playerClient - too difficult to type
3434
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3535
let playerClient: any;
36+
let lastVideo = "";
3637

3738
const sendMessage = (message: WindowMessage): void => {
3839
window.postMessage({ source: "sponsorblock", ...message }, "/");
@@ -87,7 +88,8 @@ function navigateFinishSend(event: CustomEvent): void {
8788
function sendVideoData(): void {
8889
if (!playerClient) return;
8990
const videoData = playerClient.getVideoData();
90-
if (videoData) {
91+
if (videoData && videoData.video_id !== lastVideo) {
92+
lastVideo = videoData.video_id;
9193
sendMessage({ type: "data", videoID: videoData.video_id, isLive: videoData.isLive, isPremiere: videoData.isPremiere } as VideoData);
9294
}
9395
}

0 commit comments

Comments
 (0)