aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHanYaodong <[email protected]>2024-03-09 23:38:09 +0800
committerHanYaodong <[email protected]>2024-03-09 23:42:17 +0800
commit25b53754bab47cee6d63ed58fa3ce2cbdf504c79 (patch)
tree0777141730d536343765b5ef65c4813be76088b7
parent6c710363567e76dcfc58cc1189c18ab66968351c (diff)
downloadSponsorBlock-25b53754bab47cee6d63ed58fa3ce2cbdf504c79.tar.gz
SponsorBlock-25b53754bab47cee6d63ed58fa3ce2cbdf504c79.zip
Stop refresh animation on popup when content script is not injected
-rw-r--r--src/content.ts8
-rw-r--r--src/messageTypes.ts7
-rw-r--r--src/popup.ts13
3 files changed, 21 insertions, 7 deletions
diff --git a/src/content.ts b/src/content.ts
index f89fb369..a7b8c45b 100644
--- a/src/content.ts
+++ b/src/content.ts
@@ -259,11 +259,11 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
case "refreshSegments":
// update video on refresh if videoID invalid
if (!getVideoID()) {
- checkVideoIDChange().then(() => {
- // if still no video ID found, return an empty info to the popup
- if (!getVideoID()) chrome.runtime.sendMessage({ message: "infoUpdated" });
- });
+ checkVideoIDChange();
}
+ // if popup rescieves no response, or the videoID is invalid,
+ // it will assume the page is not a video page and stop the refresh animation
+ sendResponse({ hasVideo: getVideoID() != null });
// fetch segments
sponsorsLookup(false);
diff --git a/src/messageTypes.ts b/src/messageTypes.ts
index 339bfafe..191166a0 100644
--- a/src/messageTypes.ts
+++ b/src/messageTypes.ts
@@ -103,7 +103,8 @@ export type MessageResponse =
| IsChannelWhitelistedResponse
| Record<string, never> // empty object response {}
| VoteResponse
- | ImportSegmentsResponse;
+ | ImportSegmentsResponse
+ | RefreshSegmentsResponse;
export interface VoteResponse {
successType: number;
@@ -115,6 +116,10 @@ interface ImportSegmentsResponse {
importedSegments: SponsorTime[];
}
+export interface RefreshSegmentsResponse {
+ hasVideo: boolean;
+}
+
export interface TimeUpdateMessage {
message: "time";
time: number;
diff --git a/src/popup.ts b/src/popup.ts
index f954f168..b986a2ed 100644
--- a/src/popup.ts
+++ b/src/popup.ts
@@ -15,6 +15,7 @@ import {
Message,
MessageResponse,
PopupMessage,
+ RefreshSegmentsResponse,
SponsorStartResponse,
VoteResponse,
} from "./messageTypes";
@@ -982,9 +983,17 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
stopLoadingAnimation = AnimationUtils.applyLoadingAnimation(PageElements.refreshSegmentsButton, 0.3);
}
- function refreshSegments() {
+ async function refreshSegments() {
startLoadingAnimation();
- sendTabMessage({ message: 'refreshSegments' });
+ const response = await sendTabMessageAsync({ message: 'refreshSegments' }) as RefreshSegmentsResponse;
+
+ if (response == null || !response.hasVideo) {
+ if (stopLoadingAnimation != null) {
+ stopLoadingAnimation();
+ stopLoadingAnimation = null;
+ }
+ displayNoVideo();
+ }
}
function skipSegment(actionType: ActionType, UUID: SegmentUUID, element?: HTMLElement): void {