Skip to content

Commit

Permalink
stash
Browse files Browse the repository at this point in the history
  • Loading branch information
hanydd committed Dec 13, 2024
1 parent 49f1804 commit 2cc81a0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
14 changes: 5 additions & 9 deletions src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ function messageListener(
})
);
break;
case "getPortVideo":
sendResponse(portVideo);
break;
case "submitPortVideo":
submitPortVideo(request.ytbID).then((response) => sendResponse(response));
break;
Expand Down Expand Up @@ -1258,14 +1261,8 @@ async function updatePortVideoElements(newPortVideo: PortVideo) {
waitFor(() => descriptionPill).then(() => descriptionPill.setPortVideoData(newPortVideo));

// notify popup of port video changes
chrome.runtime.sendMessage({
message: "infoUpdated",
found: sponsorDataFound,
status: lastResponseStatus,
sponsorTimes: sponsorTimes,
portVideo: newPortVideo,
time: getVideo()?.currentTime ?? 0,
});
console.log("send message to popup", { message: "portVideoUpdated", portVideo: newPortVideo });
chrome.runtime.sendMessage({ message: "portVideoUpdated", portVideo: newPortVideo });
}

async function getPortVideo(videoId: VideoID, bypassCache = false) {
Expand Down Expand Up @@ -1409,7 +1406,6 @@ async function sponsorsLookup(keepOldSubmissions = true, ignoreServerCache = fal
found: sponsorDataFound,
status: lastResponseStatus,
sponsorTimes: sponsorTimes,
portVideo: portVideo,
time: getVideo()?.currentTime ?? 0,
});

Expand Down
12 changes: 11 additions & 1 deletion src/messageTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ interface KeyDownMessage {
metaKey: boolean;
}

interface GetPortVideoMessage {
message: "getPortVideo";
}

interface SubmitPortVideoMessage {
message: "submitPortVideo";
ytbID: string;
Expand All @@ -85,6 +89,7 @@ export type Message = BaseMessage &
| CopyToClipboardMessage
| ImportSegmentsMessage
| KeyDownMessage
| GetPortVideoMessage
| SubmitPortVideoMessage
);

Expand Down Expand Up @@ -153,4 +158,9 @@ export interface VideoChangedPopupMessage {
whitelisted: boolean;
}

export type PopupMessage = TimeUpdateMessage | InfoUpdatedMessage | VideoChangedPopupMessage;
export interface PortVideoUpdateMessage {
message: "portVideoUpdated";
portVideo: PortVideo;
}

export type PopupMessage = TimeUpdateMessage | InfoUpdatedMessage | VideoChangedPopupMessage | PortVideoUpdateMessage;
7 changes: 7 additions & 0 deletions src/popup/PortVideoSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ export class PortVideoSection extends React.Component<PortVideoProps, PortVideoS
this.state = {
portVideo: null,
};
this.props
.sendTabMessageAsync({ message: "getPortVideo" })
.then((portVideo) => this.setState({ portVideo: portVideo as PortVideo }));
}

private inputRef = React.createRef<HTMLInputElement>();

setPortVideo(portVideo: PortVideo): void {
this.setState({ portVideo });
}

private hasPortVideo(): boolean {
return !!this.state.portVideo;
}
Expand Down
8 changes: 6 additions & 2 deletions src/popup/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,17 @@ function app() {
}

function onMessage(msg: PopupMessage) {
console.log("onMessage", msg);
switch (msg.message) {
case "time":
updateCurrentTime(msg.time);
break;
case "infoUpdated":
infoFound(msg);
break;
case "portVideoUpdated":
portVideoRef.current.setPortVideo(msg.portVideo);
break;
case "videoChanged":
setCurrentVideoID(msg.videoID);
updateUnsubmittedSegments();
Expand Down Expand Up @@ -256,7 +260,7 @@ function app() {
</div>
)}

{!Config.config.cleanPopup && (
{/* {!Config.config.cleanPopup && (
<header className={"sbPopupLogo"}>
<img
src="icons/IconSponsorBlocker256px.png"
Expand All @@ -267,7 +271,7 @@ function app() {
/>
<p className="u-mZ">{chrome.i18n.getMessage("fullName")}</p>
</header>
)}
)} */}

<VideoInfo
ref={videoInfoRef}
Expand Down

0 comments on commit 2cc81a0

Please sign in to comment.