mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-06 19:47:04 +03:00
Merge pull request #1019 from FlorianZahn/roundSubmitTimes
unsubmitted segments are initialized rounded to 3 digits
This commit is contained in:
@@ -38,6 +38,9 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
|||||||
|
|
||||||
configUpdateListener: () => void;
|
configUpdateListener: () => void;
|
||||||
|
|
||||||
|
previousSkipType: CategoryActionType;
|
||||||
|
timeBeforeChangingToPOI: number; // Initialized when first selecting POI
|
||||||
|
|
||||||
constructor(props: SponsorTimeEditProps) {
|
constructor(props: SponsorTimeEditProps) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
@@ -46,6 +49,7 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
|||||||
|
|
||||||
this.idSuffix = this.props.idSuffix;
|
this.idSuffix = this.props.idSuffix;
|
||||||
|
|
||||||
|
this.previousSkipType = CategoryActionType.Skippable;
|
||||||
this.state = {
|
this.state = {
|
||||||
editing: false,
|
editing: false,
|
||||||
sponsorTimeEdits: [null, null],
|
sponsorTimeEdits: [null, null],
|
||||||
@@ -274,6 +278,7 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
|||||||
}
|
}
|
||||||
sponsorTimeEdits[index] = utils.getFormattedTime(timeAsNumber, true);
|
sponsorTimeEdits[index] = utils.getFormattedTime(timeAsNumber, true);
|
||||||
if (getCategoryActionType(sponsorTime.category) === CategoryActionType.POI) sponsorTimeEdits[1] = sponsorTimeEdits[0];
|
if (getCategoryActionType(sponsorTime.category) === CategoryActionType.POI) sponsorTimeEdits[1] = sponsorTimeEdits[0];
|
||||||
|
|
||||||
this.setState({sponsorTimeEdits});
|
this.setState({sponsorTimeEdits});
|
||||||
this.saveEditTimes();
|
this.saveEditTimes();
|
||||||
}
|
}
|
||||||
@@ -338,6 +343,7 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (getCategoryActionType(event.target.value as Category) === CategoryActionType.POI) {
|
if (getCategoryActionType(event.target.value as Category) === CategoryActionType.POI) {
|
||||||
|
if (this.previousSkipType === CategoryActionType.Skippable) this.timeBeforeChangingToPOI = utils.getFormattedTimeToSeconds(this.state.sponsorTimeEdits[1]);
|
||||||
this.setTimeTo(1, null);
|
this.setTimeTo(1, null);
|
||||||
this.props.contentContainer().updateEditButtonsOnPlayer();
|
this.props.contentContainer().updateEditButtonsOnPlayer();
|
||||||
|
|
||||||
@@ -345,8 +351,11 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
|||||||
.some((segment, i) => segment.category === event.target.value && i !== this.props.index)) {
|
.some((segment, i) => segment.category === event.target.value && i !== this.props.index)) {
|
||||||
alert(chrome.i18n.getMessage("poiOnlyOneSegment"));
|
alert(chrome.i18n.getMessage("poiOnlyOneSegment"));
|
||||||
}
|
}
|
||||||
|
} else if (getCategoryActionType(event.target.value as Category) === CategoryActionType.Skippable && this.previousSkipType === CategoryActionType.POI) {
|
||||||
|
this.setTimeTo(1, this.timeBeforeChangingToPOI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.previousSkipType = getCategoryActionType(event.target.value as Category);
|
||||||
this.saveEditTimes();
|
this.saveEditTimes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1433,9 +1433,10 @@ function getRealCurrentTime(): number {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function startOrEndTimingNewSegment() {
|
function startOrEndTimingNewSegment() {
|
||||||
|
const roundedTime = Math.round((getRealCurrentTime() + Number.EPSILON) * 1000) / 1000;
|
||||||
if (!isSegmentCreationInProgress()) {
|
if (!isSegmentCreationInProgress()) {
|
||||||
sponsorTimesSubmitting.push({
|
sponsorTimesSubmitting.push({
|
||||||
segment: [getRealCurrentTime()],
|
segment: [roundedTime],
|
||||||
UUID: null,
|
UUID: null,
|
||||||
category: Config.config.defaultCategory,
|
category: Config.config.defaultCategory,
|
||||||
actionType: ActionType.Skip,
|
actionType: ActionType.Skip,
|
||||||
@@ -1445,7 +1446,7 @@ function startOrEndTimingNewSegment() {
|
|||||||
// Finish creating the new segment
|
// Finish creating the new segment
|
||||||
const existingSegment = getIncompleteSegment();
|
const existingSegment = getIncompleteSegment();
|
||||||
const existingTime = existingSegment.segment[0];
|
const existingTime = existingSegment.segment[0];
|
||||||
const currentTime = getRealCurrentTime();
|
const currentTime = roundedTime;
|
||||||
|
|
||||||
// Swap timestamps if the user put the segment end before the start
|
// Swap timestamps if the user put the segment end before the start
|
||||||
existingSegment.segment = [Math.min(existingTime, currentTime), Math.max(existingTime, currentTime)];
|
existingSegment.segment = [Math.min(existingTime, currentTime), Math.max(existingTime, currentTime)];
|
||||||
|
|||||||
Reference in New Issue
Block a user