From 5efabcdc6245fe4c959f606ea011af5702d78cb1 Mon Sep 17 00:00:00 2001 From: Kuba Orlik Date: Fri, 15 Dec 2023 20:44:19 +0100 Subject: [PATCH] Add offset option --- public/index.html | 30 ++++++++++++++++++++++++++++-- src/browser.ts | 3 ++- src/index.ts | 10 ++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/public/index.html b/public/index.html index 018cc67..ab87c8b 100644 --- a/public/index.html +++ b/public/index.html @@ -7,6 +7,10 @@ display: flex; align-items: center; } + + .hidden { + display: none; + } @@ -14,7 +18,10 @@

Convert podcast chapters

+
@@ -77,5 +100,8 @@
+ diff --git a/src/browser.ts b/src/browser.ts index 5ab6c50..3ee42d3 100644 --- a/src/browser.ts +++ b/src/browser.ts @@ -1,4 +1,5 @@ -import { encoders, parsers } from "."; +import { encoders, parsers, shift_timestamps } from "."; (window as any).parsers = parsers; (window as any).encoders = encoders; +(window as any).shift_timestamps = shift_timestamps; diff --git a/src/index.ts b/src/index.ts index 804a890..e1e0ae7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,6 +5,16 @@ type Timestamp = { title: string; }; +export function shift_timestamps( + timestamps: Timestamp[], + duration: number = 0 +) { + return timestamps.map((ts) => ({ + ...ts, + timestamp: Math.max(0, ts.timestamp + duration), + })); +} + export function parse_audacity(content: string): Timestamp[] { const lines = content.split("\n"); return lines