Go directly to video if Video ID provided in search

This commit is contained in:
WardPearce
2025-11-04 20:52:16 +13:00
parent 08cf47ce5f
commit 3f7981b93c
2 changed files with 17 additions and 4 deletions
+12 -4
View File
@@ -10,6 +10,7 @@
isAndroidTvStore,
searchHistoryStore
} from '../store';
import { isVideoID } from '$lib/misc';
const dispatch = createEventDispatcher();
@@ -39,20 +40,27 @@
function handleSubmit(event: Event | undefined = undefined) {
if (event) event.preventDefault();
if (search.trim() === '') return;
const searchTrimed = search.trim();
if (searchTrimed) return;
if (isVideoID(searchTrimed)) {
// Go directly to video if Video ID provided
goto(`/watch/${searchTrimed}`);
}
selectedSuggestionIndex = -1;
goto(`/search/${encodeURIComponent(search)}`);
goto(`/search/${encodeURIComponent(searchTrimed)}`);
suggestionsForSearch = [];
showSearchBox = false;
if ($interfaceSearchHistoryEnabled && !$searchHistoryStore.includes(search)) {
if ($interfaceSearchHistoryEnabled && !$searchHistoryStore.includes(searchTrimed)) {
let pastHistory = $searchHistoryStore;
if (pastHistory.length > 15) {
pastHistory.pop();
}
searchHistoryStore.set([search, ...pastHistory]);
searchHistoryStore.set([searchTrimed, ...pastHistory]);
}
}
+5
View File
@@ -14,6 +14,11 @@ import type {
VideoBase
} from './api/model';
export function isVideoID(videoId: string): boolean {
var regExp = /^[a-zA-Z0-9_-]{11}$/;
return regExp.test(videoId);
}
export function truncate(value: string, maxLength: number = 50): string {
return value.length > maxLength ? `${value.substring(0, maxLength)}...` : value;
}