diff --git a/src/background.ts b/src/background.ts index 727de34c..55236cec 100644 --- a/src/background.ts +++ b/src/background.ts @@ -145,8 +145,8 @@ async function registerFirefoxContentScript(options: Registration) { ids: [options.id] }).catch(() => []); - if (existingRegistrations.length > 0 - && existingRegistrations[0].matches.every((match) => options.matches.includes(match))) { + if (existingRegistrations && existingRegistrations.length > 0 + && options.matches.every((match) => existingRegistrations[0].matches.includes(match))) { // No need to register another script, already registered return; } @@ -207,27 +207,35 @@ async function submitVote(type: number, UUID: string, category: string) { const typeSection = (type !== undefined) ? "&type=" + type : "&category=" + category; - //publish this vote - const response = await asyncRequestToServer("POST", "/api/voteOnSponsorTime?UUID=" + UUID + "&userID=" + userID + typeSection); - - if (response.ok) { - return { - successType: 1, - responseText: await response.text() - }; - } else if (response.status == 405) { - //duplicate vote - return { - successType: 0, - statusCode: response.status, - responseText: await response.text() - }; - } else { - //error while connect + try { + const response = await asyncRequestToServer("POST", "/api/voteOnSponsorTime?UUID=" + UUID + "&userID=" + userID + typeSection); + + if (response.ok) { + return { + successType: 1, + responseText: await response.text() + }; + } else if (response.status == 405) { + //duplicate vote + return { + successType: 0, + statusCode: response.status, + responseText: await response.text() + }; + } else { + //error while connect + return { + successType: -1, + statusCode: response.status, + responseText: await response.text() + }; + } + } catch (e) { + console.error(e); return { successType: -1, - statusCode: response.status, - responseText: await response.text() + statusCode: -1, + responseText: "" }; } } diff --git a/src/components/SubmissionNoticeComponent.tsx b/src/components/SubmissionNoticeComponent.tsx index 7ddc3e0e..2cf394f1 100644 --- a/src/components/SubmissionNoticeComponent.tsx +++ b/src/components/SubmissionNoticeComponent.tsx @@ -14,7 +14,7 @@ export interface SubmissionNoticeProps { // Contains functions and variables from the content script needed by the skip notice contentContainer: ContentContainer; - callback: () => unknown; + callback: () => Promise; closeListener: () => void; } @@ -239,9 +239,11 @@ class SubmissionNoticeComponent extends React.Component { + if (success) { + this.cancel(); + } + }); } sortSegments(): void { diff --git a/src/content.ts b/src/content.ts index 113dcb95..4079018b 100644 --- a/src/content.ts +++ b/src/content.ts @@ -674,6 +674,7 @@ function getVirtualTime(): number { function inMuteSegment(currentTime: number, includeOverlap: boolean): boolean { const checkFunction = (segment) => segment.actionType === ActionType.Mute + && segment.hidden === SponsorHideType.Visible && segment.segment[0] <= currentTime && (segment.segment[1] > currentTime || (includeOverlap && segment.segment[1] + 0.02 > currentTime)); return sponsorTimes?.some(checkFunction) || sponsorTimesSubmitting.some(checkFunction); @@ -2123,13 +2124,13 @@ function submitSegments() { //send the message to the background js //called after all the checks have been made that it's okay to do so -async function sendSubmitMessage() { +async function sendSubmitMessage(): Promise { // check if all segments are full video const onlyFullVideo = sponsorTimesSubmitting.every((segment) => segment.actionType === ActionType.Full); // Block if submitting on a running livestream or premiere if (!onlyFullVideo && (getIsLivePremiere() || isVisible(document.querySelector(".ytp-live-badge")))) { alert(chrome.i18n.getMessage("liveOrPremiere")); - return; + return false; } if (!previewedSegment @@ -2137,7 +2138,7 @@ async function sendSubmitMessage() { [ActionType.Full, ActionType.Poi].includes(segment.actionType) || segment.segment[1] >= getVideo()?.duration)) { alert(`${chrome.i18n.getMessage("previewSegmentRequired")} ${keybindToString(Config.config.previewKeybind)}`); - return; + return false; } // Add loading animation @@ -2163,7 +2164,7 @@ async function sendSubmitMessage() { const confirmShort = chrome.i18n.getMessage("shortCheck") + "\n\n" + getSegmentsMessage(sponsorTimesSubmitting); - if(!confirm(confirmShort)) return; + if(!confirm(confirmShort)) return false; } } } @@ -2213,6 +2214,8 @@ async function sendSubmitMessage() { if (fullVideoSegment) { categoryPill?.setSegment(fullVideoSegment); } + + return true; } else { // Show that the upload failed playerButtons.submit.button.style.animation = "unset"; @@ -2224,6 +2227,8 @@ async function sendSubmitMessage() { alert(getErrorMessage(response.status, response.responseText)); } } + + return false; } //get the message that visually displays the video times @@ -2249,6 +2254,8 @@ function getSegmentsMessage(sponsorTimes: SponsorTime[]): string { } function updateActiveSegment(currentTime: number): void { + previewBar?.updateChapterText(sponsorTimes, sponsorTimesSubmitting, currentTime); + chrome.runtime.sendMessage({ message: "time", time: currentTime diff --git a/src/render/SubmissionNotice.tsx b/src/render/SubmissionNotice.tsx index 5e9fbfbd..c0159cc0 100644 --- a/src/render/SubmissionNotice.tsx +++ b/src/render/SubmissionNotice.tsx @@ -11,7 +11,7 @@ class SubmissionNotice { // Contains functions and variables from the content script needed by the skip notice contentContainer: () => unknown; - callback: () => unknown; + callback: () => Promise; noticeRef: React.MutableRefObject; @@ -19,7 +19,7 @@ class SubmissionNotice { root: Root; - constructor(contentContainer: ContentContainer, callback: () => unknown) { + constructor(contentContainer: ContentContainer, callback: () => Promise) { this.noticeRef = React.createRef(); this.contentContainer = contentContainer;