mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-10 05:27:03 +03:00
Update popup when new segments are fetched
This commit is contained in:
@@ -2,13 +2,13 @@ import * as CompileConfig from "../config.json";
|
||||
|
||||
import Config from "./config";
|
||||
import { Registration } from "./types";
|
||||
import Utils from "./utils";
|
||||
import { GenericUtils } from "./utils/genericUtils";
|
||||
|
||||
// Make the config public for debugging purposes
|
||||
|
||||
window.SB = Config;
|
||||
|
||||
import Utils from "./utils";
|
||||
import { GenericUtils } from "./utils/genericUtils";
|
||||
const utils = new Utils({
|
||||
registerFirefoxContentScript,
|
||||
unregisterFirefoxContentScript
|
||||
@@ -106,6 +106,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
||||
return true;
|
||||
}
|
||||
case "time":
|
||||
case "infoUpdated":
|
||||
if (sender.tab) {
|
||||
popupPort[sender.tab.id]?.postMessage(request);
|
||||
}
|
||||
|
||||
@@ -1004,6 +1004,14 @@ async function sponsorsLookup(keepOldSubmissions = true) {
|
||||
?.sort((a, b) => a.segment[0] - b.segment[0]);
|
||||
if (!recievedSegments || !recievedSegments.length) {
|
||||
// return if no video found
|
||||
chrome.runtime.sendMessage({
|
||||
message: "infoUpdated",
|
||||
found: false,
|
||||
status: lastResponseStatus,
|
||||
sponsorTimes: sponsorTimes,
|
||||
time: video.currentTime,
|
||||
onMobileYouTube
|
||||
});
|
||||
retryFetch(404);
|
||||
return;
|
||||
}
|
||||
@@ -1093,6 +1101,16 @@ async function sponsorsLookup(keepOldSubmissions = true) {
|
||||
|
||||
importExistingChapters(true);
|
||||
|
||||
// notify popup of segment changes
|
||||
chrome.runtime.sendMessage({
|
||||
message: "infoUpdated",
|
||||
found: sponsorDataFound,
|
||||
status: lastResponseStatus,
|
||||
sponsorTimes: sponsorTimes,
|
||||
time: video.currentTime,
|
||||
onMobileYouTube
|
||||
});
|
||||
|
||||
if (Config.config.isVip) {
|
||||
lockedCategoriesLookup();
|
||||
}
|
||||
@@ -1138,8 +1156,8 @@ async function lockedCategoriesLookup(): Promise<void> {
|
||||
}
|
||||
|
||||
function retryFetch(errorCode: number): void {
|
||||
if (!Config.config.refetchWhenNotFound) return;
|
||||
sponsorDataFound = false;
|
||||
if (!Config.config.refetchWhenNotFound) return;
|
||||
|
||||
if (retryFetchTimeout) clearTimeout(retryFetchTimeout);
|
||||
if ((errorCode !== 404 && retryCount > 1) || (errorCode !== 404 && retryCount > 10)) {
|
||||
|
||||
@@ -120,4 +120,8 @@ export interface TimeUpdateMessage {
|
||||
time: number;
|
||||
}
|
||||
|
||||
export type PopupMessage = TimeUpdateMessage;
|
||||
export type InfoUpdatedMessage = IsInfoFoundMessageResponse & {
|
||||
message: "infoUpdated";
|
||||
}
|
||||
|
||||
export type PopupMessage = TimeUpdateMessage | InfoUpdatedMessage;
|
||||
|
||||
26
src/popup.ts
26
src/popup.ts
@@ -1,8 +1,21 @@
|
||||
import Config from "./config";
|
||||
|
||||
import Utils from "./utils";
|
||||
import { SponsorTime, SponsorHideType, ActionType, SegmentUUID, SponsorSourceType, StorageChangesObject } from "./types";
|
||||
import { Message, MessageResponse, IsInfoFoundMessageResponse, ImportSegmentsResponse, PopupMessage } from "./messageTypes";
|
||||
import {
|
||||
ActionType,
|
||||
SegmentUUID,
|
||||
SponsorHideType,
|
||||
SponsorSourceType,
|
||||
SponsorTime,
|
||||
StorageChangesObject,
|
||||
} from "./types";
|
||||
import {
|
||||
ImportSegmentsResponse,
|
||||
IsInfoFoundMessageResponse,
|
||||
Message,
|
||||
MessageResponse,
|
||||
PopupMessage,
|
||||
} from "./messageTypes";
|
||||
import { showDonationLink } from "./utils/configUtils";
|
||||
import { AnimationUtils } from "./utils/animationUtils";
|
||||
import { GenericUtils } from "./utils/genericUtils";
|
||||
@@ -11,6 +24,7 @@ import { localizeHtmlPage } from "./utils/pageUtils";
|
||||
import { exportTimes } from "./utils/exporter";
|
||||
import GenericNotice from "./render/GenericNotice";
|
||||
import { noRefreshFetchingChaptersAllowed } from "./utils/licenseKey";
|
||||
|
||||
const utils = new Utils();
|
||||
|
||||
interface MessageListener {
|
||||
@@ -427,13 +441,10 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
||||
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");
|
||||
if (request.sponsorTimes) {
|
||||
displayDownloadedSponsorTimes(request.sponsorTimes, request.time);
|
||||
}
|
||||
} else if (request.status == 404 || request.status == 200) {
|
||||
PageElements.videoFound.innerHTML = chrome.i18n.getMessage("sponsor404");
|
||||
PageElements.issueReporterImportExport.classList.remove("hidden");
|
||||
@@ -1141,6 +1152,9 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
||||
case "time":
|
||||
displayDownloadedSponsorTimes(downloadedTimes, msg.time);
|
||||
break;
|
||||
case "infoUpdated":
|
||||
infoFound(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user