From 93f02877a72288dd369fd852711eedbc0c96d38f Mon Sep 17 00:00:00 2001 From: FlorianZahn Date: Wed, 6 Oct 2021 08:15:15 +0200 Subject: [PATCH 01/33] copy segments basics done --- src/components/SkipNoticeComponent.tsx | 77 +++++++++++++++++--------- src/config.ts | 8 +++ src/content.ts | 7 ++- 3 files changed, 63 insertions(+), 29 deletions(-) diff --git a/src/components/SkipNoticeComponent.tsx b/src/components/SkipNoticeComponent.tsx index 4a5152700f..fefa5040eb 100644 --- a/src/components/SkipNoticeComponent.tsx +++ b/src/components/SkipNoticeComponent.tsx @@ -4,6 +4,7 @@ import Config from "../config" import { Category, ContentContainer, CategoryActionType, SponsorHideType, SponsorTime, NoticeVisbilityMode, ActionType } from "../types"; import NoticeComponent from "./NoticeComponent"; import NoticeTextSelectionComponent from "./NoticeTextSectionComponent"; +import SubmissionNotice from "../render/SubmissionNotice"; import { getCategoryActionType, getSkippingText } from "../utils/categoryUtils"; @@ -12,6 +13,7 @@ export enum SkipNoticeAction { Upvote, Downvote, CategoryVote, + CopyDownvote, Unskip } @@ -203,12 +205,20 @@ class SkipNoticeComponent extends React.Component this.adjustDownvotingState(true)}> + {/* Copy and Downvote Button */} + this.prepAction(SkipNoticeAction.CopyDownvote)}> + : @@ -340,16 +350,6 @@ class SkipNoticeComponent extends React.Component this.forceUpdate(); - Config.configListeners.push(this.configListener); - this.setState({ choosingCategory: true, downvoting: false @@ -531,6 +536,24 @@ class SkipNoticeComponent extends React.Component unknown, ...messages: string[]): void { this.setState({ messages, @@ -557,7 +580,7 @@ class SkipNoticeComponent extends React.Component extends Map { this.update(); return result; } + + addArray(key: T, value: U) { + // Expand an array by value + let result = super.get(key).concat(value); + this.set(key, result); + this.update(); + return result; + } delete(key) { const result = super.delete(key); diff --git a/src/content.ts b/src/content.ts index 89e7893842..b2ea43424f 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1682,8 +1682,11 @@ function resetSponsorSubmissionNotice() { } function submitSponsorTimes() { - if (submissionNotice !== null) return; - + if (submissionNotice !== null){ + submissionNotice.noticeElement.style.display = (submissionNotice.noticeElement.style.display === "none") ? null : "none"; + return; + } + if (sponsorTimesSubmitting !== undefined && sponsorTimesSubmitting.length > 0) { submissionNotice = new SubmissionNotice(skipNoticeContentContainer, sendSubmitMessage); } From 84924b636475167b30c054ca2cb2db1b11661e5a Mon Sep 17 00:00:00 2001 From: FlorianZahn Date: Wed, 6 Oct 2021 08:29:45 +0200 Subject: [PATCH 02/33] Update SkipNoticeComponent.tsx --- src/components/SkipNoticeComponent.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/SkipNoticeComponent.tsx b/src/components/SkipNoticeComponent.tsx index fefa5040eb..eca8ee2304 100644 --- a/src/components/SkipNoticeComponent.tsx +++ b/src/components/SkipNoticeComponent.tsx @@ -545,7 +545,7 @@ class SkipNoticeComponent extends React.Component Date: Wed, 6 Oct 2021 08:31:18 +0200 Subject: [PATCH 03/33] Update config.ts --- src/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.ts b/src/config.ts index b1fc10708f..8390b393a1 100644 --- a/src/config.ts +++ b/src/config.ts @@ -123,7 +123,7 @@ class SBMap extends Map { addArray(key: T, value: U) { // Expand an array by value - let result = super.get(key).concat(value); + const result = super.get(key).concat(value); this.set(key, result); this.update(); return result; From 988905c15500e22c28bfb8c3cfe48708ae848023 Mon Sep 17 00:00:00 2001 From: FlorianZahn Date: Wed, 6 Oct 2021 16:33:11 +0200 Subject: [PATCH 04/33] Update config.ts --- src/config.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/config.ts b/src/config.ts index 8390b393a1..5d8a58e4f6 100644 --- a/src/config.ts +++ b/src/config.ts @@ -120,14 +120,6 @@ class SBMap extends Map { this.update(); return result; } - - addArray(key: T, value: U) { - // Expand an array by value - const result = super.get(key).concat(value); - this.set(key, result); - this.update(); - return result; - } delete(key) { const result = super.delete(key); From 4afc2c153a789454dfb3833694e43a2d24f97989 Mon Sep 17 00:00:00 2001 From: FlorianZahn Date: Wed, 6 Oct 2021 23:02:26 +0200 Subject: [PATCH 05/33] Restart Voting button. Wiki links. SkipNotice Improvements --- public/_locales/en/messages.json | 12 ++ src/components/SkipNoticeComponent.tsx | 171 ++++++++++++++++++------- src/config.ts | 24 ++-- 3 files changed, 154 insertions(+), 53 deletions(-) diff --git a/public/_locales/en/messages.json b/public/_locales/en/messages.json index 5ec3f3e3ac..da70cd4ec0 100644 --- a/public/_locales/en/messages.json +++ b/public/_locales/en/messages.json @@ -810,5 +810,17 @@ }, "LearnMore": { "message": "Learn More" + }, + "CopyDownvoteButtonInfo": { + "message": "Downvotes and creates a local copy for you to resubmit" + }, + "OpenCategoryWikiPage": { + "message": "Open this category's wiki page." + }, + "CopyAndDownvote": { + "message": "Copy and downvote" + }, + "ContinueVoting": { + "message": "Continue Voting" } } diff --git a/src/components/SkipNoticeComponent.tsx b/src/components/SkipNoticeComponent.tsx index fefa5040eb..3ed421c658 100644 --- a/src/components/SkipNoticeComponent.tsx +++ b/src/components/SkipNoticeComponent.tsx @@ -45,7 +45,7 @@ export interface SkipNoticeState { skipButtonCallback?: (index: number) => void; showSkipButton?: boolean; - downvoting?: boolean; + editing?: boolean; choosingCategory?: boolean; thanksForVotingText?: string; //null until the voting buttons should be hidden @@ -117,7 +117,7 @@ class SkipNoticeComponent extends React.Component this.unskip(index), showSkipButton: true, - downvoting: false, + editing: false, choosingCategory: false, thanksForVotingText: null, @@ -208,16 +208,15 @@ class SkipNoticeComponent extends React.Component this.adjustDownvotingState(true)}> - + onClick={() => this.prepAction(SkipNoticeAction.Downvote)}> {/* Copy and Downvote Button */} this.prepAction(SkipNoticeAction.CopyDownvote)}> + title={chrome.i18n.getMessage("CopyDownvoteButtonInfo")} + src={chrome.extension.getURL("icons/pencil.svg")} + onClick={() => this.adjustEditingState(true)}> @@ -226,7 +225,17 @@ class SkipNoticeComponent extends React.Component + + {/* Submitted string */} {this.state.thanksForVotingText} + + {/* Continue Voting Button */} + } @@ -246,16 +255,16 @@ class SkipNoticeComponent extends React.Component), - /* Downvote Options Row */ - (this.state.downvoting && - - + - {/* Normal downvote */} + {/* Copy Segment */} {/* Category vote */} @@ -269,6 +278,8 @@ class SkipNoticeComponent extends React.Component ), + + /* Category Chooser Row */ (this.state.choosingCategory && { if (this.segments.length > 1) { // Use the action selectors as a submit button @@ -445,6 +531,15 @@ class SkipNoticeComponent extends React.Component window.open(wikiLinkText), chrome.i18n.getMessage("OpenCategoryWikiPage")); + this.setState({ + editing: false, + choosingCategory: false, + actionState: SkipNoticeAction.None + }); } // Change the sponsor locally @@ -536,24 +637,6 @@ class SkipNoticeComponent extends React.Component unknown, ...messages: string[]): void { this.setState({ messages, diff --git a/src/config.ts b/src/config.ts index b1fc10708f..e8b64bf212 100644 --- a/src/config.ts +++ b/src/config.ts @@ -43,7 +43,8 @@ interface SBConfig { showDonationLink: boolean, autoHideInfoButton: boolean, autoSkipOnMusicVideos: boolean, - highlightCategoryUpdate: boolean + highlightCategoryUpdate: boolean, + wikiPages: SBMap // What categories should be skipped categorySelections: CategorySelection[], @@ -120,14 +121,6 @@ class SBMap extends Map { this.update(); return result; } - - addArray(key: T, value: U) { - // Expand an array by value - let result = super.get(key).concat(value); - this.set(key, result); - this.update(); - return result; - } delete(key) { const result = super.delete(key); @@ -205,6 +198,19 @@ const Config: SBObject = { option: CategorySkipOption.AutoSkip }], + wikiPages: new SBMap("wikiLinks", [ + ["sponsor", "https://wiki.sponsor.ajay.app/w/Sponsor"], + ["selfpromo", "https://wiki.sponsor.ajay.app/w/Unpaid/Self_Promotion"], + ["interaction", "https://wiki.sponsor.ajay.app/w/Interaction_Reminder_(Subscribe)"], + ["intro", "https://wiki.sponsor.ajay.app/w/Intermission/Intro_Animation"], + ["outro", "https://wiki.sponsor.ajay.app/w/Endcards/Credits"], + ["preview", "https://wiki.sponsor.ajay.app/w/Preview/Recap"], + ["music_offtopic", "https://wiki.sponsor.ajay.app/w/Music:_Non-Music_Section"], + ["highlight_poi", "https://wiki.sponsor.ajay.app/w/Highlight"], + ["guidelines", "https://wiki.sponsor.ajay.app/w/Guidelines"], + ["mute", "https://wiki.sponsor.ajay.app/w/Mute_Segment"], + ]), + // Preview bar barTypes: { "preview-chooseACategory": { From edd10117379969ab050cce74727f56da4738f53f Mon Sep 17 00:00:00 2001 From: FlorianZahn Date: Wed, 6 Oct 2021 23:13:10 +0200 Subject: [PATCH 06/33] margin in ContinueVoting --- src/components/SkipNoticeComponent.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/SkipNoticeComponent.tsx b/src/components/SkipNoticeComponent.tsx index 3ed421c658..fcb2f157e3 100644 --- a/src/components/SkipNoticeComponent.tsx +++ b/src/components/SkipNoticeComponent.tsx @@ -227,7 +227,9 @@ class SkipNoticeComponent extends React.Component {/* Submitted string */} + {this.state.thanksForVotingText} + {/* Continue Voting Button */} @@ -265,14 +269,15 @@ class SkipNoticeComponent extends React.Component this.prepAction(SkipNoticeAction.CopyDownvote)}> - {chrome.i18n.getMessage("CopyAndDownvote")} + {chrome.i18n.getMessage("CopyAndDownvote")} {/* Category vote */} diff --git a/src/config.ts b/src/config.ts index e8b64bf212..433451070a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -44,7 +44,8 @@ interface SBConfig { autoHideInfoButton: boolean, autoSkipOnMusicVideos: boolean, highlightCategoryUpdate: boolean, - wikiPages: SBMap + wikiPages: SBMap, + colorPalette: SBMap // What categories should be skipped categorySelections: CategorySelection[], @@ -211,6 +212,11 @@ const Config: SBObject = { ["mute", "https://wiki.sponsor.ajay.app/w/Mute_Segment"], ]), + colorPalette: new SBMap("colorPalette", [ + ["SponsorBlockRed", "#780303"], + ["SponsorBlockWhite", "#ffffff"] + ]), + // Preview bar barTypes: { "preview-chooseACategory": { diff --git a/src/svg-icons/pencil_svg.tsx b/src/svg-icons/pencil_svg.tsx new file mode 100644 index 0000000000..866f908e6c --- /dev/null +++ b/src/svg-icons/pencil_svg.tsx @@ -0,0 +1,18 @@ +import * as React from "react"; + +const pencilSvg = ({ + fill = "#ffffff" +}) => ( + + + +); + +export default pencilSvg; diff --git a/src/svg-icons/thumbs_down_svg.tsx b/src/svg-icons/thumbs_down_svg.tsx new file mode 100644 index 0000000000..4bb89d792f --- /dev/null +++ b/src/svg-icons/thumbs_down_svg.tsx @@ -0,0 +1,23 @@ +import * as React from "react"; + +const thumbsDownSvg = ({ + fill = "#ffffff" +}) => ( + + + + + +); + +export default thumbsDownSvg; diff --git a/src/svg-icons/thumbs_up_svg.tsx b/src/svg-icons/thumbs_up_svg.tsx new file mode 100644 index 0000000000..8dd77c1cb6 --- /dev/null +++ b/src/svg-icons/thumbs_up_svg.tsx @@ -0,0 +1,22 @@ +import * as React from "react"; + +const thumbsUpSvg = ({ + fill = "#ffffff" +}) => ( + + + + +); + +export default thumbsUpSvg; From 52ed4f73f4e252ea517ca4f1a8e0b0ff41c855f3 Mon Sep 17 00:00:00 2001 From: FlorianZahn Date: Sat, 9 Oct 2021 08:08:46 +0200 Subject: [PATCH 09/33] SkipNotice now remembers what has already been voted. Also nicer highlighting of current selection. --- src/components/SkipNoticeComponent.tsx | 142 +++++++++++++++++-------- src/utils.ts | 6 +- 2 files changed, 102 insertions(+), 46 deletions(-) diff --git a/src/components/SkipNoticeComponent.tsx b/src/components/SkipNoticeComponent.tsx index db0aca15e6..4fadcfb795 100644 --- a/src/components/SkipNoticeComponent.tsx +++ b/src/components/SkipNoticeComponent.tsx @@ -5,6 +5,8 @@ import { Category, ContentContainer, CategoryActionType, SponsorHideType, Sponso import NoticeComponent from "./NoticeComponent"; import NoticeTextSelectionComponent from "./NoticeTextSectionComponent"; import SubmissionNotice from "../render/SubmissionNotice"; +import Utils from "../utils"; +const utils = new Utils(); import { getCategoryActionType, getSkippingText } from "../utils/categoryUtils"; @@ -58,6 +60,10 @@ export interface SkipNoticeState { showKeybindHint?: boolean; smaller?: boolean; + + voted?: SkipNoticeAction[]; + copied?: SkipNoticeAction[]; + } class SkipNoticeComponent extends React.Component { @@ -75,6 +81,9 @@ class SkipNoticeComponent extends React.Component; categoryOptionRef: React.RefObject; + selectedColor: string; + unselectedColor: string; + // Used to update on config change configListener: () => void; @@ -106,6 +115,9 @@ class SkipNoticeComponent extends React.Component this.prepAction(SkipNoticeAction.Upvote)}> - + {/* Report Button */} @@ -211,17 +227,18 @@ class SkipNoticeComponent extends React.Component this.prepAction(SkipNoticeAction.Downvote)}> - + {/* Copy and Downvote Button */}
this.adjustEditingState(true)}> + onClick={() => this.openEditingOptions()}> + this.state.actionState === SkipNoticeAction.CopyDownvote || + this.state.choosingCategory === true) + ? this.selectedColor : this.unselectedColor} />
@@ -240,7 +257,7 @@ class SkipNoticeComponent extends React.Component this.continueVoting()}> + onClick={() => this.resetStateToStart()}> {chrome.i18n.getMessage("ContinueVoting")} @@ -270,6 +287,7 @@ class SkipNoticeComponent extends React.Component this.prepAction(SkipNoticeAction.CopyDownvote)}> {chrome.i18n.getMessage("CopyAndDownvote")} @@ -277,6 +295,7 @@ class SkipNoticeComponent extends React.Component this.openCategoryChooser()}> {chrome.i18n.getMessage("incorrectCategory")} @@ -285,8 +304,6 @@ class SkipNoticeComponent extends React.Component ), - - /* Category Chooser Row */ (this.state.choosingCategory && @@ -348,8 +366,13 @@ class SkipNoticeComponent extends React.Component this.performAction(i)} key={"submission" + i + this.segments[i].category + this.idSuffix}> {(i + 1) + ". " + chrome.i18n.getMessage("category_" + this.segments[i].category)} @@ -399,15 +422,29 @@ class SkipNoticeComponent extends React.Component { if (this.segments.length > 1) { // Use the action selectors as a submit button @@ -538,15 +578,6 @@ class SkipNoticeComponent extends React.Component window.open(wikiLinkText), chrome.i18n.getMessage("OpenCategoryWikiPage")); - this.setState({ - editing: false, - choosingCategory: false, - actionState: SkipNoticeAction.None - }); + const index = this.segments.findIndex(x => x.UUID === segment.UUID); + switch (type) { + case 0: + const wikiLinkText = Config.config.wikiPages.get(segment.category); + this.setNoticeInfoMessageWithOnClick(() => window.open(wikiLinkText), chrome.i18n.getMessage("OpenCategoryWikiPage")); + this.setState({ + voted: utils.replaceArrayElement(this.state.voted, SkipNoticeAction.Downvote, index) + }); + break; + case 1: + this.setState({ + voted: utils.replaceArrayElement(this.state.voted, SkipNoticeAction.Upvote, index) + }); + break; + case 20: + this.setState({ + voted: utils.replaceArrayElement(this.state.voted, SkipNoticeAction.CopyDownvote, index) + }); + break; } + this.addVoteButtonInfo(chrome.i18n.getMessage("voted")); // Change the sponsor locally if (segment) { @@ -639,7 +679,6 @@ class SkipNoticeComponent extends React.Component(array: Type[], value: Type, index: number): Type[] { + array[index] = value; + return array; + } } From 844567dcdf15b5349981053e8e4888dfd6e51071 Mon Sep 17 00:00:00 2001 From: FlorianZahn Date: Sat, 9 Oct 2021 08:13:02 +0200 Subject: [PATCH 10/33] Lit fixes --- src/components/SkipNoticeComponent.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/SkipNoticeComponent.tsx b/src/components/SkipNoticeComponent.tsx index 4fadcfb795..7ad242535c 100644 --- a/src/components/SkipNoticeComponent.tsx +++ b/src/components/SkipNoticeComponent.tsx @@ -651,9 +651,9 @@ class SkipNoticeComponent extends React.Component x.UUID === segment.UUID); + const wikiLinkText = Config.config.wikiPages.get(segment.category); switch (type) { case 0: - const wikiLinkText = Config.config.wikiPages.get(segment.category); this.setNoticeInfoMessageWithOnClick(() => window.open(wikiLinkText), chrome.i18n.getMessage("OpenCategoryWikiPage")); this.setState({ voted: utils.replaceArrayElement(this.state.voted, SkipNoticeAction.Downvote, index) @@ -724,7 +724,7 @@ class SkipNoticeComponent extends React.Component Date: Sun, 10 Oct 2021 00:41:21 +0200 Subject: [PATCH 11/33] Changed heigt of 2nd notice. Minor changes. Upvoting lets downvoted segment reappear --- public/content.css | 2 +- src/components/SkipNoticeComponent.tsx | 100 ++++++++----------------- 2 files changed, 32 insertions(+), 70 deletions(-) diff --git a/public/content.css b/public/content.css index 85a6887a12..f9a6aab67c 100644 --- a/public/content.css +++ b/public/content.css @@ -217,7 +217,7 @@ /* if two are very close to eachother */ .secondSkipNotice { - bottom: 250px; + bottom: 290px; } .noticeLeftIcon { diff --git a/src/components/SkipNoticeComponent.tsx b/src/components/SkipNoticeComponent.tsx index 7ad242535c..775ab42f59 100644 --- a/src/components/SkipNoticeComponent.tsx +++ b/src/components/SkipNoticeComponent.tsx @@ -235,10 +235,10 @@ class SkipNoticeComponent extends React.Component this.openEditingOptions()}> - + @@ -257,7 +257,10 @@ class SkipNoticeComponent extends React.Component this.resetStateToStart()}> + onClick={() => this.setState({ + thanksForVotingText: null, + messages: [] + })}> {chrome.i18n.getMessage("ContinueVoting")} @@ -279,7 +282,7 @@ class SkipNoticeComponent extends React.Component), /* Edit Segments Row */ - (this.state.editing && + (this.state.editing && !this.state.thanksForVotingText && !(this.state.choosingCategory || this.state.actionState === SkipNoticeAction.CopyDownvote) && @@ -287,7 +290,8 @@ class SkipNoticeComponent extends React.Component this.prepAction(SkipNoticeAction.CopyDownvote)}> {chrome.i18n.getMessage("CopyAndDownvote")} @@ -296,16 +300,15 @@ class SkipNoticeComponent extends React.Component this.openCategoryChooser()}> + onClick={() => this.resetStateToStart(SkipNoticeAction.CategoryVote, true, true)}> {chrome.i18n.getMessage("incorrectCategory")} - ), /* Category Chooser Row */ - (this.state.choosingCategory && + (this.state.choosingCategory && !this.state.thanksForVotingText && @@ -326,13 +329,12 @@ class SkipNoticeComponent extends React.Component } - ), /* Segment Chooser Row */ - (this.state.actionState !== SkipNoticeAction.None && + (this.state.actionState !== SkipNoticeAction.None && this.segments.length > 1 && !this.state.thanksForVotingText && @@ -364,11 +366,13 @@ class SkipNoticeComponent extends React.Component { - if (this.segments.length > 1) { - // Use the action selectors as a submit button - this.prepAction(SkipNoticeAction.CategoryVote); - } - }); + this.resetStateToStart(undefined, true); } getCategoryOptions(): React.ReactElement[] { @@ -650,7 +610,7 @@ class SkipNoticeComponent extends React.Component x.UUID === segment.UUID); + const index = utils.getSponsorIndexFromUUID(this.segments, segment.UUID); const wikiLinkText = Config.config.wikiPages.get(segment.category); switch (type) { case 0: @@ -671,13 +631,15 @@ class SkipNoticeComponent extends React.Component Date: Sun, 10 Oct 2021 10:47:47 +0200 Subject: [PATCH 12/33] Vip warning added when downvoting. sry that it is in the same branch, but this is the most current UI --- src/components/SkipNoticeComponent.tsx | 57 ++++++++++++++++------- src/config.ts | 9 +++- src/content.ts | 63 +++++++++++++++++++++++++- src/types.ts | 4 +- 4 files changed, 112 insertions(+), 21 deletions(-) diff --git a/src/components/SkipNoticeComponent.tsx b/src/components/SkipNoticeComponent.tsx index 775ab42f59..eaca2b42e9 100644 --- a/src/components/SkipNoticeComponent.tsx +++ b/src/components/SkipNoticeComponent.tsx @@ -83,6 +83,7 @@ class SkipNoticeComponent extends React.Component void; @@ -117,6 +118,7 @@ class SkipNoticeComponent extends React.Component this.prepAction(SkipNoticeAction.Downvote)}> - + {/* Copy and Downvote Button */} @@ -290,8 +292,7 @@ class SkipNoticeComponent extends React.Component this.prepAction(SkipNoticeAction.CopyDownvote)}> {chrome.i18n.getMessage("CopyAndDownvote")} @@ -315,7 +316,7 @@ class SkipNoticeComponent extends React.Component {this.getCategoryOptions()} @@ -366,27 +367,38 @@ class SkipNoticeComponent extends React.Component this.performAction(i)} key={"submission" + i + this.segments[i].category + this.idSuffix}> {(i + 1) + ". " + chrome.i18n.getMessage("category_" + this.segments[i].category)} ); } - return elements; } + submissionChooserOpacitySelector(index: number): number { + const isUpvote = this.state.actionState === SkipNoticeAction.Upvote; + const isDownvote = this.state.actionState == SkipNoticeAction.Downvote; + const isCopyDownvote = this.state.actionState == SkipNoticeAction.CopyDownvote; + const shouldBeGray: boolean= isUpvote && this.state.voted[index] == SkipNoticeAction.Upvote || + isDownvote && this.state.voted[index] == SkipNoticeAction.Downvote || + isCopyDownvote && this.state.copied[index] == SkipNoticeAction.CopyDownvote; + return shouldBeGray ? 0.35 : 1; + } + + submissionChooserColorSelector(index: number): string { + const isDownvote = this.state.actionState == SkipNoticeAction.Downvote; + const isCopyDownvote = this.state.actionState == SkipNoticeAction.CopyDownvote; + const shouldWarnUser: boolean = (isDownvote || isCopyDownvote) + && this.segments[index].locked === true; + return (shouldWarnUser) ? this.lockedColor : this.unselectedColor; + } + onMouseEnter(): void { if (this.state.smaller) { this.setState({ @@ -541,19 +553,22 @@ class SkipNoticeComponent extends React.Component getCategoryActionType(cat as Category) === CategoryActionType.Skippable)); + const categories = (CompileConfig.categoryList.filter((cat => getCategoryActionType(cat as Category) === CategoryActionType.Skippable))) as Category[]; for (const category of categories) { elements.push( ); } - return elements; } + categoryVoteButtonLockIcon(category: Category): string { + return (this.contentContainer().lockedCategories.includes(category)) ? "🔒" : " "; + } + unskip(index: number): void { this.contentContainer().unskipSponsorTime(this.segments[index], this.props.unskipTime); @@ -699,6 +714,16 @@ class SkipNoticeComponent extends React.Component 1) { + return (this.state.actionState === downvoteType) ? this.selectedColor : this.unselectedColor; + } else { + // You dont have segment selectors so the lockbutton needs to be colored and cannot be selected. + return (this.segments[0].locked === true) ? this.lockedColor : this.unselectedColor; + } + } + private getUnskipText(): string { switch (this.props.segments[0].actionType) { case ActionType.Mute: { diff --git a/src/config.ts b/src/config.ts index 433451070a..f077d8eb5e 100644 --- a/src/config.ts +++ b/src/config.ts @@ -3,7 +3,9 @@ import { Category, CategorySelection, CategorySkipOption, NoticeVisbilityMode, P interface SBConfig { userID: string, - /** Contains unsubmitted segments that the user has created. */ + isVip: boolean, + lastIsVipUpdate: number, + /* Contains unsubmitted segments that the user has created. */ segmentTimes: SBMap, defaultCategory: Category, whitelistedChannels: string[], @@ -153,6 +155,8 @@ const Config: SBObject = { configListeners: [], defaults: { userID: null, + isVip: false, + lastIsVipUpdate: 0, segmentTimes: new SBMap("segmentTimes"), defaultCategory: "chooseACategory" as Category, whitelistedChannels: [], @@ -214,7 +218,8 @@ const Config: SBObject = { colorPalette: new SBMap("colorPalette", [ ["SponsorBlockRed", "#780303"], - ["SponsorBlockWhite", "#ffffff"] + ["SponsorBlockWhite", "#ffffff"], + ["SponsorBlockLocked", "#ffc83d"] ]), // Preview bar diff --git a/src/content.ts b/src/content.ts index b2ea43424f..3fc942d8ad 100644 --- a/src/content.ts +++ b/src/content.ts @@ -34,8 +34,10 @@ let lastPOISkip = 0; // JSON video info let videoInfo: VideoInfo = null; -//the channel this video is about +// The channel this video is about let channelIDInfo: ChannelIDInfo; +// Locked Categories in this tab, like: ["sponsor","intro","outro"] +let lockedCategories: Category[] = []; // Skips are scheduled to ensure precision. // Skips are rescheduled every seeking event. @@ -121,7 +123,8 @@ const skipNoticeContentContainer: ContentContainer = () => ({ updateEditButtonsOnPlayer, previewTime, videoInfo, - getRealCurrentTime: getRealCurrentTime + getRealCurrentTime: getRealCurrentTime, + lockedCategories }); // value determining when to count segment as skipped and send telemetry to server (percent based) @@ -752,6 +755,62 @@ async function sponsorsLookup(id: string, keepOldSubmissions = true) { sponsorLookupRetries++; } + // Look up locked status if the user is a vip + isVipLookup(); + const isVip = Config.config.isVip; + if (isVip) { + lockedCategoriesLookup(id); + lockedSegmentsLookup() + } +} + +async function isVipLookup() { + const currentTime = Date.now(); + const lastUpdate = Config.config.lastIsVipUpdate; + if (currentTime - lastUpdate > 1000*60*60*24) { //max every 24 hours 1000*60*60*24 + Config.config.lastIsVipUpdate = currentTime; + utils.sendRequestToServer("GET", "/api/isUserVIP?userID=" + Config.config.userID, + (response) => { + if (response.status === 200 && response.ok) { + console.log(JSON.parse(response.responseText).vip); + console.log(Config.config.userID); + if (JSON.parse(response.responseText).vip === true) { + Config.config.isVip = true; + } + else Config.config.isVip = false; + } + } + ) + } +} + +async function lockedSegmentsLookup() { + let url = "" + for (let i = 0; i < sponsorTimes.length; i++) { + if (i !== 0) url += ","; + url += `"` + sponsorTimes[i].UUID + `"`; + } + utils.sendRequestToServer("GET", "/api/segmentInfo?UUIDs=[" + url + "]", + (response) => { + if (response.status === 200 && response.ok) { + for (let i = 0; i < sponsorTimes.length && i < 10; i++) { //because the api only return 10 segments maximum + sponsorTimes[i].locked = (JSON.parse(response.responseText)[i].locked === 1) ? true : false; + } + } + } + ) +} + +async function lockedCategoriesLookup(id: string) { + utils.sendRequestToServer("GET", "/api/lockCategories?videoID=" + id, + (response) => { + if (response.status === 200 && response.ok) { + for (const category of JSON.parse(response.responseText).categories) { + lockedCategories.push(category); + } + } + } + ) } function retryFetch(): void { diff --git a/src/types.ts b/src/types.ts index c60e52bb06..4ffdf33f90 100644 --- a/src/types.ts +++ b/src/types.ts @@ -20,7 +20,8 @@ export interface ContentContainer { updateEditButtonsOnPlayer: () => void, previewTime: (time: number, unpause?: boolean) => void, videoInfo: VideoInfo, - getRealCurrentTime: () => number + getRealCurrentTime: () => number, + lockedCategories: string[] } } @@ -74,6 +75,7 @@ export enum SponsorSourceType { export interface SponsorTime { segment: [number] | [number, number]; UUID: SegmentUUID; + locked?: boolean; category: Category; actionType: ActionType; From d72d5dcbcbbdf1e7325a584febd23e17ae88499c Mon Sep 17 00:00:00 2001 From: FlorianZahn Date: Sun, 10 Oct 2021 10:50:35 +0200 Subject: [PATCH 13/33] Lint fixes --- src/content.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content.ts b/src/content.ts index 3fc942d8ad..3ba015eefb 100644 --- a/src/content.ts +++ b/src/content.ts @@ -37,7 +37,7 @@ let videoInfo: VideoInfo = null; // The channel this video is about let channelIDInfo: ChannelIDInfo; // Locked Categories in this tab, like: ["sponsor","intro","outro"] -let lockedCategories: Category[] = []; +const lockedCategories: Category[] = []; // Skips are scheduled to ensure precision. // Skips are rescheduled every seeking event. From b927ebbbf7f9feb38f158681e3bdad37614adaef Mon Sep 17 00:00:00 2001 From: FlorianZahn Date: Sun, 10 Oct 2021 10:56:27 +0200 Subject: [PATCH 14/33] Lint fixes --- src/svg-icons/pencil_svg.tsx | 24 +++++++++++----------- src/svg-icons/thumbs_down_svg.tsx | 34 +++++++++++++++---------------- src/svg-icons/thumbs_up_svg.tsx | 32 ++++++++++++++--------------- 3 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/svg-icons/pencil_svg.tsx b/src/svg-icons/pencil_svg.tsx index 866f908e6c..3ddb81c22c 100644 --- a/src/svg-icons/pencil_svg.tsx +++ b/src/svg-icons/pencil_svg.tsx @@ -2,17 +2,17 @@ import * as React from "react"; const pencilSvg = ({ fill = "#ffffff" -}) => ( - - - -); + }): JSX.Element => ( + + + + ); export default pencilSvg; diff --git a/src/svg-icons/thumbs_down_svg.tsx b/src/svg-icons/thumbs_down_svg.tsx index 4bb89d792f..ce61db5aef 100644 --- a/src/svg-icons/thumbs_down_svg.tsx +++ b/src/svg-icons/thumbs_down_svg.tsx @@ -2,22 +2,22 @@ import * as React from "react"; const thumbsDownSvg = ({ fill = "#ffffff" -}) => ( - - - - - -); + }): JSX.Element => ( + + + + + + ); export default thumbsDownSvg; diff --git a/src/svg-icons/thumbs_up_svg.tsx b/src/svg-icons/thumbs_up_svg.tsx index 8dd77c1cb6..10c95d94d5 100644 --- a/src/svg-icons/thumbs_up_svg.tsx +++ b/src/svg-icons/thumbs_up_svg.tsx @@ -2,21 +2,21 @@ import * as React from "react"; const thumbsUpSvg = ({ fill = "#ffffff" -}) => ( - - - - -); + }): JSX.Element => ( + + + + + ); export default thumbsUpSvg; From aa8ee02277080699cf0587ee2f2064c3cafba057 Mon Sep 17 00:00:00 2001 From: FlorianZahn Date: Mon, 11 Oct 2021 03:49:14 +0200 Subject: [PATCH 15/33] Added colored text if a category is locked for submitting and changing category --- public/content.css | 4 ++++ src/components/SkipNoticeComponent.tsx | 9 +++++---- src/components/SponsorTimeEditComponent.tsx | 11 +++++++++-- src/content.ts | 7 ++++++- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/public/content.css b/public/content.css index f9a6aab67c..785b122e18 100644 --- a/public/content.css +++ b/public/content.css @@ -559,4 +559,8 @@ input::-webkit-inner-spin-button { border-width: 15px; border-style: solid; border-color: rgba(28, 28, 28, 0.7) transparent transparent transparent; +} + +.SponsorBlockLockedColor { + color: #ffc83d; } \ No newline at end of file diff --git a/src/components/SkipNoticeComponent.tsx b/src/components/SkipNoticeComponent.tsx index eaca2b42e9..0f24b7df18 100644 --- a/src/components/SkipNoticeComponent.tsx +++ b/src/components/SkipNoticeComponent.tsx @@ -557,16 +557,17 @@ class SkipNoticeComponent extends React.Component - {this.categoryVoteButtonLockIcon(category) + chrome.i18n.getMessage("category_" + category)} + key={category} + className={this.categoryLockedClass(category)}> + {chrome.i18n.getMessage("category_" + category)} ); } return elements; } - categoryVoteButtonLockIcon(category: Category): string { - return (this.contentContainer().lockedCategories.includes(category)) ? "🔒" : " "; + categoryLockedClass(category: string): string { + return(this.props.contentContainer().lockedCategories.includes(category)) ? "SponsorBlockLockedColor" : "" } unskip(index: number): void { diff --git a/src/components/SponsorTimeEditComponent.tsx b/src/components/SponsorTimeEditComponent.tsx index a442270349..83e526dc8c 100644 --- a/src/components/SponsorTimeEditComponent.tsx +++ b/src/components/SponsorTimeEditComponent.tsx @@ -23,6 +23,7 @@ export interface SponsorTimeEditProps { export interface SponsorTimeEditState { editing: boolean; sponsorTimeEdits: [string, string]; + selectedCategory: Category; } const DEFAULT_CATEGORY = "chooseACategory"; @@ -46,7 +47,8 @@ class SponsorTimeEditComponent extends React.Component + key={category} + className={this.categoryLockedClass(category)}> {chrome.i18n.getMessage("category_" + category)} ); @@ -260,6 +263,10 @@ class SponsorTimeEditComponent extends React.Component): void { // See if show more categories was pressed if (event.target.value !== DEFAULT_CATEGORY && !Config.config.categorySelections.some((category) => category.name === event.target.value)) { diff --git a/src/content.ts b/src/content.ts index 3ba015eefb..2f37cf01ee 100644 --- a/src/content.ts +++ b/src/content.ts @@ -755,6 +755,11 @@ async function sponsorsLookup(id: string, keepOldSubmissions = true) { sponsorLookupRetries++; } + + getVipSegmentsWarnings(id); +} + +function getVipSegmentsWarnings(id: string): void { // Look up locked status if the user is a vip isVipLookup(); const isVip = Config.config.isVip; @@ -767,7 +772,7 @@ async function sponsorsLookup(id: string, keepOldSubmissions = true) { async function isVipLookup() { const currentTime = Date.now(); const lastUpdate = Config.config.lastIsVipUpdate; - if (currentTime - lastUpdate > 1000*60*60*24) { //max every 24 hours 1000*60*60*24 + if (currentTime - lastUpdate > 1) { //max every 24 hours 1000*60*60*24 Config.config.lastIsVipUpdate = currentTime; utils.sendRequestToServer("GET", "/api/isUserVIP?userID=" + Config.config.userID, (response) => { From 60ef51b7f5a2ff58751d7cfea004d53983c9a7bd Mon Sep 17 00:00:00 2001 From: FlorianZahn Date: Mon, 11 Oct 2021 03:50:19 +0200 Subject: [PATCH 16/33] I forgot to change the 24h countdown back to 24h instead of 1 seconds --- src/content.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content.ts b/src/content.ts index 2f37cf01ee..4db051e7b2 100644 --- a/src/content.ts +++ b/src/content.ts @@ -772,7 +772,7 @@ function getVipSegmentsWarnings(id: string): void { async function isVipLookup() { const currentTime = Date.now(); const lastUpdate = Config.config.lastIsVipUpdate; - if (currentTime - lastUpdate > 1) { //max every 24 hours 1000*60*60*24 + if (currentTime - lastUpdate > 1000*60*60*24) { //max every 24 hours 1000*60*60*24 Config.config.lastIsVipUpdate = currentTime; utils.sendRequestToServer("GET", "/api/isUserVIP?userID=" + Config.config.userID, (response) => { From 77ce9433a75efd449fc7624bb0288f5dfedeeee0 Mon Sep 17 00:00:00 2001 From: FlorianZahn Date: Wed, 13 Oct 2021 06:08:14 +0200 Subject: [PATCH 17/33] removed response.ok for response === 200 --- src/content.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content.ts b/src/content.ts index f708e4f451..c6318b2920 100644 --- a/src/content.ts +++ b/src/content.ts @@ -797,7 +797,7 @@ async function lockedSegmentsLookup() { } utils.sendRequestToServer("GET", "/api/segmentInfo?UUIDs=[" + url + "]", (response) => { - if (response.status === 200 && response.ok) { + if (response.status === 200) { for (let i = 0; i < sponsorTimes.length && i < 10; i++) { //because the api only return 10 segments maximum sponsorTimes[i].locked = (JSON.parse(response.responseText)[i].locked === 1) ? true : false; } From af66a77026e7165ebfbd5a310bacc5ca5971a88e Mon Sep 17 00:00:00 2001 From: FlorianZahn Date: Thu, 14 Oct 2021 02:11:15 +0200 Subject: [PATCH 18/33] Fixed logic mistake if undovotes are ever implemented --- src/components/SkipNoticeComponent.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/SkipNoticeComponent.tsx b/src/components/SkipNoticeComponent.tsx index 0f24b7df18..fa61e3393c 100644 --- a/src/components/SkipNoticeComponent.tsx +++ b/src/components/SkipNoticeComponent.tsx @@ -642,7 +642,7 @@ class SkipNoticeComponent extends React.Component Date: Thu, 14 Oct 2021 02:16:04 +0200 Subject: [PATCH 19/33] Removed console.log and redundancy --- src/content.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/content.ts b/src/content.ts index c6318b2920..4d4c965e60 100644 --- a/src/content.ts +++ b/src/content.ts @@ -776,9 +776,7 @@ async function isVipLookup() { Config.config.lastIsVipUpdate = currentTime; utils.sendRequestToServer("GET", "/api/isUserVIP?userID=" + Config.config.userID, (response) => { - if (response.status === 200 && response.ok) { - console.log(JSON.parse(response.responseText).vip); - console.log(Config.config.userID); + if (response.status === 200) { if (JSON.parse(response.responseText).vip === true) { Config.config.isVip = true; } From ff5fa4c724fe292d9d05c6caf712ce910dec4db9 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Wed, 13 Oct 2021 23:14:51 -0400 Subject: [PATCH 20/33] Move config values and close notice --- config.json.example | 12 +++++++++++ src/components/SkipNoticeComponent.tsx | 15 +++++++++---- src/config.ts | 30 +++++++++----------------- src/content.ts | 3 ++- 4 files changed, 35 insertions(+), 25 deletions(-) diff --git a/config.json.example b/config.json.example index ffc482a511..f69160651b 100644 --- a/config.json.example +++ b/config.json.example @@ -12,5 +12,17 @@ "preview": ["skip"], "music_offtopic": ["skip"], "poi_highlight": ["skip"] + }, + "wikiLinks": { + "sponsor": "https://wiki.sponsor.ajay.app/w/Sponsor", + "selfpromo": "https://wiki.sponsor.ajay.app/w/Unpaid/Self_Promotion", + "interaction": "https://wiki.sponsor.ajay.app/w/Interaction_Reminder_(Subscribe)", + "intro": "https://wiki.sponsor.ajay.app/w/Intermission/Intro_Animation", + "outro": "https://wiki.sponsor.ajay.app/w/Endcards/Credits", + "preview": "https://wiki.sponsor.ajay.app/w/Preview/Recap", + "music_offtopic": "https://wiki.sponsor.ajay.app/w/Music:_Non-Music_Section", + "poi_highlight": "https://wiki.sponsor.ajay.app/w/Highlight", + "guidelines": "https://wiki.sponsor.ajay.app/w/Guidelines", + "mute": "https://wiki.sponsor.ajay.app/w/Mute_Segment" } } diff --git a/src/components/SkipNoticeComponent.tsx b/src/components/SkipNoticeComponent.tsx index fa61e3393c..4664ff76bd 100644 --- a/src/components/SkipNoticeComponent.tsx +++ b/src/components/SkipNoticeComponent.tsx @@ -116,9 +116,9 @@ class SkipNoticeComponent extends React.Component window.open(wikiLinkText), chrome.i18n.getMessage("OpenCategoryWikiPage")); this.setState({ voted: utils.replaceArrayElement(this.state.voted, SkipNoticeAction.Downvote, index) }); + break; case 1: this.setState({ voted: utils.replaceArrayElement(this.state.voted, SkipNoticeAction.Upvote, index) }); + break; case 20: this.setState({ voted: utils.replaceArrayElement(this.state.voted, SkipNoticeAction.None, index) }); + break; } + this.addVoteButtonInfo(chrome.i18n.getMessage("voted")); + // Change the sponsor locally if (segment) { if (type === 0) { @@ -657,6 +663,7 @@ class SkipNoticeComponent extends React.Component, - colorPalette: SBMap + colorPalette: { + red: string, + white: string, + locked: string + } // What categories should be skipped categorySelections: CategorySelection[], @@ -203,24 +206,11 @@ const Config: SBObject = { option: CategorySkipOption.AutoSkip }], - wikiPages: new SBMap("wikiLinks", [ - ["sponsor", "https://wiki.sponsor.ajay.app/w/Sponsor"], - ["selfpromo", "https://wiki.sponsor.ajay.app/w/Unpaid/Self_Promotion"], - ["interaction", "https://wiki.sponsor.ajay.app/w/Interaction_Reminder_(Subscribe)"], - ["intro", "https://wiki.sponsor.ajay.app/w/Intermission/Intro_Animation"], - ["outro", "https://wiki.sponsor.ajay.app/w/Endcards/Credits"], - ["preview", "https://wiki.sponsor.ajay.app/w/Preview/Recap"], - ["music_offtopic", "https://wiki.sponsor.ajay.app/w/Music:_Non-Music_Section"], - ["highlight_poi", "https://wiki.sponsor.ajay.app/w/Highlight"], - ["guidelines", "https://wiki.sponsor.ajay.app/w/Guidelines"], - ["mute", "https://wiki.sponsor.ajay.app/w/Mute_Segment"], - ]), - - colorPalette: new SBMap("colorPalette", [ - ["SponsorBlockRed", "#780303"], - ["SponsorBlockWhite", "#ffffff"], - ["SponsorBlockLocked", "#ffc83d"] - ]), + colorPalette: { + red: "#780303", + white: "#ffffff", + locked: "#ffc83d" + }, // Preview bar barTypes: { diff --git a/src/content.ts b/src/content.ts index 4d4c965e60..c6694c3f15 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1746,7 +1746,8 @@ function resetSponsorSubmissionNotice() { function submitSponsorTimes() { if (submissionNotice !== null){ - submissionNotice.noticeElement.style.display = (submissionNotice.noticeElement.style.display === "none") ? null : "none"; + submissionNotice.close(); + submissionNotice = null; return; } From 3e3e9796b1ef2dc1a848f82f370da6534c30ac80 Mon Sep 17 00:00:00 2001 From: FlorianZahn Date: Thu, 14 Oct 2021 05:19:18 +0200 Subject: [PATCH 21/33] syntax error Co-authored-by: Ajay Ramachandran --- src/components/SponsorTimeEditComponent.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/SponsorTimeEditComponent.tsx b/src/components/SponsorTimeEditComponent.tsx index 83e526dc8c..16707c2693 100644 --- a/src/components/SponsorTimeEditComponent.tsx +++ b/src/components/SponsorTimeEditComponent.tsx @@ -263,8 +263,8 @@ class SponsorTimeEditComponent extends React.Component): void { From 9b9174ab9a168bd104ec1f24b2cb874f809b0bd4 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Wed, 13 Oct 2021 23:25:46 -0400 Subject: [PATCH 22/33] Simplify vip info fetching --- src/content.ts | 63 +++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/src/content.ts b/src/content.ts index c6694c3f15..b1204bbe78 100644 --- a/src/content.ts +++ b/src/content.ts @@ -756,12 +756,12 @@ async function sponsorsLookup(id: string, keepOldSubmissions = true) { sponsorLookupRetries++; } - getVipSegmentsWarnings(id); + lookupVipInformation(id); } -function getVipSegmentsWarnings(id: string): void { - // Look up locked status if the user is a vip - isVipLookup(); +function lookupVipInformation(id: string): void { + updateVipInfo(); + const isVip = Config.config.isVip; if (isVip) { lockedCategoriesLookup(id); @@ -769,51 +769,50 @@ function getVipSegmentsWarnings(id: string): void { } } -async function isVipLookup() { +async function updateVipInfo() { const currentTime = Date.now(); const lastUpdate = Config.config.lastIsVipUpdate; - if (currentTime - lastUpdate > 1000*60*60*24) { //max every 24 hours 1000*60*60*24 + if (currentTime - lastUpdate > 1000 * 60 * 60 * 72) { // 72 hours Config.config.lastIsVipUpdate = currentTime; - utils.sendRequestToServer("GET", "/api/isUserVIP?userID=" + Config.config.userID, - (response) => { + + utils.sendRequestToServer("GET", "/api/isUserVIP?userID=" + Config.config.userID, (response) => { if (response.status === 200) { - if (JSON.parse(response.responseText).vip === true) { - Config.config.isVip = true; - } - else Config.config.isVip = false; + let isVip = false; + try { + const vipResponse = JSON.parse(response.responseText)?.vip; + if (typeof(vipResponse) === "boolean") { + isVip = vipResponse; + } + } catch (e) { } //eslint-disable-line no-empty + + Config.config.isVip = isVip; } - } - ) + }); } } async function lockedSegmentsLookup() { - let url = "" - for (let i = 0; i < sponsorTimes.length; i++) { - if (i !== 0) url += ","; - url += `"` + sponsorTimes[i].UUID + `"`; - } - utils.sendRequestToServer("GET", "/api/segmentInfo?UUIDs=[" + url + "]", - (response) => { - if (response.status === 200) { - for (let i = 0; i < sponsorTimes.length && i < 10; i++) { //because the api only return 10 segments maximum + utils.asyncRequestToServer("GET", "/api/segmentInfo", { UUIDs: sponsorTimes?.map((segment) => segment.UUID) }) + .then((response) => { + if (response.status === 200) { + for (let i = 0; i < sponsorTimes.length && i < 10; i++) { // Because the api only return 10 segments maximum + try { sponsorTimes[i].locked = (JSON.parse(response.responseText)[i].locked === 1) ? true : false; - } + } catch (e) { } //eslint-disable-line no-empty } } - ) + }); } async function lockedCategoriesLookup(id: string) { - utils.sendRequestToServer("GET", "/api/lockCategories?videoID=" + id, - (response) => { - if (response.status === 200 && response.ok) { - for (const category of JSON.parse(response.responseText).categories) { - lockedCategories.push(category); - } + utils.asyncRequestToServer("GET", "/api/lockCategories?videoID=" + id) + .then((response) => { + if (response.status === 200 && response.ok) { + for (const category of JSON.parse(response.responseText).categories) { + lockedCategories.push(category); } } - ) + }); } function retryFetch(): void { From 45274f5c7204d1824db751778d1a77259875970c Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Wed, 13 Oct 2021 23:32:52 -0400 Subject: [PATCH 23/33] Wait for vip info to be fetched --- src/content.ts | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/content.ts b/src/content.ts index b1204bbe78..79b166dc51 100644 --- a/src/content.ts +++ b/src/content.ts @@ -760,13 +760,12 @@ async function sponsorsLookup(id: string, keepOldSubmissions = true) { } function lookupVipInformation(id: string): void { - updateVipInfo(); - - const isVip = Config.config.isVip; - if (isVip) { - lockedCategoriesLookup(id); - lockedSegmentsLookup() - } + updateVipInfo().then((isVip) => { + if (isVip) { + lockedCategoriesLookup(id); + lockedSegmentsLookup() + } + }) } async function updateVipInfo() { @@ -775,20 +774,23 @@ async function updateVipInfo() { if (currentTime - lastUpdate > 1000 * 60 * 60 * 72) { // 72 hours Config.config.lastIsVipUpdate = currentTime; - utils.sendRequestToServer("GET", "/api/isUserVIP?userID=" + Config.config.userID, (response) => { - if (response.status === 200) { - let isVip = false; - try { - const vipResponse = JSON.parse(response.responseText)?.vip; - if (typeof(vipResponse) === "boolean") { - isVip = vipResponse; - } - } catch (e) { } //eslint-disable-line no-empty + const response = await utils.asyncRequestToServer("GET", "/api/isUserVIP", { userID: Config.config.userID}); - Config.config.isVip = isVip; - } - }); + if (response.ok) { + let isVip = false; + try { + const vipResponse = JSON.parse(response.responseText)?.vip; + if (typeof(vipResponse) === "boolean") { + isVip = vipResponse; + } + } catch (e) { } //eslint-disable-line no-empty + + Config.config.isVip = isVip; + return isVip; + } } + + return Config.config.isVip; } async function lockedSegmentsLookup() { @@ -805,7 +807,7 @@ async function lockedSegmentsLookup() { } async function lockedCategoriesLookup(id: string) { - utils.asyncRequestToServer("GET", "/api/lockCategories?videoID=" + id) + utils.asyncRequestToServer("GET", "/api/lockCategories", { videoID: id }) .then((response) => { if (response.status === 200 && response.ok) { for (const category of JSON.parse(response.responseText).categories) { From 27f5997e5a297ccb7db06d439dd6dde1f5e6a905 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Wed, 13 Oct 2021 23:34:25 -0400 Subject: [PATCH 24/33] Add return types to vip fetching functions --- src/content.ts | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/content.ts b/src/content.ts index 79b166dc51..e147bd6ddf 100644 --- a/src/content.ts +++ b/src/content.ts @@ -768,7 +768,7 @@ function lookupVipInformation(id: string): void { }) } -async function updateVipInfo() { +async function updateVipInfo(): Promise { const currentTime = Date.now(); const lastUpdate = Config.config.lastIsVipUpdate; if (currentTime - lastUpdate > 1000 * 60 * 60 * 72) { // 72 hours @@ -793,28 +793,26 @@ async function updateVipInfo() { return Config.config.isVip; } -async function lockedSegmentsLookup() { - utils.asyncRequestToServer("GET", "/api/segmentInfo", { UUIDs: sponsorTimes?.map((segment) => segment.UUID) }) - .then((response) => { - if (response.status === 200) { - for (let i = 0; i < sponsorTimes.length && i < 10; i++) { // Because the api only return 10 segments maximum - try { - sponsorTimes[i].locked = (JSON.parse(response.responseText)[i].locked === 1) ? true : false; - } catch (e) { } //eslint-disable-line no-empty - } +async function lockedSegmentsLookup(): Promise { + const response = await utils.asyncRequestToServer("GET", "/api/segmentInfo", { UUIDs: sponsorTimes?.map((segment) => segment.UUID) }); + + if (response.status === 200) { + for (let i = 0; i < sponsorTimes.length && i < 10; i++) { // Because the api only return 10 segments maximum + try { + sponsorTimes[i].locked = (JSON.parse(response.responseText)[i].locked === 1) ? true : false; + } catch (e) { } //eslint-disable-line no-empty } - }); + } } -async function lockedCategoriesLookup(id: string) { - utils.asyncRequestToServer("GET", "/api/lockCategories", { videoID: id }) - .then((response) => { - if (response.status === 200 && response.ok) { - for (const category of JSON.parse(response.responseText).categories) { - lockedCategories.push(category); - } +async function lockedCategoriesLookup(id: string): Promise { + const response = await utils.asyncRequestToServer("GET", "/api/lockCategories", { videoID: id }); + + if (response.status === 200 && response.ok) { + for (const category of JSON.parse(response.responseText).categories) { + lockedCategories.push(category); } - }); + } } function retryFetch(): void { From fc7fc693ed5bc36866d54084f9db669f83aac937 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Wed, 13 Oct 2021 23:57:59 -0400 Subject: [PATCH 25/33] Fix getting locked category --- src/components/SponsorTimeEditComponent.tsx | 2 +- src/content.ts | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/components/SponsorTimeEditComponent.tsx b/src/components/SponsorTimeEditComponent.tsx index 16707c2693..2fcae4080a 100644 --- a/src/components/SponsorTimeEditComponent.tsx +++ b/src/components/SponsorTimeEditComponent.tsx @@ -254,7 +254,7 @@ class SponsorTimeEditComponent extends React.Component + className={this.getCategoryLockedClass(category)}> {chrome.i18n.getMessage("category_" + category)} ); diff --git a/src/content.ts b/src/content.ts index e147bd6ddf..260e9760c6 100644 --- a/src/content.ts +++ b/src/content.ts @@ -37,7 +37,7 @@ let videoInfo: VideoInfo = null; // The channel this video is about let channelIDInfo: ChannelIDInfo; // Locked Categories in this tab, like: ["sponsor","intro","outro"] -const lockedCategories: Category[] = []; +let lockedCategories: Category[] = []; // Skips are scheduled to ensure precision. // Skips are rescheduled every seeking event. @@ -234,6 +234,7 @@ function resetValues() { status: ChannelIDStatus.Fetching, id: null }; + lockedCategories = []; //empty the preview bar if (previewBar !== null) { @@ -808,10 +809,13 @@ async function lockedSegmentsLookup(): Promise { async function lockedCategoriesLookup(id: string): Promise { const response = await utils.asyncRequestToServer("GET", "/api/lockCategories", { videoID: id }); - if (response.status === 200 && response.ok) { - for (const category of JSON.parse(response.responseText).categories) { - lockedCategories.push(category); - } + if (response.ok) { + try { + const categoriesResponse = JSON.parse(response.responseText).categories; + if (Array.isArray(categoriesResponse)) { + lockedCategories = categoriesResponse; + } + } catch (e) { } //eslint-disable-line no-empty } } From 7698be8462c792881950358eed0697d8bb5c92f0 Mon Sep 17 00:00:00 2001 From: FlorianZahn Date: Thu, 14 Oct 2021 07:21:07 +0200 Subject: [PATCH 26/33] Remove merge mistake --- src/config.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/config.ts b/src/config.ts index a685e8d8d9..51c1f06ee5 100644 --- a/src/config.ts +++ b/src/config.ts @@ -46,7 +46,6 @@ interface SBConfig { autoHideInfoButton: boolean, autoSkipOnMusicVideos: boolean, highlightCategoryUpdate: boolean, - copySegment, colorPalette: { red: string, white: string, From a457a8009ec4f9f55199a3b6603cd8bd411a9ba3 Mon Sep 17 00:00:00 2001 From: FlorianZahn Date: Thu, 14 Oct 2021 08:05:55 +0200 Subject: [PATCH 27/33] SkipNotice countdown now updates again on config update --- src/components/SkipNoticeComponent.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/SkipNoticeComponent.tsx b/src/components/SkipNoticeComponent.tsx index 4664ff76bd..b20776b7f1 100644 --- a/src/components/SkipNoticeComponent.tsx +++ b/src/components/SkipNoticeComponent.tsx @@ -631,6 +631,7 @@ class SkipNoticeComponent extends React.Component window.open(wikiLinkText), chrome.i18n.getMessage("OpenCategoryWikiPage")); this.setState({ voted: utils.replaceArrayElement(this.state.voted, SkipNoticeAction.Downvote, index) @@ -694,11 +695,18 @@ class SkipNoticeComponent extends React.Component Date: Thu, 14 Oct 2021 19:05:36 +0200 Subject: [PATCH 28/33] fix loading text not displaying upon voting --- src/components/SkipNoticeComponent.tsx | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/components/SkipNoticeComponent.tsx b/src/components/SkipNoticeComponent.tsx index b20776b7f1..1a0b0f1698 100644 --- a/src/components/SkipNoticeComponent.tsx +++ b/src/components/SkipNoticeComponent.tsx @@ -502,20 +502,17 @@ class SkipNoticeComponent extends React.Component Date: Fri, 15 Oct 2021 00:31:07 -0400 Subject: [PATCH 29/33] Remove extra segment lookup and use lockbyhash lookup --- src/components/SkipNoticeComponent.tsx | 8 ++++---- src/content.ts | 18 +++--------------- src/types.ts | 2 +- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/src/components/SkipNoticeComponent.tsx b/src/components/SkipNoticeComponent.tsx index 4664ff76bd..6aad43dd4d 100644 --- a/src/components/SkipNoticeComponent.tsx +++ b/src/components/SkipNoticeComponent.tsx @@ -394,9 +394,9 @@ class SkipNoticeComponent extends React.Component { if (isVip) { lockedCategoriesLookup(id); - lockedSegmentsLookup() } }) } @@ -794,24 +793,13 @@ async function updateVipInfo(): Promise { return Config.config.isVip; } -async function lockedSegmentsLookup(): Promise { - const response = await utils.asyncRequestToServer("GET", "/api/segmentInfo", { UUIDs: sponsorTimes?.map((segment) => segment.UUID) }); - - if (response.status === 200) { - for (let i = 0; i < sponsorTimes.length && i < 10; i++) { // Because the api only return 10 segments maximum - try { - sponsorTimes[i].locked = (JSON.parse(response.responseText)[i].locked === 1) ? true : false; - } catch (e) { } //eslint-disable-line no-empty - } - } -} - async function lockedCategoriesLookup(id: string): Promise { - const response = await utils.asyncRequestToServer("GET", "/api/lockCategories", { videoID: id }); + const hashPrefix = (await utils.getHash(id, 1)).substr(0, 4); + const response = await utils.asyncRequestToServer("GET", "/api/lockCategories/" + hashPrefix); if (response.ok) { try { - const categoriesResponse = JSON.parse(response.responseText).categories; + const categoriesResponse = JSON.parse(response.responseText).filter((lockInfo) => lockInfo.videoID === id)[0]?.categories; if (Array.isArray(categoriesResponse)) { lockedCategories = categoriesResponse; } diff --git a/src/types.ts b/src/types.ts index 4ffdf33f90..1caf257c27 100644 --- a/src/types.ts +++ b/src/types.ts @@ -75,7 +75,7 @@ export enum SponsorSourceType { export interface SponsorTime { segment: [number] | [number, number]; UUID: SegmentUUID; - locked?: boolean; + locked?: number; category: Category; actionType: ActionType; From fe5499e80a887fd12901183c5b86219fd7a11478 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Fri, 15 Oct 2021 00:56:48 -0400 Subject: [PATCH 30/33] Code style fixes and react errors --- public/content.css | 2 +- src/components/SkipNoticeComponent.tsx | 93 +++++++++++---------- src/components/SponsorTimeEditComponent.tsx | 2 +- src/content.ts | 2 +- src/utils.ts | 5 -- 5 files changed, 52 insertions(+), 52 deletions(-) diff --git a/public/content.css b/public/content.css index 52df956f3f..4751d293b5 100644 --- a/public/content.css +++ b/public/content.css @@ -561,7 +561,7 @@ input::-webkit-inner-spin-button { border-color: rgba(28, 28, 28, 0.7) transparent transparent transparent; } -.SponsorBlockLockedColor { +.sponsorBlockLockedColor { color: #ffc83d; } diff --git a/src/components/SkipNoticeComponent.tsx b/src/components/SkipNoticeComponent.tsx index f83f72c4a0..6d3c378bab 100644 --- a/src/components/SkipNoticeComponent.tsx +++ b/src/components/SkipNoticeComponent.tsx @@ -252,7 +252,7 @@ class SkipNoticeComponent extends React.Component - {this.state.thanksForVotingText} + {this.state.thanksForVotingText} {/* Continue Voting Button */} @@ -370,8 +370,8 @@ class SkipNoticeComponent extends React.Component this.performAction(i)} key={"submission" + i + this.segments[i].category + this.idSuffix}> {(i + 1) + ". " + chrome.i18n.getMessage("category_" + this.segments[i].category)} @@ -381,21 +381,23 @@ class SkipNoticeComponent extends React.Component - + + + className={this.getCategoryNameClass(category)}> {chrome.i18n.getMessage("category_" + category)} ); @@ -563,8 +574,8 @@ class SkipNoticeComponent extends React.Component window.open(wikiLinkText), chrome.i18n.getMessage("OpenCategoryWikiPage")); - this.setState({ - voted: utils.replaceArrayElement(this.state.voted, SkipNoticeAction.Downvote, index) - }); + voted[index] = SkipNoticeAction.Downvote; break; case 1: - this.setState({ - voted: utils.replaceArrayElement(this.state.voted, SkipNoticeAction.Upvote, index) - }); - + voted[index] = SkipNoticeAction.Upvote; break; case 20: - this.setState({ - voted: utils.replaceArrayElement(this.state.voted, SkipNoticeAction.None, index) - }); - + voted[index] = SkipNoticeAction.None; break; } + this.setState({ + voted + }); + this.addVoteButtonInfo(chrome.i18n.getMessage("voted")); // Change the sponsor locally @@ -715,16 +723,13 @@ class SkipNoticeComponent extends React.Component): void { diff --git a/src/content.ts b/src/content.ts index 760baa7c75..7eeed429cc 100644 --- a/src/content.ts +++ b/src/content.ts @@ -765,7 +765,7 @@ function lookupVipInformation(id: string): void { if (isVip) { lockedCategoriesLookup(id); } - }) + }); } async function updateVipInfo(): Promise { diff --git a/src/utils.ts b/src/utils.ts index 6dacf325c0..99d6113713 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -539,9 +539,4 @@ export default class Utils { return hashHex; } - - replaceArrayElement(array: Type[], value: Type, index: number): Type[] { - array[index] = value; - return array; - } } From d375a97e996431963b569fa7d5f5cf6a0dd29abc Mon Sep 17 00:00:00 2001 From: FlorianZahn Date: Fri, 15 Oct 2021 20:52:15 +0200 Subject: [PATCH 31/33] Vip Warning also in popup --- manifest/manifest.json | 1 + public/icons/thumbs_down_locked.svg | 58 +++++++++++++++++++++++++++++ src/popup.ts | 3 +- 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 public/icons/thumbs_down_locked.svg diff --git a/manifest/manifest.json b/manifest/manifest.json index c9350235fb..5f64027753 100644 --- a/manifest/manifest.json +++ b/manifest/manifest.json @@ -37,6 +37,7 @@ "icons/upvote.png", "icons/downvote.png", "icons/thumbs_down.svg", + "icons/thumbs_down_locked.svg", "icons/thumbs_up.svg", "icons/help.svg", "icons/report.png", diff --git a/public/icons/thumbs_down_locked.svg b/public/icons/thumbs_down_locked.svg new file mode 100644 index 0000000000..57672e2df0 --- /dev/null +++ b/public/icons/thumbs_down_locked.svg @@ -0,0 +1,58 @@ + + + + + + image/svg+xml + + + + + + + + + diff --git a/src/popup.ts b/src/popup.ts index 680e07792c..2cdbab0453 100644 --- a/src/popup.ts +++ b/src/popup.ts @@ -381,6 +381,7 @@ async function runThePopup(messageListener?: MessageListener): Promise { for (let i = 0; i < segmentTimes.length; i++) { const UUID = segmentTimes[i].UUID; + const locked = segmentTimes[i].locked; const sponsorTimeButton = document.createElement("button"); sponsorTimeButton.className = "segmentTimeButton popupElement"; @@ -430,7 +431,7 @@ async function runThePopup(messageListener?: MessageListener): Promise { const downvoteButton = document.createElement("img"); downvoteButton.id = "sponsorTimesDownvoteButtonsContainer" + UUID; downvoteButton.className = "voteButton"; - downvoteButton.src = chrome.runtime.getURL("icons/thumbs_down.svg"); + downvoteButton.src = locked ? chrome.runtime.getURL("icons/thumbs_down_locked.svg") : chrome.runtime.getURL("icons/thumbs_down.svg"); downvoteButton.addEventListener("click", () => vote(0, UUID)); //uuid button From 8aea74160c1a596a608207b66ffbcb39cf2ae38a Mon Sep 17 00:00:00 2001 From: FlorianZahn Date: Fri, 15 Oct 2021 21:01:32 +0200 Subject: [PATCH 32/33] only change color if user isVip --- src/popup.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/popup.ts b/src/popup.ts index 2cdbab0453..5a75c8ba33 100644 --- a/src/popup.ts +++ b/src/popup.ts @@ -379,6 +379,7 @@ async function runThePopup(messageListener?: MessageListener): Promise { container.removeChild(container.firstChild); } + const isVip = Config.config.isVip; for (let i = 0; i < segmentTimes.length; i++) { const UUID = segmentTimes[i].UUID; const locked = segmentTimes[i].locked; @@ -431,7 +432,7 @@ async function runThePopup(messageListener?: MessageListener): Promise { const downvoteButton = document.createElement("img"); downvoteButton.id = "sponsorTimesDownvoteButtonsContainer" + UUID; downvoteButton.className = "voteButton"; - downvoteButton.src = locked ? chrome.runtime.getURL("icons/thumbs_down_locked.svg") : chrome.runtime.getURL("icons/thumbs_down.svg"); + downvoteButton.src = locked && isVip ? chrome.runtime.getURL("icons/thumbs_down_locked.svg") : chrome.runtime.getURL("icons/thumbs_down.svg"); downvoteButton.addEventListener("click", () => vote(0, UUID)); //uuid button From 08630616655d91a40b864d9997f0f5975d0e9b6a Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Fri, 15 Oct 2021 18:57:36 -0400 Subject: [PATCH 33/33] Fix indentation in manifest --- manifest/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest/manifest.json b/manifest/manifest.json index 5f64027753..3c49bebf30 100644 --- a/manifest/manifest.json +++ b/manifest/manifest.json @@ -37,7 +37,7 @@ "icons/upvote.png", "icons/downvote.png", "icons/thumbs_down.svg", - "icons/thumbs_down_locked.svg", + "icons/thumbs_down_locked.svg", "icons/thumbs_up.svg", "icons/help.svg", "icons/report.png",