blob: d2d8d2d2f6de8d5df7ade66aba158eec0aae607c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
import Config from "../config";
import { SponsorTime } from "../types";
import { getSkippingText } from "../utils/categoryUtils";
export interface SkipButtonControlBarProps {
skip: (segment: SponsorTime) => void;
}
export class SkipButtonControlBar {
container: HTMLElement;
skipIcon: HTMLImageElement;
textContainer: HTMLElement;
chapterText: HTMLElement;
segment: SponsorTime;
timeout: NodeJS.Timeout;
skip: (segment: SponsorTime) => void;
constructor(props: SkipButtonControlBarProps) {
this.skip = props.skip;
this.container = document.createElement("div");
this.container.classList.add("skipButtonControlBarContainer");
this.container.classList.add("hidden");
this.skipIcon = document.createElement("img");
this.skipIcon.src = chrome.runtime.getURL("icons/skipIcon.svg");
this.skipIcon.classList.add("ytp-button");
this.skipIcon.id = "sbSkipIconControlBarImage";
this.textContainer = document.createElement("div");
this.container.appendChild(this.skipIcon);
this.container.appendChild(this.textContainer);
this.container.addEventListener("click", () => this.onClick());
this.container.addEventListener("mouseenter", () => this.stopTimer());
this.container.addEventListener("mouseleave", () => this.startTimer());
}
attachToPage(): void {
const leftControlsContainer = document.querySelector(".ytp-left-controls");
this.chapterText = document.querySelector(".ytp-chapter-container");
if (!leftControlsContainer.contains(this.container)) {
leftControlsContainer.insertBefore(this.container, this.chapterText);
}
}
enable(segment: SponsorTime): void {
this.segment = segment;
this.chapterText?.classList?.add("hidden");
this.container.classList.remove("hidden");
this.textContainer.innerText = getSkippingText([segment], false);
this.startTimer();
}
stopTimer(): void {
if (this.timeout) clearTimeout(this.timeout);
}
startTimer() {
this.stopTimer();
this.timeout = setTimeout(() => this.disable(), Config.config.skipNoticeDuration * 1000);
}
disable(): void {
this.container.classList.add("hidden");
this.chapterText?.classList?.remove("hidden");
}
onClick(): void {
this.skip(this.segment);
this.disable();
}
}
|