chatty-mcchatface-bot / reddit.html
asdkhf's picture
reddit.com
805e777 verified
Raw History Blame Contribute Delete
6.29 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Reddit Posts</title>
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/feather-icons"></script>
<style>
.post-card {
transition: transform 0.2s ease;
}
.post-card:hover {
transform: translateY(-2px);
}
.upvote {
color: #ff4500;
}
</style>
</head>
<body class="bg-gray-100">
<div class="flex flex-col min-h-screen">
<!-- Header -->
<header class="bg-indigo-600 text-white py-4 px-6 shadow-md">
<div class="flex items-center justify-between">
<div class="flex items-center space-x-6">
<a href="/" class="flex items-center space-x-3">
<div class="w-10 h-10 bg-white rounded-full flex items-center justify-center">
<i data-feather="message-square" class="text-indigo-600"></i>
</div>
<h1 class="text-xl font-bold">Chatty McChatface</h1>
</a>
<h2 class="text-lg font-medium">Reddit Posts</h2>
</div>
</div>
</header>
<!-- Main Content -->
<main class="flex-1 p-6">
<div class="max-w-4xl mx-auto">
<div class="bg-white rounded-lg shadow-md p-6 mb-6">
<h2 class="text-2xl font-bold mb-4 text-indigo-600">Popular Reddit Posts</h2>
<div class="space-y-4" id="reddit-posts">
<!-- Posts will be loaded here -->
<div class="text-center py-8">
<div class="animate-pulse space-y-4">
<div class="h-6 bg-gray-200 rounded w-3/4 mx-auto"></div>
<div class="h-6 bg-gray-200 rounded w-1/2 mx-auto"></div>
<div class="h-4 bg-gray-200 rounded w-1/3 mx-auto"></div>
</div>
</div>
</div>
</div>
</div>
</main>
</div>
<script>
feather.replace();
// Fetch popular Reddit posts
async function fetchRedditPosts() {
try {
const response = await fetch('https://www.reddit.com/r/popular.json?limit=10');
const data = await response.json();
const postsContainer = document.getElementById('reddit-posts');
postsContainer.innerHTML = '';
data.data.children.forEach(post => {
const postData = post.data;
const postCard = document.createElement('div');
postCard.className = 'post-card bg-gray-50 p-4 rounded-lg border border-gray-200';
postCard.innerHTML = `
<div class="flex items-start space-x-3">
<div class="flex flex-col items-center">
<i data-feather="arrow-up" class="upvote"></i>
<span class="text-sm font-medium">${postData.ups.toLocaleString()}</span>
<i data-feather="arrow-down" class="text-gray-400"></i>
</div>
<div class="flex-1">
<a href="https://reddit.com${postData.permalink}" target="_blank" class="hover:underline">
<h3 class="font-bold text-lg">${postData.title}</h3>
</a>
<p class="text-gray-600 text-sm mt-1">Posted in r/${postData.subreddit} by u/${postData.author}</p>
${postData.selftext ? `<p class="text-gray-700 mt-2">${postData.selftext.substring(0, 200)}${postData.selftext.length > 200 ? '...' : ''}</p>` : ''}
${postData.url && !postData.url.includes('reddit.com') && !postData.is_self ?
`<a href="${postData.url}" target="_blank" class="text-indigo-600 hover:underline text-sm mt-2 block">${postData.url}</a>` : ''}
<div class="flex items-center space-x-4 text-gray-500 text-sm mt-3">
<span class="flex items-center space-x-1">
<i data-feather="message-square" class="w-4 h-4"></i>
<span>${postData.num_comments.toLocaleString()} comments</span>
</span>
</div>
</div>
${postData.thumbnail && postData.thumbnail.startsWith('http') ?
`<img src="${postData.thumbnail}" alt="Thumbnail" class="w-16 h-16 rounded object-cover">` : ''}
</div>
`;
postsContainer.appendChild(postCard);
});
feather.replace();
} catch (error) {
document.getElementById('reddit-posts').innerHTML = `
<div class="bg-red-50 border-l-4 border-red-500 p-4">
<div class="flex">
<div class="flex-shrink-0">
<i data-feather="alert-circle" class="h-5 w-5 text-red-500"></i>
</div>
<div class="ml-3">
<p class="text-sm text-red-700">Failed to load Reddit posts. Please try again later.</p>
</div>
</div>
</div>
`;
feather.replace();
}
}
// Load posts when page loads
document.addEventListener('DOMContentLoaded', fetchRedditPosts);
</script>
</body>
</html>