mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-10 21:47:06 +03:00
Add partial segments to upload menu
This commit is contained in:
@@ -340,12 +340,7 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
|||||||
deleteTime(): void {
|
deleteTime(): void {
|
||||||
const sponsorTimes = this.props.contentContainer().sponsorTimesSubmitting;
|
const sponsorTimes = this.props.contentContainer().sponsorTimesSubmitting;
|
||||||
const index = this.props.index;
|
const index = this.props.index;
|
||||||
|
const removingIncomplete = sponsorTimes[index].segment.length < 2;
|
||||||
//if it is not a complete sponsor time
|
|
||||||
if (sponsorTimes[index].segment.length < 2) {
|
|
||||||
//update video player
|
|
||||||
this.props.contentContainer().updateEditButtonsOnPlayer();
|
|
||||||
}
|
|
||||||
|
|
||||||
sponsorTimes.splice(index, 1);
|
sponsorTimes.splice(index, 1);
|
||||||
|
|
||||||
@@ -357,13 +352,16 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
|||||||
//if they are all removed
|
//if they are all removed
|
||||||
if (sponsorTimes.length == 0) {
|
if (sponsorTimes.length == 0) {
|
||||||
this.props.submissionNotice.cancel();
|
this.props.submissionNotice.cancel();
|
||||||
|
|
||||||
//update video player
|
|
||||||
this.props.contentContainer().updateEditButtonsOnPlayer();
|
|
||||||
} else {
|
} else {
|
||||||
//update display
|
//update display
|
||||||
this.props.submissionNotice.forceUpdate();
|
this.props.submissionNotice.forceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//if it is not a complete segment, or all are removed
|
||||||
|
if (sponsorTimes.length === 0 || removingIncomplete) {
|
||||||
|
//update video player
|
||||||
|
this.props.contentContainer().updateEditButtonsOnPlayer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
configUpdate(): void {
|
configUpdate(): void {
|
||||||
|
|||||||
@@ -410,7 +410,7 @@ function migrateOldFormats(config: SBConfig) {
|
|||||||
// Otherwise junk data
|
// Otherwise junk data
|
||||||
if (Array.isArray(jsonData)) {
|
if (Array.isArray(jsonData)) {
|
||||||
const oldMap = new Map(jsonData);
|
const oldMap = new Map(jsonData);
|
||||||
oldMap.forEach((sponsorTimes: number[][], key) => {
|
oldMap.forEach((sponsorTimes: [number, number][], key) => {
|
||||||
const segmentTimes: SponsorTime[] = [];
|
const segmentTimes: SponsorTime[] = [];
|
||||||
for (const segment of sponsorTimes) {
|
for (const segment of sponsorTimes) {
|
||||||
segmentTimes.push({
|
segmentTimes.push({
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import Config from "./config";
|
import Config from "./config";
|
||||||
|
|
||||||
import { SponsorTime, IncompleteSponsorTime, CategorySkipOption, VideoID, SponsorHideType, FetchResponse, VideoInfo, StorageChangesObject } from "./types";
|
import { SponsorTime, CategorySkipOption, VideoID, SponsorHideType, FetchResponse, VideoInfo, StorageChangesObject } from "./types";
|
||||||
|
|
||||||
import { ContentContainer } from "./types";
|
import { ContentContainer } from "./types";
|
||||||
import Utils from "./utils";
|
import Utils from "./utils";
|
||||||
@@ -84,9 +84,6 @@ utils.wait(() => Config.config !== null, 1000, 1).then(() => videoIDChange(getYo
|
|||||||
//this only happens if there is an error
|
//this only happens if there is an error
|
||||||
let sponsorLookupRetries = 0;
|
let sponsorLookupRetries = 0;
|
||||||
|
|
||||||
/** Currently timed segment, which will be added to the unsubmitted segments when ready. */
|
|
||||||
let currentlyTimedSegment: IncompleteSponsorTime | null = null;
|
|
||||||
|
|
||||||
/** Segments created by the user which have not yet been submitted. */
|
/** Segments created by the user which have not yet been submitted. */
|
||||||
let sponsorTimesSubmitting: SponsorTime[] = [];
|
let sponsorTimesSubmitting: SponsorTime[] = [];
|
||||||
|
|
||||||
@@ -136,7 +133,7 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
|
|||||||
startOrEndTimingNewSegment()
|
startOrEndTimingNewSegment()
|
||||||
|
|
||||||
sendResponse({
|
sendResponse({
|
||||||
creatingSegment: currentlyTimedSegment !== null,
|
creatingSegment: isSegmentCreationInProgress(),
|
||||||
});
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -157,7 +154,7 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
|
|||||||
case "getVideoID":
|
case "getVideoID":
|
||||||
sendResponse({
|
sendResponse({
|
||||||
videoID: sponsorVideoID,
|
videoID: sponsorVideoID,
|
||||||
creatingSegment: currentlyTimedSegment !== null,
|
creatingSegment: isSegmentCreationInProgress(),
|
||||||
});
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -305,7 +302,6 @@ async function videoIDChange(id) {
|
|||||||
|
|
||||||
// Clear unsubmitted segments from the previous video
|
// Clear unsubmitted segments from the previous video
|
||||||
sponsorTimesSubmitting = [];
|
sponsorTimesSubmitting = [];
|
||||||
currentlyTimedSegment = null;
|
|
||||||
updateSponsorTimesSubmitting();
|
updateSponsorTimesSubmitting();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1144,7 +1140,7 @@ function updateEditButtonsOnPlayer(): void {
|
|||||||
|
|
||||||
// Only check if buttons should be visible if they're enabled
|
// Only check if buttons should be visible if they're enabled
|
||||||
if (buttonsEnabled) {
|
if (buttonsEnabled) {
|
||||||
creatingSegment = currentlyTimedSegment !== null;
|
creatingSegment = isSegmentCreationInProgress();
|
||||||
|
|
||||||
// Show only if there are any segments to submit
|
// Show only if there are any segments to submit
|
||||||
submitButtonVisible = sponsorTimesSubmitting.length > 0;
|
submitButtonVisible = sponsorTimesSubmitting.length > 0;
|
||||||
@@ -1190,41 +1186,49 @@ function getRealCurrentTime(): number {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function startOrEndTimingNewSegment() {
|
function startOrEndTimingNewSegment() {
|
||||||
if (!currentlyTimedSegment) {
|
if (!isSegmentCreationInProgress()) {
|
||||||
// Start a new segment
|
sponsorTimesSubmitting.push({
|
||||||
currentlyTimedSegment = {
|
|
||||||
segment: [getRealCurrentTime()],
|
segment: [getRealCurrentTime()],
|
||||||
UUID: null,
|
UUID: null,
|
||||||
category: Config.config.defaultCategory,
|
category: Config.config.defaultCategory,
|
||||||
};
|
});
|
||||||
} else {
|
} else {
|
||||||
// Finish creating the new segment
|
// Finish creating the new segment
|
||||||
const existingTime = currentlyTimedSegment.segment[0];
|
const existingSegment = getIncompleteSegment();
|
||||||
|
const existingTime = existingSegment.segment[0];
|
||||||
const currentTime = getRealCurrentTime();
|
const currentTime = getRealCurrentTime();
|
||||||
|
|
||||||
sponsorTimesSubmitting.push({
|
|
||||||
...currentlyTimedSegment,
|
|
||||||
// Swap timestamps if the user put the segment end before the start
|
// Swap timestamps if the user put the segment end before the start
|
||||||
segment: [Math.min(existingTime, currentTime), Math.max(existingTime, currentTime)],
|
existingSegment.segment = [Math.min(existingTime, currentTime), Math.max(existingTime, currentTime)];
|
||||||
});
|
}
|
||||||
|
|
||||||
currentlyTimedSegment = null;
|
|
||||||
|
|
||||||
// Save the newly created segment
|
// Save the newly created segment
|
||||||
Config.config.segmentTimes.set(sponsorVideoID, sponsorTimesSubmitting);
|
Config.config.segmentTimes.set(sponsorVideoID, sponsorTimesSubmitting);
|
||||||
|
|
||||||
|
updateEditButtonsOnPlayer();
|
||||||
|
updateSponsorTimesSubmitting(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getIncompleteSegment(): SponsorTime {
|
||||||
|
return sponsorTimesSubmitting[sponsorTimesSubmitting.length - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Is the latest submitting segment incomplete */
|
||||||
|
function isSegmentCreationInProgress(): boolean {
|
||||||
|
const segment = getIncompleteSegment();
|
||||||
|
return segment && segment?.segment?.length !== 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelCreatingSegment() {
|
||||||
|
if (isSegmentCreationInProgress()) {
|
||||||
|
sponsorTimesSubmitting.splice(sponsorTimesSubmitting.length - 1, 1);
|
||||||
|
Config.config.segmentTimes.set(sponsorVideoID, sponsorTimesSubmitting);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateEditButtonsOnPlayer();
|
updateEditButtonsOnPlayer();
|
||||||
|
|
||||||
updateSponsorTimesSubmitting(false);
|
updateSponsorTimesSubmitting(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
function cancelCreatingSegment() {
|
|
||||||
currentlyTimedSegment = null;
|
|
||||||
|
|
||||||
updateEditButtonsOnPlayer();
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateSponsorTimesSubmitting(getFromConfig = true) {
|
function updateSponsorTimesSubmitting(getFromConfig = true) {
|
||||||
const segmentTimes = Config.config.segmentTimes.get(sponsorVideoID);
|
const segmentTimes = Config.config.segmentTimes.get(sponsorVideoID);
|
||||||
|
|
||||||
@@ -1500,7 +1504,6 @@ async function sendSubmitMessage() {
|
|||||||
Config.config.segmentTimes.delete(sponsorVideoID);
|
Config.config.segmentTimes.delete(sponsorVideoID);
|
||||||
|
|
||||||
// Add submissions to current sponsors list
|
// Add submissions to current sponsors list
|
||||||
// FIXME: segments from sponsorTimesSubmitting do not contain UUIDs .-.
|
|
||||||
sponsorTimes = (sponsorTimes || []).concat(sponsorTimesSubmitting);
|
sponsorTimes = (sponsorTimes || []).concat(sponsorTimesSubmitting);
|
||||||
|
|
||||||
// Increase contribution count
|
// Increase contribution count
|
||||||
@@ -1511,7 +1514,6 @@ async function sendSubmitMessage() {
|
|||||||
Config.config.submissionCountSinceCategories = Config.config.submissionCountSinceCategories + 1;
|
Config.config.submissionCountSinceCategories = Config.config.submissionCountSinceCategories + 1;
|
||||||
|
|
||||||
// Empty the submitting times
|
// Empty the submitting times
|
||||||
currentlyTimedSegment = null;
|
|
||||||
sponsorTimesSubmitting = [];
|
sponsorTimesSubmitting = [];
|
||||||
|
|
||||||
updatePreviewBar();
|
updatePreviewBar();
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ export enum SponsorHideType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface SponsorTime {
|
export interface SponsorTime {
|
||||||
segment: number[];
|
segment: [number] | [number, number];
|
||||||
UUID: string;
|
UUID: string;
|
||||||
|
|
||||||
category: string;
|
category: string;
|
||||||
@@ -60,10 +60,6 @@ export interface SponsorTime {
|
|||||||
hidden?: SponsorHideType;
|
hidden?: SponsorHideType;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type IncompleteSponsorTime = Omit<SponsorTime, 'segment'> & {
|
|
||||||
segment: [number];
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface PreviewBarOption {
|
export interface PreviewBarOption {
|
||||||
color: string,
|
color: string,
|
||||||
opacity: string
|
opacity: string
|
||||||
|
|||||||
Reference in New Issue
Block a user