mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-06 11:37:02 +03:00
Merge pull request #1983 from HanYaodong/dev
[Fix #1979] 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;
|
||||||
|
|||||||
61
src/popup.ts
61
src/popup.ts
@@ -15,6 +15,7 @@ import {
|
|||||||
Message,
|
Message,
|
||||||
MessageResponse,
|
MessageResponse,
|
||||||
PopupMessage,
|
PopupMessage,
|
||||||
|
RefreshSegmentsResponse,
|
||||||
SponsorStartResponse,
|
SponsorStartResponse,
|
||||||
VoteResponse,
|
VoteResponse,
|
||||||
} from "./messageTypes";
|
} from "./messageTypes";
|
||||||
@@ -459,39 +460,35 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
|||||||
stopLoadingAnimation = null;
|
stopLoadingAnimation = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chrome.runtime.lastError) {
|
if (chrome.runtime.lastError || request == undefined || request.found == undefined) {
|
||||||
//This page doesn't have the injected content script, or at least not yet
|
//This page doesn't have the injected content script, or at least not yet
|
||||||
|
// Or if the request is empty, meaning the current page is not YouTube or a video page
|
||||||
displayNoVideo();
|
displayNoVideo();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if request has no field other than message, then the page currently being browsed is not YouTube
|
//remove loading text
|
||||||
if (request.found != undefined) {
|
PageElements.mainControls.style.display = "block";
|
||||||
//remove loading text
|
if (request.onMobileYouTube) PageElements.mainControls.classList.add("hidden");
|
||||||
PageElements.mainControls.style.display = "block";
|
PageElements.whitelistButton.classList.remove("hidden");
|
||||||
if (request.onMobileYouTube) PageElements.mainControls.classList.add("hidden");
|
PageElements.loadingIndicator.style.display = "none";
|
||||||
PageElements.whitelistButton.classList.remove("hidden");
|
|
||||||
PageElements.loadingIndicator.style.display = "none";
|
|
||||||
|
|
||||||
downloadedTimes = request.sponsorTimes ?? [];
|
downloadedTimes = request.sponsorTimes ?? [];
|
||||||
displayDownloadedSponsorTimes(downloadedTimes, request.time);
|
displayDownloadedSponsorTimes(downloadedTimes, request.time);
|
||||||
if (request.found) {
|
if (request.found) {
|
||||||
PageElements.videoFound.innerHTML = chrome.i18n.getMessage("sponsorFound");
|
PageElements.videoFound.innerHTML = chrome.i18n.getMessage("sponsorFound");
|
||||||
PageElements.issueReporterImportExport.classList.remove("hidden");
|
PageElements.issueReporterImportExport.classList.remove("hidden");
|
||||||
} else if (request.status == 404 || request.status == 200) {
|
} else if (request.status == 404 || request.status == 200) {
|
||||||
PageElements.videoFound.innerHTML = chrome.i18n.getMessage("sponsor404");
|
PageElements.videoFound.innerHTML = chrome.i18n.getMessage("sponsor404");
|
||||||
PageElements.issueReporterImportExport.classList.remove("hidden");
|
PageElements.issueReporterImportExport.classList.remove("hidden");
|
||||||
} else {
|
|
||||||
if (request.status) {
|
|
||||||
PageElements.videoFound.innerHTML = chrome.i18n.getMessage("connectionError") + request.status;
|
|
||||||
} else {
|
|
||||||
PageElements.videoFound.innerHTML = chrome.i18n.getMessage("segmentsStillLoading");
|
|
||||||
}
|
|
||||||
|
|
||||||
PageElements.issueReporterImportExport.classList.remove("hidden");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
displayNoVideo();
|
if (request.status) {
|
||||||
|
PageElements.videoFound.innerHTML = chrome.i18n.getMessage("connectionError") + request.status;
|
||||||
|
} else {
|
||||||
|
PageElements.videoFound.innerHTML = chrome.i18n.getMessage("segmentsStillLoading");
|
||||||
|
}
|
||||||
|
|
||||||
|
PageElements.issueReporterImportExport.classList.remove("hidden");
|
||||||
}
|
}
|
||||||
|
|
||||||
//see if whitelist button should be swapped
|
//see if whitelist button should be swapped
|
||||||
@@ -982,9 +979,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