From 0237af4b07e5f9feb68b193f57cf1f8ce076991c Mon Sep 17 00:00:00 2001 From: HanYaodong Date: Sun, 3 Mar 2024 13:05:53 +0800 Subject: [PATCH] Refractor not on video page in popup --- src/popup.ts | 48 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/src/popup.ts b/src/popup.ts index 879b8b7f..00381e93 100644 --- a/src/popup.ts +++ b/src/popup.ts @@ -441,38 +441,34 @@ async function runThePopup(messageListener?: MessageListener): Promise { stopLoadingAnimation = null; } - if (chrome.runtime.lastError) { - //This page doesn't have the injected content script, or at least not yet + if (chrome.runtime.lastError || request.found == undefined) { + // This page doesn't have the injected content script, or at least not yet + // or if request is undefined, then the page currently being browsed is not Bilibili displayNoVideo(); return; } - // if request is undefined, then the page currently being browsed is not Bilibili - if (request.found != undefined) { - //remove loading text - PageElements.mainControls.style.display = "block"; - 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"; + 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