Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const addBookmarkBtn = document.getElementById('addBookmark');
+ const addBookmarkForm = document.getElementById('addBookmarkForm');
+ const bookmarkForm = document.getElementById('bookmarkForm');
+ const cancelAddBtn = document.getElementById('cancelAdd');
+ const bookmarksGrid = document.getElementById('bookmarksGrid');
+ const searchInput = document.getElementById('searchBookmarks');
+ const categoryFilter = document.getElementById('categoryFilter');
+
+ let bookmarks = JSON.parse(localStorage.getItem('bookmarks')) || [];
+
+ function toggleForm() {
+ addBookmarkForm.classList.toggle('hidden');
+ }
+
+ function getVideoId(url) {
+ const regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/;
+ const match = url.match(regExp);
+ return match && match[2].length === 11 ? match[2] : null;
+ }
+
+ function renderBookmarks(bookmarksToRender = bookmarks) {
+ bookmarksGrid.innerHTML = bookmarksToRender
+ .map((bookmark, index) => `
+
+ src="https://img.youtube.com/vi/${bookmark.videoId}/maxresdefault.jpg"
+ alt="${bookmark.title}"
+ class="thumbnail"
+ >
+
+
${bookmark.title}
+
${bookmark.category || 'Uncategorized'}
+
+
+ Watch
+
+
+ Delete
+
+
+
+
+ `)
+ .join('');
+ }
+
+ function saveBookmarks() {
+ localStorage.setItem('bookmarks', JSON.stringify(bookmarks));
+ }
+
+ window.deleteBookmark = (index) => {
+ bookmarks.splice(index, 1);
+ saveBookmarks();
+ renderBookmarks();
+ };
+
+ bookmarkForm.addEventListener('submit', (e) => {
+ e.preventDefault();
+
+ const videoUrl = document.getElementById('videoUrl').value;
+ const videoId = getVideoId(videoUrl);
+
+ if (!videoId) {
+ alert('Please enter a valid YouTube URL');
+ return;
+ }
+
+ const bookmark = {
+ videoId,
+ title: document.getElementById('videoTitle').value || 'Untitled Video',
+ category: document.getElementById('videoCategory').value,
+ dateAdded: new Date().toISOString()
+ };
+
+ bookmarks.unshift(bookmark);
+ saveBookmarks();
+ renderBookmarks();
+ bookmarkForm.reset();
+ toggleForm();
+ });
+
+ addBookmarkBtn.addEventListener('click', toggleForm);
+ cancelAddBtn.addEventListener('click', toggleForm);
+
+ searchInput.addEventListener('input', (e) => {
+ const searchTerm = e.target.value.toLowerCase();
+ const categoryValue = categoryFilter.value;
+
+ const filtered = bookmarks.filter(bookmark => {
+ const matchesSearch = bookmark.title.toLowerCase().includes(searchTerm);
+ const matchesCategory = !categoryValue || bookmark.category === categoryValue;
+ return matchesSearch && matchesCategory;
+ });
+
+ renderBookmarks(filtered);
+ });
+
+ categoryFilter.addEventListener('change', (e) => {
+ const searchTerm = searchInput.value.toLowerCase();
+ const categoryValue = e.target.value;
+
+ const filtered = bookmarks.filter(bookmark => {
+ const matchesSearch = bookmark.title.toLowerCase().includes(searchTerm);
+ const matchesCategory = !categoryValue || bookmark.category === categoryValue;
+ return matchesSearch && matchesCategory;
+ });
+
+ renderBookmarks(filtered);
+ });
+
+ renderBookmarks();
+ });
Changed around line 1
+ :root {
+ --primary: #6366f1;
+ --primary-dark: #4f46e5;
+ --bg: #f8fafc;
+ --text: #1e293b;
+ --gray: #64748b;
+ --card-bg: #ffffff;
+ --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
+ }
+
+ * {
+ margin: 0;
+ padding: 0;
+ box-sizing: border-box;
+ }
+
+ body {
+ font-family: system-ui, -apple-system, sans-serif;
+ background: var(--bg);
+ color: var(--text);
+ line-height: 1.5;
+ }
+
+ header {
+ background: var(--card-bg);
+ box-shadow: var(--shadow);
+ position: sticky;
+ top: 0;
+ z-index: 10;
+ }
+
+ nav {
+ max-width: 1200px;
+ margin: 0 auto;
+ padding: 1rem;
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ }
+
+ h1 {
+ font-size: 1.5rem;
+ color: var(--primary);
+ font-weight: 700;
+ }
+
+ #addBookmark {
+ background: var(--primary);
+ color: white;
+ border: none;
+ width: 2.5rem;
+ height: 2.5rem;
+ border-radius: 50%;
+ font-size: 1.5rem;
+ cursor: pointer;
+ transition: transform 0.2s;
+ }
+
+ #addBookmark:hover {
+ transform: scale(1.1);
+ background: var(--primary-dark);
+ }
+
+ main {
+ max-width: 1200px;
+ margin: 2rem auto;
+ padding: 0 1rem;
+ }
+
+ #addBookmarkForm {
+ background: var(--card-bg);
+ padding: 2rem;
+ border-radius: 0.5rem;
+ box-shadow: var(--shadow);
+ margin-bottom: 2rem;
+ }
+
+ #addBookmarkForm.hidden {
+ display: none;
+ }
+
+ form {
+ display: grid;
+ gap: 1rem;
+ }
+
+ input, select, button {
+ padding: 0.75rem;
+ border: 1px solid var(--gray);
+ border-radius: 0.25rem;
+ font-size: 1rem;
+ }
+
+ button {
+ background: var(--primary);
+ color: white;
+ border: none;
+ cursor: pointer;
+ transition: background 0.2s;
+ }
+
+ button:hover {
+ background: var(--primary-dark);
+ }
+
+ #cancelAdd {
+ background: var(--gray);
+ }
+
+ .filters {
+ display: grid;
+ gap: 1rem;
+ margin-bottom: 2rem;
+ grid-template-columns: 1fr auto;
+ }
+
+ #bookmarksGrid {
+ display: grid;
+ gap: 1.5rem;
+ grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
+ }
+
+ .bookmark-card {
+ background: var(--card-bg);
+ border-radius: 0.5rem;
+ overflow: hidden;
+ box-shadow: var(--shadow);
+ transition: transform 0.2s;
+ }
+
+ .bookmark-card:hover {
+ transform: translateY(-4px);
+ }
+
+ .thumbnail {
+ width: 100%;
+ aspect-ratio: 16/9;
+ object-fit: cover;
+ }
+
+ .bookmark-info {
+ padding: 1rem;
+ }
+
+ .bookmark-title {
+ font-weight: 600;
+ margin-bottom: 0.5rem;
+ }
+
+ .bookmark-category {
+ color: var(--gray);
+ font-size: 0.875rem;
+ }
+
+ .bookmark-actions {
+ display: flex;
+ gap: 0.5rem;
+ margin-top: 1rem;
+ }
+
+ .bookmark-actions button {
+ flex: 1;
+ font-size: 0.875rem;
+ }
+
+ footer {
+ text-align: center;
+ padding: 2rem;
+ color: var(--gray);
+ }
+
+ @media (max-width: 640px) {
+ .filters {
+ grid-template-columns: 1fr;
+ }
+
+ #bookmarksGrid {
+ grid-template-columns: 1fr;
+ }
+ }