-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbookmarks.html
More file actions
373 lines (335 loc) · 16.3 KB
/
Copy pathbookmarks.html
File metadata and controls
373 lines (335 loc) · 16.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="./db.js"></script>
<title>ShareHive - Bookmarks</title>
<style>
/* --- Base & Theme (Unchanged) --- */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
background-color: var(--bg-color);
color: var(--text-color);
transition: background-color 0.3s, color 0.3s;
}
:root {
--bg-color: #f9f9f9;
--text-color: #222;
--primary-color: #0077ff;
--sidebar-bg: #ffffff;
--card-bg: #ffffff;
--border-color: #e0e0e0;
--shadow-color: rgba(0,0,0,0.06);
}
body.dark {
--bg-color: #1e1e1e;
--text-color: #f0f0f0;
--sidebar-bg: #2c2c2c;
--card-bg: #333333;
--border-color: #444;
--shadow-color: rgba(0,0,0,0.2);
}
/* --- Navbar & Sidebar (Unchanged) --- */
.navbar { display: flex; justify-content: space-between; align-items: center; padding: 10px 20px; background: var(--primary-color); color: white; }
.navbar h1 { font-size: 20px; }
.toggle-btn { background: white; border: none; color: var(--primary-color); padding: 5px 10px; border-radius: 5px; cursor: pointer; font-weight: bold; }
.container { display: flex; height: calc(100vh - 50px); }
.sidebar { width: 220px; background: var(--sidebar-bg); padding: 20px; overflow-y: auto; border-right: 1px solid var(--border-color); }
.sidebar h2 { font-size: 16px; margin-bottom: 10px; }
.sidebar a { display: block; text-decoration: none; color: var(--text-color); padding: 8px 10px; border-radius: 5px; margin-bottom: 5px; }
.sidebar a:hover { background: var(--primary-color); color: white; }
/* --- Main Content Area (Modernized) --- */
.main { flex: 1; padding: 25px; overflow-y: auto; }
.main-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.main-header h2 { font-size: 24px; margin: 0; }
.add-bookmark-btn {
padding: 10px 20px; border: none; background: var(--primary-color);
color: white; border-radius: 8px; cursor: pointer; font-weight: bold; font-size: 16px;
}
.filters-toolbar { display: flex; gap: 15px; margin-bottom: 25px; flex-wrap: wrap; }
.filters-toolbar input, .filters-toolbar select {
padding: 10px; border-radius: 8px; border: 1px solid var(--border-color);
background: var(--card-bg); color: var(--text-color); font-size: 14px;
}
.search-box { flex-grow: 1; }
/* --- Bookmarks List & Cards (Modernized) --- */
.bookmarks-container { display: flex; flex-direction: column; gap: 12px; }
.bookmark-card {
display: flex; align-items: center;
background: var(--card-bg); padding: 15px;
border-radius: 10px; box-shadow: 0 3px 10px var(--shadow-color);
transition: transform 0.2s, box-shadow 0.2s;
}
.bookmark-card:hover { transform: translateY(-3px); box-shadow: 0 6px 15px var(--shadow-color); }
.favicon { width: 24px; height: 24px; margin-right: 15px; background: #eee; border-radius: 4px; }
body.dark .favicon { background: #444; }
.card-info { flex-grow: 1; text-decoration: none; color: var(--text-color); }
.card-info h3 { font-size: 16px; font-weight: 600; margin-bottom: 2px; }
.card-info .domain { font-size: 13px; color: #888; }
body.dark .card-info .domain { color: #aaa; }
.tags-container { display: flex; gap: 6px; margin-right: 15px; }
.tag { font-size: 11px; background: #eee; color: #555; padding: 3px 8px; border-radius: 12px; }
body.dark .tag { background: #444; color: #ccc; }
.actions { display: flex; gap: 8px; }
.actions button { background: none; border: none; cursor: pointer; font-size: 18px; padding: 5px; color: #888; }
body.dark .actions button { color: #aaa; }
/* Empty State */
.empty-state { text-align: center; padding: 50px; background: var(--card-bg); border-radius: 12px; }
/* Modal */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 1000; display: none; justify-content: center; align-items: center; }
.modal { background: var(--bg-color); padding: 25px; border-radius: 12px; width: 90%; max-width: 500px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header h2 { margin: 0; }
.modal-header .close-btn { font-size: 24px; background: none; border: none; cursor: pointer; color: var(--text-color); }
.form { display: flex; flex-direction: column; gap: 15px; }
.form input { width: 100%; padding: 12px; font-size: 14px; border: 1px solid var(--border-color); border-radius: 8px; background: var(--card-bg); color: var(--text-color); }
.form button { padding: 12px; border: none; background: var(--primary-color); color: white; border-radius: 8px; cursor: pointer; font-weight: bold; font-size: 16px; }
/* Animations */
@keyframes fadeInDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
.bookmark-card { animation: fadeInDown 0.3s ease-out forwards; }
.bookmark-card.deleting { transition: opacity 0.3s, transform 0.3s; opacity: 0; transform: scale(0.95); }
</style>
</head>
<body>
<!-- Navbar -->
<div class="navbar">
<h1>🐝 ShareHive - Bookmarks</h1>
<button class="toggle-btn" onclick="toggleTheme()">🌙</button>
</div>
<div class="container">
<!-- Sidebar -->
<div class="sidebar">
<!-- Sidebar content remains the same -->
<h2>Menu</h2>
<a href="index.html">🏠 Dashboard</a>
<a href="notes.html">📝 Notes</a>
<a href="bookmarks.html"><b>🔖 Bookmarks</b></a>
<a href="videos.html">🎬 Video Links</a>
<a href="expense.html">💰 Expense Tracker</a>
<a href="planner.html">📅 Planner</a>
<a href="uploads.html">📂 Upload Files</a>
<a href="projects.html">📌 Projects</a>
<a href="watchlist.html">🎥 Watchlist</a>
<a href="courses.html">📚 Courses</a>
<a href="profile.html">👤 Profile</a>
<a href="settings.html">⚙️ Settings</a>
<hr>
<a href="about.html">ℹ️ About</a>
<a href="help.html">❓ Help</a>
<a href="faq.html">❔ FAQ</a>
<a href="blog.html">📰 Blog</a>
<a href="contact.html">✉️ Contact</a>
<a href="join.html">🤝 Join Us</a>
<a href="report.html">🐞 Report</a>
<a href="privacy.html">📜 Privacy & Policy</a>
<a href="community.html">🌍 Community</a>
</div>
<!-- Main -->
<div class="main">
<div class="main-header">
<h2>My Bookmarks</h2>
<button class="add-bookmark-btn" id="addBookmarkBtn">➕ Add Bookmark</button>
</div>
<div class="filters-toolbar">
<input class="search-box" id="search" type="text" placeholder="Search by title...">
<select id="tagFilter"></select>
<select id="sortOrder">
<option value="newest">Sort by Newest</option>
<option value="oldest">Sort by Oldest</option>
<option value="az">Sort by Title (A-Z)</option>
<option value="za">Sort by Title (Z-A)</option>
</select>
</div>
<div class="bookmarks-container" id="bookmarksContainer"></div>
</div>
</div>
<!-- Add/Edit Bookmark Modal -->
<div class="modal-overlay" id="bookmarkModal">
<div class="modal">
<div class="modal-header">
<h2 id="modalTitle">Add New Bookmark</h2>
<button class="close-btn" id="closeModalBtn">×</button>
</div>
<div class="form">
<input id="title" type="text" placeholder="Bookmark Title">
<input id="url" type="url" placeholder="URL (e.g., https://example.com)">
<input id="tags" type="text" placeholder="Tags (comma-separated, e.g., work, reading)">
<button id="saveBtn">Save Bookmark</button>
</div>
</div>
</div>
<script>
// 🌙 Dark Mode
const toggleBtn = document.querySelector('.toggle-btn');
function toggleTheme() {
document.body.classList.toggle("dark");
const isDark = document.body.classList.contains("dark");
localStorage.setItem("theme", isDark ? "dark" : "light");
toggleBtn.textContent = isDark ? '☀️' : '🌙';
}
if (localStorage.getItem("theme") === "dark") {
document.body.classList.add("dark");
toggleBtn.textContent = '☀️';
}
// 📦 IndexedDB (v21 unified)
let db;
const stores = ["notes","bookmarks","videos","todos","expenses","planner","wiki","uploads","projects","watchlist","courses","profile","community"];
const request = indexedDB.open("ShareHiveDB", 22);
request.onupgradeneeded = e => {
db = e.target.result;
if (!db.objectStoreNames.contains("bookmarks")) {
db.createObjectStore("bookmarks", { keyPath: "id", autoIncrement: true });
}
};
request.onsuccess = e => { db = e.target.result; displayBookmarks(); };
request.onerror = e => console.error("DB error:", e.target.error);
// --- Modal Handling ---
const modal = document.getElementById('bookmarkModal');
const openModalBtn = document.getElementById('addBookmarkBtn');
const closeModalBtn = document.getElementById('closeModalBtn');
const modalTitle = document.getElementById('modalTitle');
const saveBtn = document.getElementById('saveBtn');
const form = {
title: document.getElementById('title'),
url: document.getElementById('url'),
tags: document.getElementById('tags'),
};
function openModal(bookmark = null) {
if (bookmark) { // Editing
modalTitle.textContent = 'Edit Bookmark';
saveBtn.textContent = 'Update Bookmark';
saveBtn.dataset.editId = bookmark.id;
form.title.value = bookmark.title;
form.url.value = bookmark.url;
form.tags.value = bookmark.tags ? bookmark.tags.join(', ') : '';
} else { // Adding new
modalTitle.textContent = 'Add New Bookmark';
saveBtn.textContent = 'Save Bookmark';
delete saveBtn.dataset.editId;
form.title.value = '';
form.url.value = '';
form.tags.value = '';
}
modal.style.display = 'flex';
}
function closeModal() { modal.style.display = 'none'; }
openModalBtn.onclick = () => openModal();
closeModalBtn.onclick = closeModal;
modal.onclick = (e) => { if (e.target === modal) closeModal(); };
// --- Helper to get metadata ---
function getBookmarkMetadata(url) {
try {
const urlObj = new URL(url);
const domain = urlObj.hostname.replace('www.', '');
const favicon = `https://s2.googleusercontent.com/s2/favicons?domain=${domain}&sz=32`;
return { domain, favicon };
} catch (e) {
return { domain: 'Invalid URL', favicon: '' };
}
}
// --- Display & Filtering Logic ---
async function displayBookmarks() {
const tx = db.transaction("bookmarks", "readonly");
const allBookmarks = await new Promise(res => tx.objectStore("bookmarks").getAll().onsuccess = e => res(e.target.result));
updateTagFilter(allBookmarks);
// 1. Filter
const searchTerm = document.getElementById('search').value.toLowerCase();
const tagFilter = document.getElementById('tagFilter').value;
let filteredBookmarks = allBookmarks.filter(b => {
const titleMatch = b.title.toLowerCase().includes(searchTerm);
const tagMatch = tagFilter === 'all' || (b.tags && b.tags.includes(tagFilter));
return titleMatch && tagMatch;
});
// 2. Sort
const sortOrder = document.getElementById('sortOrder').value;
filteredBookmarks.sort((a, b) => {
if (sortOrder === 'newest') return new Date(b.createdAt) - new Date(a.createdAt);
if (sortOrder === 'oldest') return new Date(a.createdAt) - new Date(b.createdAt);
if (sortOrder === 'az') return a.title.localeCompare(b.title);
if (sortOrder === 'za') return b.title.localeCompare(a.title);
});
// 3. Render
const container = document.getElementById('bookmarksContainer');
container.innerHTML = '';
if (filteredBookmarks.length === 0) {
container.innerHTML = `<div class="empty-state"><h3>No bookmarks found.</h3><p>Try adding a new bookmark or adjusting your filters.</p></div>`;
} else {
filteredBookmarks.forEach(b => {
const card = document.createElement('div');
card.className = 'bookmark-card';
card.dataset.id = b.id;
card.innerHTML = `
<img class="favicon" src="${b.favicon}" alt="">
<a href="${b.url}" target="_blank" class="card-info">
<h3>${b.title}</h3>
<span class="domain">${b.domain}</span>
</a>
<div class="tags-container">
${(b.tags || []).map(tag => `<span class="tag">${tag}</span>`).join('')}
</div>
<div class="actions">
<button onclick="editBookmark(${b.id})" title="Edit">✏️</button>
<button onclick="deleteBookmark(${b.id})" title="Delete">🗑️</button>
</div>
`;
container.appendChild(card);
});
}
}
function updateTagFilter(bookmarks) {
const allTags = new Set(bookmarks.flatMap(b => b.tags || []));
const filterSelect = document.getElementById('tagFilter');
const currentVal = filterSelect.value; // Preserve selection
filterSelect.innerHTML = '<option value="all">Filter by Tag (All)</option>';
allTags.forEach(tag => {
const selected = tag === currentVal ? 'selected' : '';
filterSelect.innerHTML += `<option value="${tag}" ${selected}>${tag}</option>`;
});
}
// --- CRUD ---
saveBtn.onclick = () => {
const title = form.title.value.trim();
let url = form.url.value.trim();
if (!title || !url) { alert("Title and URL are required."); return; }
if (!/^https?:\/\//i.test(url)) { url = "https://" + url; }
const { domain, favicon } = getBookmarkMetadata(url);
const tags = form.tags.value.split(',').map(t => t.trim()).filter(Boolean);
const editId = saveBtn.dataset.editId;
const tx = db.transaction("bookmarks", "readwrite");
const store = tx.objectStore("bookmarks");
if (editId) { // Update
const req = store.get(Number(editId));
req.onsuccess = () => {
const bookmark = req.result;
Object.assign(bookmark, { title, url, tags, domain, favicon });
store.put(bookmark);
};
} else { // Add new
const bookmarkData = { title, url, tags, domain, favicon, createdAt: new Date().toISOString() };
store.add(bookmarkData);
}
tx.oncomplete = () => { closeModal(); displayBookmarks(); };
};
function editBookmark(id) {
const tx = db.transaction("bookmarks", "readonly");
tx.objectStore("bookmarks").get(id).onsuccess = e => openModal(e.target.result);
}
function deleteBookmark(id) {
const card = document.querySelector(`.bookmark-card[data-id='${id}']`);
if (card && confirm("Are you sure you want to delete this bookmark?")) {
card.classList.add('deleting');
setTimeout(() => {
const tx = db.transaction("bookmarks", "readwrite");
tx.objectStore("bookmarks").delete(id);
tx.oncomplete = displayBookmarks;
}, 300); // Wait for animation
}
}
// --- Event Listeners ---
document.getElementById('search').addEventListener('input', displayBookmarks);
document.getElementById('tagFilter').addEventListener('change', displayBookmarks);
document.getElementById('sortOrder').addEventListener('change', displayBookmarks);
</script>
</body>
</html>