aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/components/SponsorTimeEditComponent.tsx
diff options
context:
space:
mode:
authorAjay <[email protected]>2022-06-22 18:10:07 -0400
committerAjay <[email protected]>2022-06-22 18:10:07 -0400
commit355572ba0407dbf66f56c775cecc02f889023495 (patch)
treeae259d04001f1aa0f3f0cfced1efa94cecf7ff09 /src/components/SponsorTimeEditComponent.tsx
parent70731e42a54ce58402471b989a90d903ac4e46df (diff)
downloadSponsorBlock-355572ba0407dbf66f56c775cecc02f889023495.tar.gz
SponsorBlock-355572ba0407dbf66f56c775cecc02f889023495.zip
Add warning when chapter name similar to category
Diffstat (limited to 'src/components/SponsorTimeEditComponent.tsx')
-rw-r--r--src/components/SponsorTimeEditComponent.tsx55
1 files changed, 38 insertions, 17 deletions
diff --git a/src/components/SponsorTimeEditComponent.tsx b/src/components/SponsorTimeEditComponent.tsx
index 2260abe3..4a7e354f 100644
--- a/src/components/SponsorTimeEditComponent.tsx
+++ b/src/components/SponsorTimeEditComponent.tsx
@@ -34,6 +34,9 @@ export interface SponsorTimeEditState {
const DEFAULT_CATEGORY = "chooseACategory";
+const categoryNames = CompileConfig.categoryList.filter((name) => name !== "chapter")
+ .map((name) => chrome.i18n.getMessage("category_" + name));
+
class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, SponsorTimeEditState> {
idSuffix: string;
@@ -48,6 +51,7 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
// Used when selecting POI or Full
timesBeforeChanging: number[] = [];
fullVideoWarningShown = false;
+ categoryNameWarningShown = false;
// For description auto-complete
fetchingSuggestions: boolean;
@@ -101,6 +105,7 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
render(): React.ReactElement {
this.checkToShowFullVideoWarning();
+ this.checkToShowChapterWarning();
const style: React.CSSProperties = {
textAlign: "center"
@@ -336,26 +341,29 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
showScrollToEditToolTip(): void {
if (!Config.config.scrollToEditTimeUpdate && document.getElementById("sponsorRectangleTooltip" + "sponsorTimesContainer" + this.idSuffix) === null) {
- this.showToolTip(chrome.i18n.getMessage("SponsorTimeEditScrollNewFeature"), () => { Config.config.scrollToEditTimeUpdate = true });
+ this.showToolTip(chrome.i18n.getMessage("SponsorTimeEditScrollNewFeature"), "scrollToEdit", () => { Config.config.scrollToEditTimeUpdate = true });
}
}
- showToolTip(text: string, buttonFunction?: () => void): boolean {
+ showToolTip(text: string, id: string, buttonFunction?: () => void): boolean {
const element = document.getElementById("sponsorTimesContainer" + this.idSuffix);
- if (element) {
- new RectangleTooltip({
- text,
- referenceNode: element.parentElement,
- prependElement: element,
- timeout: 15,
- bottomOffset: 0 + "px",
- leftOffset: -318 + "px",
- backgroundColor: "rgba(28, 28, 28, 1.0)",
- htmlId: "sponsorTimesContainer" + this.idSuffix,
- buttonFunction,
- fontSize: "14px",
- maxHeight: "200px"
- });
+ if (element) {
+ const htmlId = `sponsorRectangleTooltip${id + this.idSuffix}`;
+ if (!document.getElementById(htmlId)) {
+ new RectangleTooltip({
+ text,
+ referenceNode: element.parentElement,
+ prependElement: element,
+ timeout: 15,
+ bottomOffset: 0 + "px",
+ leftOffset: -318 + "px",
+ backgroundColor: "rgba(28, 28, 28, 1.0)",
+ htmlId,
+ buttonFunction,
+ fontSize: "14px",
+ maxHeight: "200px"
+ });
+ }
return true;
} else {
@@ -370,12 +378,25 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
if (videoPercentage > 0.6 && !this.fullVideoWarningShown
&& (sponsorTime.category === "sponsor" || sponsorTime.category === "selfpromo" || sponsorTime.category === "chooseACategory")) {
- if (this.showToolTip(chrome.i18n.getMessage("fullVideoTooltipWarning"))) {
+ if (this.showToolTip(chrome.i18n.getMessage("fullVideoTooltipWarning"), "fullVideoWarning")) {
this.fullVideoWarningShown = true;
}
}
}
+ checkToShowChapterWarning(): void {
+ const sponsorTime = this.props.contentContainer().sponsorTimesSubmitting[this.props.index];
+
+ if (sponsorTime.actionType === ActionType.Chapter && sponsorTime.description
+ && !this.categoryNameWarningShown
+ && categoryNames.some(
+ (category) => sponsorTime.description.toLowerCase().includes(category.toLowerCase()))) {
+ if (this.showToolTip(chrome.i18n.getMessage("chapterNameTooltipWarning"), "chapterWarning")) {
+ this.categoryNameWarningShown = true;
+ }
+ }
+ }
+
getCategoryOptions(): React.ReactElement[] {
const elements = [(
<option value={DEFAULT_CATEGORY}