diff options
author | FlorianZahn <[email protected]> | 2021-10-21 03:14:45 +0200 |
---|---|---|
committer | FlorianZahn <[email protected]> | 2021-10-21 03:14:45 +0200 |
commit | 9dda9a583d5226f532ad620518c702e3598342f1 (patch) | |
tree | 2d9cd2caa2dc67f771abca72a7d8436d77473393 | |
parent | 510db57666708a9cfaf643ac6632efb711a5cdd3 (diff) | |
download | SponsorBlock-9dda9a583d5226f532ad620518c702e3598342f1.tar.gz SponsorBlock-9dda9a583d5226f532ad620518c702e3598342f1.zip |
unsubmitted segments are initialized rounded to 3 digits
-rw-r--r-- | src/components/SponsorTimeEditComponent.tsx | 11 | ||||
-rw-r--r-- | src/content.ts | 5 |
2 files changed, 13 insertions, 3 deletions
diff --git a/src/components/SponsorTimeEditComponent.tsx b/src/components/SponsorTimeEditComponent.tsx index 371228dd..ea09ec6a 100644 --- a/src/components/SponsorTimeEditComponent.tsx +++ b/src/components/SponsorTimeEditComponent.tsx @@ -38,6 +38,9 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo configUpdateListener: () => void; + previousSkipType: CategoryActionType; + timeBeforeChangingToPOI: number; // Initialized when first selecting POI + constructor(props: SponsorTimeEditProps) { super(props); @@ -46,6 +49,7 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo this.idSuffix = this.props.idSuffix; + this.previousSkipType = CategoryActionType.Skippable; this.state = { editing: false, sponsorTimeEdits: [null, null], @@ -275,6 +279,7 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo } sponsorTimeEdits[index] = utils.getFormattedTime(timeAsNumber, true); if (getCategoryActionType(sponsorTime.category) === CategoryActionType.POI) sponsorTimeEdits[1] = sponsorTimeEdits[0]; + this.setState({sponsorTimeEdits}); this.saveEditTimes(); } @@ -339,6 +344,7 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo } if (getCategoryActionType(event.target.value as Category) === CategoryActionType.POI) { + this.timeBeforeChangingToPOI = utils.getFormattedTimeToSeconds(this.state.sponsorTimeEdits[1]); this.setTimeTo(1, null); this.props.contentContainer().updateEditButtonsOnPlayer(); @@ -346,8 +352,11 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo .some((segment, i) => segment.category === event.target.value && i !== this.props.index)) { 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(); } diff --git a/src/content.ts b/src/content.ts index 7eeed429..679f5847 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1459,9 +1459,10 @@ function getRealCurrentTime(): number { } function startOrEndTimingNewSegment() { + const roundedTime = Math.round((getRealCurrentTime() + Number.EPSILON) * 1000) / 1000; if (!isSegmentCreationInProgress()) { sponsorTimesSubmitting.push({ - segment: [getRealCurrentTime()], + segment: [roundedTime], UUID: null, category: Config.config.defaultCategory, actionType: ActionType.Skip, @@ -1471,7 +1472,7 @@ function startOrEndTimingNewSegment() { // Finish creating the new segment const existingSegment = getIncompleteSegment(); const existingTime = existingSegment.segment[0]; - const currentTime = getRealCurrentTime(); + const currentTime = roundedTime; // Swap timestamps if the user put the segment end before the start existingSegment.segment = [Math.min(existingTime, currentTime), Math.max(existingTime, currentTime)]; |