Added comment timestamp support
This commit is contained in:
@@ -18,6 +18,16 @@
|
||||
});
|
||||
} catch {}
|
||||
}
|
||||
|
||||
function commentTimestamps(html: string): string {
|
||||
const regex =
|
||||
/<a href="([^"]+)" data-onclick="jump_to_time" data-jump-time="(\d+)">(\d+:\d+(?::\d+)?)<\/a>\s*(.+)/;
|
||||
const replacement = `<a href="/watch/${videoId}?time=$2" data-sveltekit-preload-data="off" class="link">$3</a>`;
|
||||
|
||||
const processedHtml = html.replace(regex, replacement);
|
||||
|
||||
return processedHtml;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="comment">
|
||||
@@ -42,7 +52,7 @@
|
||||
{/if}
|
||||
</div>
|
||||
<p style="margin-bottom: 0;">
|
||||
{@html comment.contentHtml}
|
||||
{@html commentTimestamps(comment.contentHtml)}
|
||||
</p>
|
||||
<div style="display: flex;">
|
||||
<p><i>thumb_up</i> {numberWithCommas(comment.likeCount)}</p>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<script lang="ts">
|
||||
import 'vidstack/bundle';
|
||||
|
||||
import { page } from '$app/stores';
|
||||
import type { Page } from '@sveltejs/kit';
|
||||
import { SponsorBlock, type Category } from 'sponsorblock-api';
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
import { _ } from 'svelte-i18n';
|
||||
@@ -36,6 +38,20 @@
|
||||
let playerIsLive = false;
|
||||
let playerPosSet = false;
|
||||
|
||||
function loadTimeFromUrl(page: Page): boolean {
|
||||
if (player) {
|
||||
const timeGivenUrl = page.url.searchParams.get('time');
|
||||
if (timeGivenUrl && !isNaN(parseFloat(timeGivenUrl))) {
|
||||
player.currentTime = Number(timeGivenUrl);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
page.subscribe((pageUpdate) => loadTimeFromUrl(pageUpdate));
|
||||
|
||||
export function seekTo(time: number) {
|
||||
if (typeof player !== 'undefined') {
|
||||
player.currentTime = time;
|
||||
@@ -122,11 +138,11 @@
|
||||
}
|
||||
|
||||
if (get(playerDashStore)) {
|
||||
src = [{ src: data.video.dashUrl + '?local=true', type: 'application/dash+xml' }];
|
||||
|
||||
player.addEventListener('dash-can-play', async () => {
|
||||
await loadPlayerPos();
|
||||
});
|
||||
|
||||
src = [{ src: data.video.dashUrl + '?local=true', type: 'application/dash+xml' }];
|
||||
} else {
|
||||
let formattedSrc;
|
||||
src = data.video.formatStreams.map((format) => {
|
||||
@@ -192,12 +208,7 @@
|
||||
if (playerPosSet) return;
|
||||
playerPosSet = true;
|
||||
|
||||
const paramTime = new URLSearchParams(window.location.search).get('time');
|
||||
|
||||
if (paramTime && !isNaN(parseFloat(paramTime))) {
|
||||
player.currentTime = Number(paramTime);
|
||||
return;
|
||||
}
|
||||
if (loadTimeFromUrl($page)) return;
|
||||
|
||||
let toSetTime = 0;
|
||||
|
||||
|
||||
@@ -4,12 +4,19 @@ import { error } from '@sveltejs/kit';
|
||||
export async function load({ url }) {
|
||||
const videoId = url.searchParams.get('v');
|
||||
const playlistId = url.searchParams.get('list');
|
||||
const timestamp = url.searchParams.get('t');
|
||||
|
||||
if (videoId) {
|
||||
let goToUrl = `/watch/${videoId}`;
|
||||
let goToUrl = new URL(`${location.origin}/watch/${videoId}`);
|
||||
|
||||
if (playlistId) {
|
||||
goToUrl += `?playlist=${playlistId}`;
|
||||
goToUrl.searchParams.set('playlist', playlistId);
|
||||
}
|
||||
|
||||
if (timestamp) {
|
||||
goToUrl.searchParams.set('time', timestamp);
|
||||
}
|
||||
|
||||
goto(goToUrl);
|
||||
} else {
|
||||
error(404);
|
||||
|
||||
Reference in New Issue
Block a user