Files

42 lines
1.6 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Index2 - FreeTube API Example</title>
</head>
<body>
<h1>Welcome to Index2 (FreeTube API Example)</h1>
<form id="searchForm">
<input type="text" id="searchQuery" placeholder="Search YouTube...">
<button type="submit">Search</button>
</form>
<div id="results"></div>
<script>
document.getElementById('searchForm').addEventListener('submit', async function(e) {
e.preventDefault();
const query = document.getElementById('searchQuery').value;
const resultsDiv = document.getElementById('results');
resultsDiv.innerHTML = 'Searching...';
// Example FreeTube API endpoint (replace with actual endpoint if needed)
const apiUrl = `https://api.freetubeapp.io/api/v1/search?q=${encodeURIComponent(query)}`;
try {
const res = await fetch(apiUrl);
const data = await res.json();
if (Array.isArray(data)) {
resultsDiv.innerHTML = data.map(video => `
<div>
<a href="wach2.html?id=${video.id}">${video.title}</a>
</div>
`).join('');
} else {
resultsDiv.innerHTML = 'No results found.';
}
} catch (err) {
resultsDiv.innerHTML = 'Error fetching results.';
}
});
</script>
</body>
</html>