Skip to content

Commit b5b58c3

Browse files
committed
Add timestamp to Redirect/Summary banners with the time they happened (if timestamps are on)
1 parent 1722cfc commit b5b58c3

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

src/components/ChatSummary.svelte

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
import Icon from 'smelte/src/components/Icon';
66
import { Theme } from '../ts/chat-constants';
77
import { createEventDispatcher } from 'svelte';
8+
import { showTimestamps } from '../ts/storage';
89
910
export let summary: Ytc.ParsedSummary;
1011
1112
let dismissed = false;
1213
let shorten = false;
14+
$: actionId = summary?.actionId || '';
15+
$: showtime = summary?.showtime || 0;
1316
let autoHideTimeout: NodeJS.Timeout | null = null;
1417
const classes = 'rounded inline-flex flex-col overflow-visible ' +
1518
'bg-secondary-900 p-2 w-full text-white z-10 shadow';
@@ -22,11 +25,11 @@
2225
}
2326
};
2427
25-
$: if (summary) {
28+
$: if (actionId) {
2629
dismissed = false;
2730
shorten = false;
28-
if (summary.showtime) {
29-
autoHideTimeout = setTimeout(() => { shorten = true; }, summary.showtime);
31+
if (showtime) {
32+
autoHideTimeout = setTimeout(() => { shorten = true; }, showtime);
3033
}
3134
}
3235
@@ -55,6 +58,11 @@
5558
<span class="align-middle">{run.text}</span>
5659
{/if}
5760
{/each}
61+
{#if summary.timestamp && $showTimestamps}
62+
<span class="text-xs ml-1 text-gray-400 dark:text-gray-600 align-middle">
63+
{summary.timestamp}
64+
</span>
65+
{/if}
5866
</div>
5967
<div class="flex-none self-end" style="transform: translateY(3px);">
6068
<Tooltip offsetY={0} small>

src/components/RedirectBanner.svelte

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
import { slide, fade } from 'svelte/transition';
33
import MessageRun from './MessageRuns.svelte';
44
import Tooltip from './common/Tooltip.svelte';
5+
import Button from 'smelte/src/components/Button';
56
import Icon from 'smelte/src/components/Icon';
67
import { Theme } from '../ts/chat-constants';
78
import { createEventDispatcher } from 'svelte';
8-
import { showProfileIcons } from '../ts/storage';
9-
import Button from 'smelte/src/components/Button';
9+
import { showProfileIcons, showTimestamps } from '../ts/storage';
1010
1111
export let redirect: Ytc.ParsedRedirect;
1212
1313
let dismissed = false;
1414
let shorten = false;
15+
$: actionId = redirect?.actionId || '';
16+
$: showtime = redirect?.showtime || 0;
1517
let autoHideTimeout: NodeJS.Timeout | null = null;
1618
const classes = 'rounded inline-flex flex-col overflow-visible ' +
1719
'bg-secondary-900 p-2 w-full text-white z-10 shadow';
@@ -24,11 +26,11 @@
2426
}
2527
};
2628
27-
$: if (redirect) {
29+
$: if (actionId) {
2830
dismissed = false;
2931
shorten = false;
30-
if (redirect.showtime) {
31-
autoHideTimeout = setTimeout(() => { shorten = true; }, redirect.showtime);
32+
if (showtime) {
33+
autoHideTimeout = setTimeout(() => { shorten = true; }, showtime);
3234
}
3335
}
3436
@@ -53,6 +55,11 @@
5355
</Icon>
5456
</span>
5557
<span class="align-middle">Live Redirect Notice</span>
58+
{#if redirect.timestamp && $showTimestamps}
59+
<span class="text-xs ml-1 text-gray-400 dark:text-gray-600 align-middle">
60+
{redirect.timestamp}
61+
</span>
62+
{/if}
5663
</div>
5764
<div class="flex-none self-end" style="transform: translateY(3px);">
5865
<Tooltip offsetY={0} small>

src/ts/chat-parser.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ const parseChatSummary = (renderer: Ytc.AddChatItem, actionId: string, showtime:
103103
message: splitRuns[2],
104104
},
105105
showtime: showtime,
106+
timestamp: formatTimestamp(Date.now() * 1000),
106107
};
107108
return item;
108109
}
@@ -132,6 +133,7 @@ const parseRedirectBanner = (renderer: Ytc.AddChatItem, actionId: string, showti
132133
}
133134
},
134135
showtime: showtime,
136+
timestamp: formatTimestamp(Date.now() * 1000),
135137
};
136138
return item;
137139
}

src/ts/typings/ytc.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ declare namespace Ytc {
489489
message: ParsedRun[];
490490
};
491491
showtime: number;
492+
timestamp?: string;
492493
}
493494

494495
interface ParsedRedirect {
@@ -503,6 +504,7 @@ declare namespace Ytc {
503504
}
504505
};
505506
showtime: number;
507+
timestamp?: string;
506508
}
507509

508510
interface ParsedPoll {

0 commit comments

Comments
 (0)