aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHanYaodong <[email protected]>2024-03-09 23:47:48 +0800
committerHanYaodong <[email protected]>2024-03-09 23:47:48 +0800
commita1505bcf205c609e7ddd65b941562e26ceecd19f (patch)
treeff1d5d57d6f464c7ff61f2bcb60d58171870a924
parent25b53754bab47cee6d63ed58fa3ce2cbdf504c79 (diff)
downloadSponsorBlock-a1505bcf205c609e7ddd65b941562e26ceecd19f.tar.gz
SponsorBlock-a1505bcf205c609e7ddd65b941562e26ceecd19f.zip
Refractor popup infoFound() empty message detection
-rw-r--r--src/popup.ts48
1 files changed, 22 insertions, 26 deletions
diff --git a/src/popup.ts b/src/popup.ts
index b986a2ed..2f3a0d7a 100644
--- a/src/popup.ts
+++ b/src/popup.ts
@@ -460,39 +460,35 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
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
+ // Or if the request is empty, meaning the current page is not YouTube or a video page
displayNoVideo();
return;
}
- // if request has no field other than message, then the page currently being browsed is not YouTube
- if (request.found != undefined) {
- //remove loading text
- PageElements.mainControls.style.display = "block";
- if (request.onMobileYouTube) PageElements.mainControls.classList.add("hidden");
- PageElements.whitelistButton.classList.remove("hidden");
- PageElements.loadingIndicator.style.display = "none";
-
- downloadedTimes = request.sponsorTimes ?? [];
- displayDownloadedSponsorTimes(downloadedTimes, request.time);
- if (request.found) {
- PageElements.videoFound.innerHTML = chrome.i18n.getMessage("sponsorFound");
- PageElements.issueReporterImportExport.classList.remove("hidden");
- } else if (request.status == 404 || request.status == 200) {
- PageElements.videoFound.innerHTML = chrome.i18n.getMessage("sponsor404");
- PageElements.issueReporterImportExport.classList.remove("hidden");
+ //remove loading text
+ PageElements.mainControls.style.display = "block";
+ if (request.onMobileYouTube) PageElements.mainControls.classList.add("hidden");
+ PageElements.whitelistButton.classList.remove("hidden");
+ PageElements.loadingIndicator.style.display = "none";
+
+ downloadedTimes = request.sponsorTimes ?? [];
+ displayDownloadedSponsorTimes(downloadedTimes, request.time);
+ if (request.found) {
+ PageElements.videoFound.innerHTML = chrome.i18n.getMessage("sponsorFound");
+ PageElements.issueReporterImportExport.classList.remove("hidden");
+ } else if (request.status == 404 || request.status == 200) {
+ PageElements.videoFound.innerHTML = chrome.i18n.getMessage("sponsor404");
+ PageElements.issueReporterImportExport.classList.remove("hidden");
+ } else {
+ if (request.status) {
+ PageElements.videoFound.innerHTML = chrome.i18n.getMessage("connectionError") + request.status;
} 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");
+ PageElements.videoFound.innerHTML = chrome.i18n.getMessage("segmentsStillLoading");
}
- } else {
- displayNoVideo();
+
+ PageElements.issueReporterImportExport.classList.remove("hidden");
}
//see if whitelist button should be swapped