-
Notifications
You must be signed in to change notification settings - Fork 711
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
69 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
export default function Sentence({ | ||
bvId, | ||
sentence, | ||
}: { | ||
bvId: string; | ||
sentence: string; | ||
}) { | ||
const baseUrl = `https://www.bilibili.com/video/${bvId}`; | ||
|
||
const matchResult = sentence.match(/\s*(\d+\.\d+)(.*)/); | ||
let timestamp: string | undefined; | ||
if (matchResult) { | ||
console.log("========matchResult========", matchResult); | ||
const seconds = Number(matchResult[1]); | ||
const hours = Math.floor(seconds / 3600); | ||
const remainingSeconds = Math.floor(seconds % 3600); | ||
const minutes = Math.floor(remainingSeconds / 60); | ||
const remainingMinutes = Math.floor(remainingSeconds % 60); | ||
if (hours > 0) { | ||
timestamp = `${hours}:${minutes | ||
.toString() | ||
.padStart(2, "0")}:${remainingMinutes.toString().padStart(2, "0")}`; | ||
} else { | ||
timestamp = `${minutes}:${remainingMinutes.toString().padStart(2, "0")}`; | ||
} | ||
|
||
const content = matchResult[2]; | ||
return ( | ||
<li className="mb-2 list-disc"> | ||
<a | ||
href={`${baseUrl}/?t=${encodeURIComponent(timestamp)}`} | ||
className="text-sky-400 hover:text-sky-600" | ||
> | ||
{timestamp} | ||
</a> | ||
{`${content?.startsWith(":") ? content.substring(1) : content}`} | ||
</li> | ||
); | ||
} | ||
return <li className="mb-2 list-disc">{sentence}</li>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const isDev = process.env.NODE_ENV === "development"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters