Skip to content

Commit

Permalink
Add refresh button to update ported segments
Browse files Browse the repository at this point in the history
  • Loading branch information
hanydd committed Oct 15, 2024
1 parent 1a5fd2f commit 6d845ef
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 2 deletions.
9 changes: 9 additions & 0 deletions public/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,15 @@
"hasbindedPortVideo": {
"message": "已绑定搬运视频:"
},
"refreshPortedSegments": {
"message": "更新绑定视频的片段"
},
"refreshSuccess": {
"message": "更新成功!"
},
"refreshFailed": {
"message": "更新失败!"
},
"enterPortVideoURL": {
"message": "请输入搬运视频地址"
},
Expand Down
1 change: 1 addition & 0 deletions public/content.css
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,7 @@ input::-webkit-inner-spin-button {
}

#bsbDescriptionPortVideoPill .bsbVoteButton {
color: var(--sb-brand-blue);
cursor: pointer;
height: 24px;
padding: 0 3px;
Expand Down
2 changes: 1 addition & 1 deletion public/icons/refresh.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/components/DescriptionPortPillComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface DescriptionPortPillProps {

onSubmitPortVideo: (ytbID: VideoID) => Promise<PortVideo>;
onVote(type: number): Promise<void>;
onRefresh(): Promise<void>;
}

export interface DescriptionPortPillState {
Expand Down Expand Up @@ -61,6 +62,12 @@ export class DescriptionPortPillComponent extends React.Component<DescriptionPor
src={chrome.runtime.getURL("icons/thumbs_down_blue.svg")}
onClick={(e) => this.vote(e, 0)}
></img>
<img
className="bsbVoteButton"
title={chrome.i18n.getMessage("refreshPortedSegments")}
src={chrome.runtime.getURL("icons/refresh.svg")}
onClick={() => this.props.onRefresh()}
></img>
</>
)}
{!this.hasYtbVideo() && (
Expand Down
15 changes: 14 additions & 1 deletion src/render/DesciptionPortPill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { DescriptionPortPillComponent } from "../components/DescriptionPortPillC
import YouTubeLogoButton from "../components/YouTubeLogoButton";
import Config from "../config";
import { getPageLoaded } from "../content";
import { getPortVideoByHash } from "../requests/portVideo";
import { getPortVideoByHash, updatePortedSegments } from "../requests/portVideo";
import { asyncRequestToServer } from "../requests/requests";
import { VideoID } from "../types";
import { waitFor } from "../utils/";
import { waitForElement } from "../utils/dom";
import { getVideoDescriptionFromWindow } from "../utils/injectedScriptMessageUtils";
import { getVideo, getVideoID } from "../utils/video";
import { showMessage } from "./MessageNotice";

const id = "bsbDescriptionContainer";

Expand Down Expand Up @@ -100,6 +101,7 @@ export class DescriptionPortPill {
showYtbVideoButton={Config.config.showPreviewYoutubeButton}
onSubmitPortVideo={(ytbID) => this.submitPortVideo(ytbID)}
onVote={(type) => this.vote(type)}
onRefresh={() => this.updateSegments()}
/>
);

Expand Down Expand Up @@ -208,4 +210,15 @@ export class DescriptionPortPill {
await this.getPortVideo(this.bvID, true);
this.ref.current.setState({ ytbVideoID: this.ytbID, previewYtbID: this.ytbID });
}

private async updateSegments() {
const response = await updatePortedSegments(this.bvID);
if (!response?.ok) {
console.error(response.responseText);
showMessage(chrome.i18n.getMessage("refreshFailed") + response.responseText, "error");
return;
}
this.sponsorsLookup(true, true, true);
showMessage(chrome.i18n.getMessage("refreshSuccess"), "success");
}
}
5 changes: 5 additions & 0 deletions src/requests/portVideo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { VideoID } from "../types";
import { getHash } from "../utils/hash";
import { FetchResponse } from "./background-request-proxy";
import { asyncRequestToServer } from "./requests";

interface RequestOptions {
Expand Down Expand Up @@ -49,3 +50,7 @@ export async function getPortVideoByHash(bvID: VideoID, options: RequestOptions
}
throw response;
}

export async function updatePortedSegments(bvID: VideoID): Promise<FetchResponse> {
return asyncRequestToServer("POST", "/api/updatePortedSegments", { videoID: bvID });
}

0 comments on commit 6d845ef

Please sign in to comment.