Skip to content

Commit

Permalink
Cleanup downloaded segments in app
Browse files Browse the repository at this point in the history
  • Loading branch information
hanydd committed Aug 29, 2024
1 parent 848548c commit c0bd1bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 44 deletions.
4 changes: 1 addition & 3 deletions src/popup/VideoInfo/VideoInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { exportTimes } from "../../utils/exporter";
import PopupSegment from "./PopupSegment";

interface VideoInfoProps {
downloadedTimes: SponsorTime[];

sendTabMessage: (data: Message, callback?) => void;
sendTabMessageAsync: (data: Message) => Promise<unknown>;
copyToClipboard: (text: string) => void;
Expand Down Expand Up @@ -91,7 +89,7 @@ class VideoInfo extends React.Component<VideoInfoProps, VideoInfoState> {
}

private exportSegments() {
this.props.copyToClipboard(exportTimes(this.props.downloadedTimes));
this.props.copyToClipboard(exportTimes(this.state.downloadedTimes));

new GenericNotice(null, "exportCopied", {
title: chrome.i18n.getMessage(`CopiedExclamation`),
Expand Down
50 changes: 9 additions & 41 deletions src/popup/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,6 @@ function app() {
const messageHandler = new MessageHandler();
let port: chrome.runtime.Port = null;

//the start and end time pairs (2d)
let downloadedTimes: SponsorTime[] = [];
function setDownloadedTimes(times: SponsorTime[]) {
downloadedTimes = times;
}
// const [downloadedTimes, setDownloadedTimes] = React.useState<SponsorTime[]>([]);

//current video ID of this tab
function setCurrentVideoID(videoID: VideoID) {
submitBoxRef.current.setState({ currentVideoID: videoID });
}

// Forward click events
if (isEmbed) {
document.addEventListener("keydown", (e) => {
Expand Down Expand Up @@ -129,8 +117,7 @@ function app() {
submitBoxRef.current.showSubmitBox();
controlMenuRef.current.setState({ hasVideo: true });

setDownloadedTimes(request.sponsorTimes ?? []);
displayDownloadedSponsorTimes(downloadedTimes, request.time);
displayDownloadedSponsorTimes(request.sponsorTimes ?? [], request.time);
if (request.found) {
videoInfoRef.current.displayVideoWithMessage();
} else if (request.status == 404 || request.status == 200) {
Expand Down Expand Up @@ -220,32 +207,6 @@ function app() {
port.onMessage.addListener((msg) => onMessage(msg));
}

function updateCurrentTime(currentTime: number) {
// Create a map of segment UUID -> segment object for easy access
const segmentMap: Record<string, SponsorTime> = {};
for (const segment of downloadedTimes) segmentMap[segment.UUID] = segment;

// Iterate over segment elements and update their classes
const segmentList = document.getElementById("issueReporterTimeButtons");
for (const segmentElement of segmentList.children) {
const UUID = segmentElement.getAttribute("data-uuid");
if (UUID == null || segmentMap[UUID] == undefined) continue;

const summaryElement = segmentElement.querySelector("summary");
if (summaryElement == null) continue;

const segment = segmentMap[UUID];
summaryElement.classList.remove("segmentActive", "segmentPassed");
if (currentTime >= segment.segment[0]) {
if (currentTime < segment.segment[1]) {
summaryElement.classList.add("segmentActive");
} else {
summaryElement.classList.add("segmentPassed");
}
}
}
}

function onMessage(msg: PopupMessage) {
switch (msg.message) {
case "time":
Expand All @@ -267,6 +228,14 @@ function app() {
}
}

function setCurrentVideoID(videoID: VideoID) {
submitBoxRef.current.setState({ currentVideoID: videoID });
}

function updateCurrentTime(currentTime: number) {
this.VideoInfo.setState({ currentTime: currentTime });
}

return (
<ConfigProvider theme={{ algorithm: theme.darkAlgorithm }}>
<div id="sponsorblockPopup" className="sponsorBlockPageBody sb-preload">
Expand Down Expand Up @@ -303,7 +272,6 @@ function app() {

<VideoInfo
ref={videoInfoRef}
downloadedTimes={downloadedTimes}
sendTabMessage={sendTabMessage}
sendTabMessageAsync={sendTabMessageAsync}
copyToClipboard={copyToClipboard}
Expand Down

0 comments on commit c0bd1bd

Please sign in to comment.