mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-10 21:47:06 +03:00
Remove extra segment lookup and use lockbyhash lookup
This commit is contained in:
@@ -394,9 +394,9 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
|||||||
submissionChooserColorSelector(index: number): string {
|
submissionChooserColorSelector(index: number): string {
|
||||||
const isDownvote = this.state.actionState == SkipNoticeAction.Downvote;
|
const isDownvote = this.state.actionState == SkipNoticeAction.Downvote;
|
||||||
const isCopyDownvote = this.state.actionState == SkipNoticeAction.CopyDownvote;
|
const isCopyDownvote = this.state.actionState == SkipNoticeAction.CopyDownvote;
|
||||||
const shouldWarnUser: boolean = (isDownvote || isCopyDownvote)
|
const shouldWarnUser = Config.config.isVip && (isDownvote || isCopyDownvote)
|
||||||
&& this.segments[index].locked === true;
|
&& this.segments[index].locked === 1;
|
||||||
return (shouldWarnUser) ? this.lockedColor : this.unselectedColor;
|
return shouldWarnUser ? this.lockedColor : this.unselectedColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
onMouseEnter(): void {
|
onMouseEnter(): void {
|
||||||
@@ -728,7 +728,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
|||||||
return (this.state.actionState === downvoteType) ? this.selectedColor : this.unselectedColor;
|
return (this.state.actionState === downvoteType) ? this.selectedColor : this.unselectedColor;
|
||||||
} else {
|
} else {
|
||||||
// You dont have segment selectors so the lockbutton needs to be colored and cannot be selected.
|
// 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;
|
return Config.config.isVip && this.segments[0].locked === 1 ? this.lockedColor : this.unselectedColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -764,7 +764,6 @@ function lookupVipInformation(id: string): void {
|
|||||||
updateVipInfo().then((isVip) => {
|
updateVipInfo().then((isVip) => {
|
||||||
if (isVip) {
|
if (isVip) {
|
||||||
lockedCategoriesLookup(id);
|
lockedCategoriesLookup(id);
|
||||||
lockedSegmentsLookup()
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -794,24 +793,13 @@ async function updateVipInfo(): Promise<boolean> {
|
|||||||
return Config.config.isVip;
|
return Config.config.isVip;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function lockedSegmentsLookup(): Promise<void> {
|
|
||||||
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<void> {
|
async function lockedCategoriesLookup(id: string): Promise<void> {
|
||||||
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) {
|
if (response.ok) {
|
||||||
try {
|
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)) {
|
if (Array.isArray(categoriesResponse)) {
|
||||||
lockedCategories = categoriesResponse;
|
lockedCategories = categoriesResponse;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ export enum SponsorSourceType {
|
|||||||
export interface SponsorTime {
|
export interface SponsorTime {
|
||||||
segment: [number] | [number, number];
|
segment: [number] | [number, number];
|
||||||
UUID: SegmentUUID;
|
UUID: SegmentUUID;
|
||||||
locked?: boolean;
|
locked?: number;
|
||||||
|
|
||||||
category: Category;
|
category: Category;
|
||||||
actionType: ActionType;
|
actionType: ActionType;
|
||||||
|
|||||||
Reference in New Issue
Block a user