Skip to content

Commit

Permalink
Added link to place in video
Browse files Browse the repository at this point in the history
  • Loading branch information
lstrzepek committed Jan 10, 2023
1 parent ae216f6 commit 6519c05
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
13 changes: 7 additions & 6 deletions main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-ytranscript",
"name": "YTranscript",
"version": "0.2.0",
"version": "0.3.0",
"minAppVersion": "0.15.0",
"description": "This is simple plugin to fetch transcription for Youtube.",
"author": "Łukasz Strzępek",
Expand Down
12 changes: 7 additions & 5 deletions transcript-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import YoutubeTranscript from "youtube-transcript";
export const TRANSCRIPT_TYPE_VIEW = "transcript-view";
const formatTimestamp = (t: number): string => {
const fnum = (n: number) => (n && n < 10) ? "0" + n.toFixed() : n.toFixed();
const h = 3600 * 1000;
const s = 1000;
const m = 60 * s;
const h = 60 * m;
const hours = Math.floor(t / h);
const m = 60 * 1000;
const minutes = Math.floor((t - hours * h) / m);
const ms = 1000;
const seconds = Math.floor((t - minutes * m) / ms);
const seconds = Math.floor((t - minutes * m) / s);
const time = hours ? [hours, minutes, seconds] : [minutes, seconds];
return time.map(fnum).join(':')
}
Expand Down Expand Up @@ -39,7 +39,9 @@ export class TranscriptView extends ItemView {
if (i % timestampMod == 0) {
div = createEl('div');
const button = createEl('button', { cls: "timestamp", attr: { "data-timestamp": line.offset.toFixed() } });
button.innerText = formatTimestamp(line.offset);
const link = createEl('a', { text: formatTimestamp(line.offset), attr: { "href": url + '&t=' + Math.floor(line.offset / 1000) } });
button.appendChild(link);
// button.innerText = formatTimestamp(line.offset);
const span = this.contentEl.createEl('span', { cls: "transcript-line", text: line.text + " " });
div.appendChild(button);
div.appendChild(span);
Expand Down

0 comments on commit 6519c05

Please sign in to comment.