mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-07 20:17:05 +03:00
Added now button to editor
This commit is contained in:
@@ -483,5 +483,8 @@
|
|||||||
"to": {
|
"to": {
|
||||||
"message": "to",
|
"message": "to",
|
||||||
"description": "Used between sponsor times. Example: 1:20 to 1:30"
|
"description": "Used between sponsor times. Example: 1:20 to 1:30"
|
||||||
|
},
|
||||||
|
"bracketNow": {
|
||||||
|
"message": "(Now)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -351,3 +351,10 @@ input::-webkit-inner-spin-button {
|
|||||||
.sponsorTimeEditSeconds {
|
.sponsorTimeEditSeconds {
|
||||||
width: 60px;
|
width: 60px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sponsorNowButton {
|
||||||
|
font-size: 11px;
|
||||||
|
|
||||||
|
cursor: pointer;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
@@ -19,7 +19,7 @@ export interface SponsorTimeEditProps {
|
|||||||
|
|
||||||
export interface SponsorTimeEditState {
|
export interface SponsorTimeEditState {
|
||||||
editing: boolean;
|
editing: boolean;
|
||||||
sponsorTimeEdits: Array<Array<number>>;
|
sponsorTimeEdits: number[][];
|
||||||
}
|
}
|
||||||
|
|
||||||
class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, SponsorTimeEditState> {
|
class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, SponsorTimeEditState> {
|
||||||
@@ -61,6 +61,13 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
|||||||
timeDisplay = (
|
timeDisplay = (
|
||||||
<div id={"sponsorTimesContainer" + this.idSuffix}
|
<div id={"sponsorTimesContainer" + this.idSuffix}
|
||||||
className="sponsorTimeDisplay">
|
className="sponsorTimeDisplay">
|
||||||
|
|
||||||
|
<span id={"nowButton0" + this.idSuffix}
|
||||||
|
className="sponsorNowButton"
|
||||||
|
onClick={(() => this.setTimeToNow.bind(this)(0)).bind(this)}>
|
||||||
|
{chrome.i18n.getMessage("bracketNow")}
|
||||||
|
</span>
|
||||||
|
|
||||||
<input id={"submittingTimeMinutes0" + this.idSuffix}
|
<input id={"submittingTimeMinutes0" + this.idSuffix}
|
||||||
className="sponsorTimeEdit sponsorTimeEditMinutes"
|
className="sponsorTimeEdit sponsorTimeEditMinutes"
|
||||||
type="number"
|
type="number"
|
||||||
@@ -112,12 +119,19 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
|||||||
this.setState({sponsorTimeEdits});
|
this.setState({sponsorTimeEdits});
|
||||||
}}>
|
}}>
|
||||||
</input>
|
</input>
|
||||||
|
|
||||||
|
<span id={"nowButton1" + this.idSuffix}
|
||||||
|
className="sponsorNowButton"
|
||||||
|
onClick={(() => this.setTimeToNow.bind(this)(1)).bind(this)}>
|
||||||
|
{chrome.i18n.getMessage("bracketNow")}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
timeDisplay = (
|
timeDisplay = (
|
||||||
<div id={"sponsorTimesContainer" + this.idSuffix}
|
<div id={"sponsorTimesContainer" + this.idSuffix}
|
||||||
className="sponsorTimeDisplay">
|
className="sponsorTimeDisplay"
|
||||||
|
onClick={this.toggleEditTime.bind(this)}>
|
||||||
{utils.getFormattedTime(sponsorTime[0], true) +
|
{utils.getFormattedTime(sponsorTime[0], true) +
|
||||||
((sponsorTime.length >= 1) ? " " + chrome.i18n.getMessage("to") + " " + utils.getFormattedTime(sponsorTime[1], true) : "")}
|
((sponsorTime.length >= 1) ? " " + chrome.i18n.getMessage("to") + " " + utils.getFormattedTime(sponsorTime[1], true) : "")}
|
||||||
</div>
|
</div>
|
||||||
@@ -154,6 +168,17 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setTimeToNow(index: number) {
|
||||||
|
let sponsorTime = this.props.contentContainer().sponsorTimesSubmitting[this.props.index];
|
||||||
|
|
||||||
|
sponsorTime[index] =
|
||||||
|
this.props.contentContainer().v.currentTime;
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
sponsorTimeEdits: this.getFormattedSponsorTimesEdits(sponsorTime)
|
||||||
|
}, this.saveEditTimes);
|
||||||
|
}
|
||||||
|
|
||||||
toggleEditTime(): void {
|
toggleEditTime(): void {
|
||||||
if (this.state.editing) {
|
if (this.state.editing) {
|
||||||
|
|
||||||
@@ -167,12 +192,17 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
|||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
editing: true,
|
editing: true,
|
||||||
sponsorTimeEdits: [[utils.getFormattedMinutes(sponsorTime[0]), utils.getFormattedSeconds(sponsorTime[0])],
|
sponsorTimeEdits: this.getFormattedSponsorTimesEdits(sponsorTime)
|
||||||
[utils.getFormattedMinutes(sponsorTime[1]), utils.getFormattedSeconds(sponsorTime[1])]]
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns an array in the sponsorTimeEdits form (minutes and seconds) from a normal seconds sponsor time */
|
||||||
|
getFormattedSponsorTimesEdits(sponsorTime: number[]): number[][] {
|
||||||
|
return [[utils.getFormattedMinutes(sponsorTime[0]), utils.getFormattedSeconds(sponsorTime[0])],
|
||||||
|
[utils.getFormattedMinutes(sponsorTime[1]), utils.getFormattedSeconds(sponsorTime[1])]]
|
||||||
|
}
|
||||||
|
|
||||||
saveEditTimes() {
|
saveEditTimes() {
|
||||||
// Save sponsorTimes
|
// Save sponsorTimes
|
||||||
this.props.contentContainer().sponsorTimesSubmitting[this.props.index] =
|
this.props.contentContainer().sponsorTimesSubmitting[this.props.index] =
|
||||||
|
|||||||
Reference in New Issue
Block a user