diff --git a/src/content.ts b/src/content.ts index 48cbfccf..614054f4 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1237,7 +1237,7 @@ function setupCategoryPill() { function setupDescriptionPill() { if (!descriptionPill) { - descriptionPill = new DescriptionPortPill(getPortVideo, sponsorsLookup); + descriptionPill = new DescriptionPortPill(getPortVideo, portVideoVote, sponsorsLookup); } descriptionPill.setupDecription(getVideoID()); } @@ -1261,6 +1261,20 @@ async function getPortVideo(videoId: VideoID, bypassCache = false) { }); } +async function portVideoVote(UUID: string, bvID: VideoID, voteType: number) { + const response = await asyncRequestToServer("POST", "/api/votePort", { + UUID: UUID, + bvID: bvID, + userID: Config.config.userID, + type: voteType, + }); + if (!response?.ok) { + throw response?.responseText ? response.responseText : "投票失败!"; + } + + await getPortVideo(this.bvID, true); +} + async function sponsorsLookup(keepOldSubmissions = true, ignoreServerCache = false, forceUpdatePreviewBar = false) { if (lookupWaiting) return; //there is still no video here diff --git a/src/render/DesciptionPortPill.tsx b/src/render/DesciptionPortPill.tsx index af3cf5fc..1f3f8867 100644 --- a/src/render/DesciptionPortPill.tsx +++ b/src/render/DesciptionPortPill.tsx @@ -21,6 +21,7 @@ export class DescriptionPortPill { portUUID: string; hasDescription: boolean; getPortVideo: (videoId: VideoID, bypassCache?: boolean) => void; + portVideoVote: (UUID: string, bvID: VideoID, voteType: number) => void; sponsorsLookup: (keepOldSubmissions: boolean, ignoreServerCache: boolean, forceUpdatePreviewBar: boolean) => void; inputContainer: HTMLElement; @@ -28,8 +29,13 @@ export class DescriptionPortPill { ref: React.RefObject; root: Root; - constructor(getPortVideo: (videoId: VideoID, bypassCache?: boolean) => void, sponsorsLookup: () => void) { + constructor( + getPortVideo: (videoId: VideoID, bypassCache?: boolean) => void, + portVideoVote: (UUID: string, bvID: VideoID, voteType: number) => void, + sponsorsLookup: () => void + ) { this.getPortVideo = getPortVideo; + this.portVideoVote = portVideoVote; this.sponsorsLookup = sponsorsLookup; } @@ -187,18 +193,7 @@ export class DescriptionPortPill { return; } - const response = await asyncRequestToServer("POST", "/api/votePort", { - UUID: this.portUUID, - bvID: this.bvID, - userID: Config.config.userID, - type: voteType, - }); - if (!response?.ok) { - throw response?.responseText ? response.responseText : "投票失败!"; - } - - await this.getPortVideo(this.bvID, true); - this.ref.current.setState({ ytbVideoID: this.ytbID, previewYtbID: this.ytbID }); + this.portVideoVote(this.portUUID, this.bvID, voteType); } private async updateSegments() {