aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAjay Ramachandran <[email protected]>2022-06-24 17:22:33 -0400
committerGitHub <[email protected]>2022-06-24 17:22:33 -0400
commit67b510e628382d619d7b509ab42d1458ce269f99 (patch)
treedbaabb720651c22e3cb4246a19b11d6cd715a66a
parent6b4da2584784645f0b723db8451e340a02cdf247 (diff)
parent7cc0847db11cf88a207f090d05b45197a6235e8b (diff)
downloadSponsorBlock-67b510e628382d619d7b509ab42d1458ce269f99.tar.gz
SponsorBlock-67b510e628382d619d7b509ab42d1458ce269f99.zip
Merge pull request #1370 from mchangrh/popup-connection-error
Show connectionError string if status is not 404
-rw-r--r--src/content.ts19
-rw-r--r--src/messageTypes.ts3
-rw-r--r--src/popup.ts4
3 files changed, 19 insertions, 7 deletions
diff --git a/src/content.ts b/src/content.ts
index bb4bdf9a..e97d5309 100644
--- a/src/content.ts
+++ b/src/content.ts
@@ -65,8 +65,8 @@ const videosWithEventListeners: HTMLVideoElement[] = [];
const controlsWithEventListeners: HTMLElement[] = []
// This misleading variable name will be fixed soon
-let onInvidious;
-let onMobileYouTube;
+let onInvidious: boolean;
+let onMobileYouTube: boolean;
//the video id of the last preview bar update
let lastPreviewBarUpdate;
@@ -117,6 +117,9 @@ let submissionNotice: SubmissionNotice = null;
// If there is an advert playing (or about to be played), this is true
let isAdPlaying = false;
+// last response status
+let lastResponseStatus: number;
+
// Contains all of the functions and variables needed by the skip notice
const skipNoticeContentContainer: ContentContainer = () => ({
vote,
@@ -163,6 +166,7 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
//send the sponsor times along with if it's found
sendResponse({
found: sponsorDataFound,
+ status: lastResponseStatus,
sponsorTimes: sponsorTimes,
onMobileYouTube
});
@@ -204,6 +208,7 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
case "refreshSegments":
sponsorsLookup(false).then(() => sendResponse({
found: sponsorDataFound,
+ status: lastResponseStatus,
sponsorTimes: sponsorTimes,
onMobileYouTube
}));
@@ -828,7 +833,6 @@ async function sponsorsLookup(keepOldSubmissions = true) {
const hashParams = getHashParams();
if (hashParams.requiredSegment) extraRequestData.requiredSegment = hashParams.requiredSegment;
- // Check for hashPrefix setting
const hashPrefix = (await utils.getHash(sponsorVideoID, 1)).slice(0, 4) as VideoID & HashedValue;
const response = await utils.asyncRequestToServer('GET', "/api/skipSegments/" + hashPrefix, {
categories,
@@ -837,6 +841,9 @@ async function sponsorsLookup(keepOldSubmissions = true) {
...extraRequestData
});
+ // store last response status
+ lastResponseStatus = response?.status;
+
if (response?.ok) {
const recievedSegments: SponsorTime[] = JSON.parse(response.responseText)
?.filter((video) => video.videoID === sponsorVideoID)
@@ -904,8 +911,10 @@ async function sponsorsLookup(keepOldSubmissions = true) {
//otherwise the listener can handle it
updatePreviewBar();
}
- } else if (response?.status === 404) {
- retryFetch();
+ } else {
+ if (lastResponseStatus === 404) {
+ retryFetch();
+ }
}
if (Config.config.isVip) {
diff --git a/src/messageTypes.ts b/src/messageTypes.ts
index 65e5c612..764d2dc4 100644
--- a/src/messageTypes.ts
+++ b/src/messageTypes.ts
@@ -63,6 +63,7 @@ export type Message = BaseMessage & (DefaultMessage | BoolValueMessage | IsInfoF
export interface IsInfoFoundMessageResponse {
found: boolean;
+ status: number;
sponsorTimes: SponsorTime[];
onMobileYouTube: boolean;
}
@@ -89,7 +90,7 @@ export type MessageResponse =
| GetChannelIDResponse
| SponsorStartResponse
| IsChannelWhitelistedResponse
- | Record<string, never>
+ | Record<never, never> // empty object response {}
| VoteResponse;
export interface VoteResponse {
diff --git a/src/popup.ts b/src/popup.ts
index 0a5d7c16..75afa07b 100644
--- a/src/popup.ts
+++ b/src/popup.ts
@@ -367,8 +367,10 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
PageElements.videoFound.innerHTML = chrome.i18n.getMessage("sponsorFound");
displayDownloadedSponsorTimes(request);
- } else {
+ } else if (request.status == 404 || request.status == 200) {
PageElements.videoFound.innerHTML = chrome.i18n.getMessage("sponsor404");
+ } else {
+ PageElements.videoFound.innerHTML = chrome.i18n.getMessage("connectionError") + request.status;
}
}