Skip to content

Commit 51d9edb

Browse files
committed
Add start of visual segment editing
1 parent 76d9a9a commit 51d9edb

File tree

6 files changed

+144
-4
lines changed

6 files changed

+144
-4
lines changed

public/_locales/en/messages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,10 @@
305305
"mute": {
306306
"message": "Mute"
307307
},
308+
"visual": {
309+
"message": "Visual",
310+
"description": "This is the name of the option to create visual obstructions on top of the video to hide logos when a skip doesn't work."
311+
},
308312
"skip_category": {
309313
"message": "Skip {0}?"
310314
},

src/components/SponsorTimeEditComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from "react";
22
import * as CompileConfig from "../../config.json";
33
import Config from "../config";
4-
import { ActionType, ActionTypes, Category, CategoryActionType, ContentContainer, SponsorTime } from "../types";
4+
import { ActionType, Category, CategoryActionType, ContentContainer, SponsorTime } from "../types";
55
import Utils from "../utils";
66
import { getCategoryActionType } from "../utils/categoryUtils";
77
import SubmissionNoticeComponent from "./SubmissionNoticeComponent";
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import * as React from "react";
2+
import Config from "../config";
3+
import { ContentContainer, VisualSegmentInfo } from "../types";
4+
import Utils from "../utils";
5+
6+
7+
const utils = new Utils();
8+
9+
export interface VisualSegmentEditProps {
10+
index: number,
11+
12+
visual: VisualSegmentInfo,
13+
14+
idSuffix: string,
15+
// Contains functions and variables from the content script needed by the skip notice
16+
contentContainer: ContentContainer,
17+
}
18+
19+
export interface VisualSegmentEditState {
20+
21+
}
22+
23+
class VisualSegmentEditComponent extends React.Component<VisualSegmentEditProps, VisualSegmentEditState> {
24+
25+
idSuffix: string;
26+
27+
configUpdateListener: () => void;
28+
29+
constructor(props: VisualSegmentEditProps) {
30+
super(props);
31+
32+
this.idSuffix = this.props.idSuffix;
33+
34+
this.state = {
35+
};
36+
}
37+
38+
componentDidMount(): void {
39+
// Add as a config listener
40+
if (!this.configUpdateListener) {
41+
this.configUpdateListener = () => this.configUpdate();
42+
Config.configListeners.push(this.configUpdate.bind(this));
43+
}
44+
}
45+
46+
componentWillUnmount(): void {
47+
if (this.configUpdateListener) {
48+
Config.configListeners.splice(Config.configListeners.indexOf(this.configUpdate.bind(this)), 1);
49+
}
50+
}
51+
52+
render(): React.ReactElement {
53+
return <>
54+
<span id={`time${this.props.idSuffix}`}>
55+
{utils.getFormattedTime(this.props.visual.time, true)}
56+
</span>
57+
58+
<span>
59+
-
60+
</span>
61+
62+
{this.getBoundsElement()}
63+
64+
<span>
65+
-
66+
</span>
67+
68+
<input
69+
type="checkBox"
70+
onChange={(event) => this.colorUpdated(event)}
71+
value={this.props.visual.color}
72+
/>
73+
74+
<span>
75+
Smooth
76+
</span>
77+
78+
<span>
79+
-
80+
</span>
81+
82+
<input
83+
className="categoryColorTextBox"
84+
type="color"
85+
onChange={(event) => this.colorUpdated(event)}
86+
value={this.props.visual.color}
87+
/>
88+
89+
90+
</>
91+
}
92+
93+
getBoundsElement(): React.ReactElement[] {
94+
const elements: React.ReactElement[] = [];
95+
96+
for (const bound of this.props.visual.bounds) {
97+
elements.push(
98+
<span>
99+
{`${bound[0] * 100}% x ${bound[0] * 100}%, `}
100+
</span>
101+
);
102+
}
103+
104+
return elements;
105+
}
106+
107+
colorUpdated(event: React.ChangeEvent<HTMLInputElement>): void {
108+
this.props.visual.color = event.target.value;
109+
}
110+
111+
configUpdate(): void {
112+
this.forceUpdate();
113+
}
114+
}
115+
116+
export default VisualSegmentEditComponent;

src/js-components/skipButtonControlBar.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ export class SkipButtonControlBar {
4040
this.container.appendChild(this.textContainer);
4141
this.container.addEventListener("click", () => this.toggleSkip());
4242
this.container.addEventListener("mouseenter", () => this.stopTimer());
43+
this.container.addEventListener("mouseenter", () => console.log("mouseenter"));
4344
this.container.addEventListener("mouseleave", () => this.startTimer());
45+
this.container.addEventListener("mouseleave", () => console.log("mouseleave"));
4446
}
4547

4648
getElement(): HTMLElement {

src/types.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,10 @@ export enum CategoryActionType {
5858

5959
export enum ActionType {
6060
Skip = "skip",
61-
Mute = "mute"
61+
Mute = "mute",
62+
Visual = "visual",
6263
}
6364

64-
export const ActionTypes = [ActionType.Skip, ActionType.Mute];
65-
6665
export type SegmentUUID = string & { __segmentUUIDBrand: unknown };
6766
export type Category = string & { __categoryBrand: unknown };
6867

@@ -80,6 +79,16 @@ export interface SponsorTime {
8079

8180
hidden?: SponsorHideType;
8281
source?: SponsorSourceType;
82+
83+
visual: string;
84+
}
85+
86+
export interface VisualSegmentInfo {
87+
time: number;
88+
bounds: [number, number][];
89+
smooth: boolean;
90+
curve: string;
91+
color: string;
8392
}
8493

8594
export interface ScheduledTime extends SponsorTime {

src/utils/visualUtils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { VisualSegmentInfo } from "../types";
2+
3+
export function toSVG(visuals: VisualSegmentInfo[]): string {
4+
throw new Error("Method not implemented.");
5+
}
6+
7+
export function toVisualSegmentInfo(svg: string): VisualSegmentInfo {
8+
throw new Error("Method not implemented.");
9+
}

0 commit comments

Comments
 (0)