Add index3.html and wach3.html for CloudTube API example

This commit is contained in:
miles authored and GitHub committed 2025-09-15 16:29:23 +00:00
1 parent 811b90c479
commit e278fee547
2 files changed
+79

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Index3 - CloudTube API Example</title>
</head>
<body>
<h1>Index3 (CloudTube 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>
const CLOUDTUBE_API = 'https://api.cloudtube.dev';
document.getElementById('searchForm').addEventListener('submit', async function(e) {
e.preventDefault();
const query = document.getElementById('searchQuery').value;
const resultsDiv = document.getElementById('results');
resultsDiv.innerHTML = 'Searching...';
try {
const res = await fetch(`${CLOUDTUBE_API}/search?q=${encodeURIComponent(query)}`);
const data = await res.json();
if (Array.isArray(data) && data.length > 0) {
resultsDiv.innerHTML = data.map(video => `
<div>
<a href="wach3.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>
+39
View File
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Wach3 - CloudTube API Example</title>
</head>
<body>
<h1>Wach3 (CloudTube API Example)</h1>
<div id="video"></div>
<script>
const CLOUDTUBE_API = 'https://api.cloudtube.dev';
// Get video ID from URL
const urlParams = new URLSearchParams(window.location.search);
const videoId = urlParams.get('id');
const videoDiv = document.getElementById('video');
if (!videoId) {
videoDiv.innerHTML = 'No video ID provided.';
} else {
fetch(`${CLOUDTUBE_API}/video?id=${videoId}`)
.then(res => res.json())
.then(data => {
if (data && data.title && data.url) {
videoDiv.innerHTML = `
<h2>${data.title}</h2>
<video width="640" controls src="${data.url}"></video>
<p>${data.description || ''}</p>
`;
} else {
videoDiv.innerHTML = 'Video not found.';
}
})
.catch(() => {
videoDiv.innerHTML = 'Error loading video.';
});
}
</script>
</body>
</html>