mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-15 07:57:09 +03:00
Stop refresh animation on popup when content script is not injected
This commit is contained in:
@@ -259,11 +259,11 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
|
|||||||
case "refreshSegments":
|
case "refreshSegments":
|
||||||
// update video on refresh if videoID invalid
|
// update video on refresh if videoID invalid
|
||||||
if (!getVideoID()) {
|
if (!getVideoID()) {
|
||||||
checkVideoIDChange().then(() => {
|
checkVideoIDChange();
|
||||||
// if still no video ID found, return an empty info to the popup
|
|
||||||
if (!getVideoID()) chrome.runtime.sendMessage({ message: "infoUpdated" });
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
// 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
|
// fetch segments
|
||||||
sponsorsLookup(false);
|
sponsorsLookup(false);
|
||||||
|
|
||||||
|
|||||||
@@ -103,7 +103,8 @@ export type MessageResponse =
|
|||||||
| IsChannelWhitelistedResponse
|
| IsChannelWhitelistedResponse
|
||||||
| Record<string, never> // empty object response {}
|
| Record<string, never> // empty object response {}
|
||||||
| VoteResponse
|
| VoteResponse
|
||||||
| ImportSegmentsResponse;
|
| ImportSegmentsResponse
|
||||||
|
| RefreshSegmentsResponse;
|
||||||
|
|
||||||
export interface VoteResponse {
|
export interface VoteResponse {
|
||||||
successType: number;
|
successType: number;
|
||||||
@@ -115,6 +116,10 @@ interface ImportSegmentsResponse {
|
|||||||
importedSegments: SponsorTime[];
|
importedSegments: SponsorTime[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface RefreshSegmentsResponse {
|
||||||
|
hasVideo: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export interface TimeUpdateMessage {
|
export interface TimeUpdateMessage {
|
||||||
message: "time";
|
message: "time";
|
||||||
time: number;
|
time: number;
|
||||||
|
|||||||
13
src/popup.ts
13
src/popup.ts
@@ -15,6 +15,7 @@ import {
|
|||||||
Message,
|
Message,
|
||||||
MessageResponse,
|
MessageResponse,
|
||||||
PopupMessage,
|
PopupMessage,
|
||||||
|
RefreshSegmentsResponse,
|
||||||
SponsorStartResponse,
|
SponsorStartResponse,
|
||||||
VoteResponse,
|
VoteResponse,
|
||||||
} from "./messageTypes";
|
} from "./messageTypes";
|
||||||
@@ -982,9 +983,17 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
|||||||
stopLoadingAnimation = AnimationUtils.applyLoadingAnimation(PageElements.refreshSegmentsButton, 0.3);
|
stopLoadingAnimation = AnimationUtils.applyLoadingAnimation(PageElements.refreshSegmentsButton, 0.3);
|
||||||
}
|
}
|
||||||
|
|
||||||
function refreshSegments() {
|
async function refreshSegments() {
|
||||||
startLoadingAnimation();
|
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 {
|
function skipSegment(actionType: ActionType, UUID: SegmentUUID, element?: HTMLElement): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user