mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-12 22:47:18 +03:00
Allow voting on segments right after submitting
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import Config from "./config";
|
import Config from "./config";
|
||||||
|
|
||||||
import { SponsorTime, CategorySkipOption, VideoID, SponsorHideType, FetchResponse, VideoInfo, StorageChangesObject, ChannelIDInfo, ChannelIDStatus } from "./types";
|
import { SponsorTime, CategorySkipOption, VideoID, SponsorHideType, FetchResponse, VideoInfo, StorageChangesObject, ChannelIDInfo, ChannelIDStatus, SponsorSourceType } from "./types";
|
||||||
|
|
||||||
import { ContentContainer } from "./types";
|
import { ContentContainer } from "./types";
|
||||||
import Utils from "./utils";
|
import Utils from "./utils";
|
||||||
@@ -608,7 +608,7 @@ async function sponsorsLookup(id: string) {
|
|||||||
// Check if any old submissions should be kept
|
// Check if any old submissions should be kept
|
||||||
if (sponsorTimes !== null) {
|
if (sponsorTimes !== null) {
|
||||||
for (let i = 0; i < sponsorTimes.length; i++) {
|
for (let i = 0; i < sponsorTimes.length; i++) {
|
||||||
if (sponsorTimes[i].UUID === null) {
|
if (sponsorTimes[i].source === SponsorSourceType.Local) {
|
||||||
// This is a user submission, keep it
|
// This is a user submission, keep it
|
||||||
recievedSegments.push(sponsorTimes[i]);
|
recievedSegments.push(sponsorTimes[i]);
|
||||||
}
|
}
|
||||||
@@ -1282,6 +1282,7 @@ function startOrEndTimingNewSegment() {
|
|||||||
segment: [getRealCurrentTime()],
|
segment: [getRealCurrentTime()],
|
||||||
UUID: null,
|
UUID: null,
|
||||||
category: Config.config.defaultCategory,
|
category: Config.config.defaultCategory,
|
||||||
|
source: SponsorSourceType.Local
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Finish creating the new segment
|
// Finish creating the new segment
|
||||||
@@ -1335,8 +1336,9 @@ function updateSponsorTimesSubmitting(getFromConfig = true) {
|
|||||||
for (const segmentTime of segmentTimes) {
|
for (const segmentTime of segmentTimes) {
|
||||||
sponsorTimesSubmitting.push({
|
sponsorTimesSubmitting.push({
|
||||||
segment: segmentTime.segment,
|
segment: segmentTime.segment,
|
||||||
UUID: null,
|
UUID: segmentTime.UUID,
|
||||||
category: segmentTime.category
|
category: segmentTime.category,
|
||||||
|
source: segmentTime.source
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1602,8 +1604,18 @@ async function sendSubmitMessage() {
|
|||||||
// Remove segments from storage since they've already been submitted
|
// Remove segments from storage since they've already been submitted
|
||||||
Config.config.segmentTimes.delete(sponsorVideoID);
|
Config.config.segmentTimes.delete(sponsorVideoID);
|
||||||
|
|
||||||
|
const newSegments = sponsorTimesSubmitting;
|
||||||
|
try {
|
||||||
|
const recievedNewSegments = JSON.parse(response.responseText);
|
||||||
|
if (recievedNewSegments?.length === newSegments.length) {
|
||||||
|
for (let i = 0; i < recievedNewSegments.length; i++) {
|
||||||
|
newSegments[i].UUID = recievedNewSegments[i].UUID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(e) {} // eslint-disable-line no-empty
|
||||||
|
|
||||||
// Add submissions to current sponsors list
|
// Add submissions to current sponsors list
|
||||||
sponsorTimes = (sponsorTimes || []).concat(sponsorTimesSubmitting);
|
sponsorTimes = (sponsorTimes || []).concat(newSegments);
|
||||||
|
|
||||||
// Increase contribution count
|
// Increase contribution count
|
||||||
Config.config.sponsorTimesContributed = Config.config.sponsorTimesContributed + sponsorTimesSubmitting.length;
|
Config.config.sponsorTimesContributed = Config.config.sponsorTimesContributed + sponsorTimesSubmitting.length;
|
||||||
|
|||||||
@@ -51,6 +51,11 @@ export enum SponsorHideType {
|
|||||||
MinimumDuration
|
MinimumDuration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum SponsorSourceType {
|
||||||
|
Server = undefined,
|
||||||
|
Local = 1
|
||||||
|
}
|
||||||
|
|
||||||
export interface SponsorTime {
|
export interface SponsorTime {
|
||||||
segment: [number] | [number, number];
|
segment: [number] | [number, number];
|
||||||
UUID: string;
|
UUID: string;
|
||||||
@@ -58,6 +63,7 @@ export interface SponsorTime {
|
|||||||
category: string;
|
category: string;
|
||||||
|
|
||||||
hidden?: SponsorHideType;
|
hidden?: SponsorHideType;
|
||||||
|
source?: SponsorSourceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PreviewBarOption {
|
export interface PreviewBarOption {
|
||||||
|
|||||||
Reference in New Issue
Block a user