Public
Like
like-anything
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data β all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v52View latest version
A cross-origin API service that tracks likes using unique IDs.
- Simple ID-based tracking - Use any unique identifier (blog posts, products, comments, etc.)
- Embeddable widget - Drop-in script that creates beautiful like buttons
- Real-time updates - Like counts update instantly across all websites
- CORS enabled - Works from any website or domain
- SQLite storage - Reliable, persistent data storage
<script src="https://jamesllllllllll--019894a514b47659ac14319f8b619533.web.val.run/script.js"></script>
<div data-likes-id="your-unique-id"> <button class="likes-button">β€οΈ <span class="likes-count">0</span></button> </div>
π‘ Customize the emoji: Change β€οΈ to any emoji you want: π π π β π― π π π π
- Loads current like count automatically
- Handles button clicks to record likes
- Updates count in real-time
- Supports multiple IDs on one page
Record a like for a specific ID:
{ "id": "post-123" }
Returns:
{ "success": true, "id": "post-123", "likeCount": 42 }
Get like count for a specific ID:
GET /api/likes/post-123
Returns:
{ "id": "post-123", "likeCount": 42 }
Get all like data for admin/stats purposes.
- Blog posts: Use post IDs like "post-123" or "2024-01-15-intro"
- Products: Use product IDs like "product-abc" or "laptop-xps-13"
- Comments: Use comment IDs like "comment-456" or "reply-789"
- Custom: Any unique identifier you want to track likes for!
// Get current likes for a post
fetch('https://jamesllllllllll--019894a514b47659ac14319f8b619533.web.val.run/api/likes/post-123')
.then(res => res.json())
.then(data => {
document.querySelector('.likes-count').textContent = data.likeCount;
});
// Record a like
fetch('https://jamesllllllllll--019894a514b47659ac14319f8b619533.web.val.run/api/like', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ id: 'post-123' })
})
.then(res => res.json())
.then(data => {
document.querySelector('.likes-count').textContent = data.likeCount;
});
// Get the post ID from your page (could be from URL, data attribute, etc.)
const postId = document.querySelector('[data-post-id]').dataset.postId;
// or const postId = window.location.pathname.split('/').pop();
// Get likes for this specific post
fetch(`https://jamesllllllllll--019894a514b47659ac14319f8b619533.web.val.run/api/likes/${postId}`)
.then(res => res.json())
.then(data => {
document.querySelector('.likes-count').textContent = data.likeCount;
});
// Record a like for this post
fetch('https://jamesllllllllll--019894a514b47659ac14319f8b619533.web.val.run/api/like', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ id: postId })
})
.then(res => res.json())
.then(data => {
document.querySelector('.likes-count').textContent = data.likeCount;
});
βββ backend/
β βββ database.ts # SQLite database setup and queries
βββ frontend/
β βββ index.html # Interactive documentation and demo
βββ script.js # Embeddable likes widget script
βββ index.ts # Main HTTP handler using Hono
βββ README.md # This file
- Backend: Hono framework with SQLite database
- Frontend: Modern HTML with Tailwind CSS
- Widget: Vanilla JavaScript with glassmorphism styling
- Database: SQLite with automatic table creation
- Deployment: Val Town serverless platform
Visit the live documentation to:
- Test the API endpoints
- See the embeddable widget in action
- Get copy-paste code examples
- Try different content IDs