Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a simple book marker manager #383

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions JavaScript/bookmark_manager/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bookmark Manager</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-900 text-white min-h-screen flex items-center justify-center">

<div class="w-full max-w-xl p-8 bg-gray-800 rounded-lg shadow-md">
<h1 class="text-3xl font-bold text-center mb-8">Bookmark Manager</h1>

<form id="bookmarkForm" class="flex gap-2 mb-4">
<input
type="url"
id="bookmarkUrl"
class="w-full p-2 rounded bg-gray-700 text-white"
placeholder="Enter Bookmark URL"
required />
<button
type="submit"
class="bg-blue-600 hover:bg-blue-700 px-4 py-2 rounded text-white font-semibold">
Add
</button>
</form>

<div id="bookmarkList" class="space-y-2">
<!-- Bookmarks will appear here -->
</div>
</div>

<script src="script.js"></script>
</body>
</html>
44 changes: 44 additions & 0 deletions JavaScript/bookmark_manager/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Select elements
const bookmarkForm = document.getElementById('bookmarkForm');
const bookmarkUrl = document.getElementById('bookmarkUrl');
const bookmarkList = document.getElementById('bookmarkList');

// Retrieve bookmarks from localStorage
let bookmarks = JSON.parse(localStorage.getItem('bookmarks')) || [];

// Function to display bookmarks
function displayBookmarks() {
bookmarkList.innerHTML = '';
bookmarks.forEach((bookmark, index) => {
bookmarkList.innerHTML += `
<div class="flex justify-between items-center p-2 bg-gray-700 rounded">
<a href="${bookmark}" target="_blank" class="text-blue-400 hover:underline">${bookmark}</a>
<button onclick="deleteBookmark(${index})" class="text-red-500 hover:text-red-700">Delete</button>
</div>
`;
});
}

// Function to add a new bookmark
bookmarkForm.addEventListener('submit', (e) => {
e.preventDefault();
const url = bookmarkUrl.value;

// Add bookmark and save to localStorage
bookmarks.push(url);
localStorage.setItem('bookmarks', JSON.stringify(bookmarks));

// Clear input and update the list
bookmarkUrl.value = '';
displayBookmarks();
});

// Function to delete a bookmark
function deleteBookmark(index) {
bookmarks.splice(index, 1);
localStorage.setItem('bookmarks', JSON.stringify(bookmarks));
displayBookmarks();
}

// Display bookmarks on page load
displayBookmarks();
Loading