diff --git a/src/background.ts b/src/background.ts index 55236cec..bf1adae7 100644 --- a/src/background.ts +++ b/src/background.ts @@ -74,6 +74,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) { case "time": case "infoUpdated": case "videoChanged": + case "refreshAck": if (sender.tab) { try { popupPort[sender.tab.id]?.postMessage(request); diff --git a/src/content.ts b/src/content.ts index b8652aaa..72f51481 100644 --- a/src/content.ts +++ b/src/content.ts @@ -247,6 +247,7 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo openSubmissionMenu(); break; case "refreshSegments": + chrome.runtime.sendMessage({ message: "refreshAck" }); // update video on refresh if videoID invalid if (!getVideoID()) { checkVideoIDChange().then(() => { diff --git a/src/messageTypes.ts b/src/messageTypes.ts index 091aef3b..4f3a41bf 100644 --- a/src/messageTypes.ts +++ b/src/messageTypes.ts @@ -123,10 +123,14 @@ export type InfoUpdatedMessage = IsInfoFoundMessageResponse & { message: "infoUpdated"; } +export interface RefreshAckMessage { + message: "refreshAck"; +} + export interface VideoChangedPopupMessage { message: "videoChanged"; videoID: string; whitelisted: boolean; } -export type PopupMessage = TimeUpdateMessage | InfoUpdatedMessage | VideoChangedPopupMessage; +export type PopupMessage = TimeUpdateMessage | InfoUpdatedMessage | RefreshAckMessage | VideoChangedPopupMessage; diff --git a/src/popup.ts b/src/popup.ts index 00381e93..6fa76459 100644 --- a/src/popup.ts +++ b/src/popup.ts @@ -936,8 +936,21 @@ async function runThePopup(messageListener?: MessageListener): Promise { stopLoadingAnimation = AnimationUtils.applyLoadingAnimation(PageElements.refreshSegmentsButton, 0.3); } + let stopAnimationTimer = null; function refreshSegments() { + if (stopAnimationTimer != null) { + return; + } startLoadingAnimation(); + stopAnimationTimer = setTimeout(() => { + // if no content script sends back acknolwedgement, assume the page is not bilibili + if (stopLoadingAnimation != null) { + stopLoadingAnimation(); + stopLoadingAnimation = null; + } + displayNoVideo(); + stopAnimationTimer = null; + }, 100); sendTabMessage({ message: 'refreshSegments' }); } @@ -1088,6 +1101,12 @@ async function runThePopup(messageListener?: MessageListener): Promise { case "time": updateCurrentTime(msg.time); break; + case "refreshAck": + if (stopAnimationTimer != null) { + clearTimeout(stopAnimationTimer); + stopAnimationTimer = null; + } + break; case "infoUpdated": infoFound(msg); break;