document.getElementById('saveButton').addEventListener('click', saveBookmark);
function saveBookmark() {
const url = document.getElementById('urlInput').value;
const title = document.getElementById('titleInput').value;
if (!url || !title) {
alert('Please enter both a URL and a title.');
return;
}
const bookmark = { parentId: "1" ,title, url };
// Save bookmark to Chrome bookmarks
chrome.bookmarks.create(bookmark, function(newBookmark) {
console.log("Bookmark Created:", newBookmark);
displayBookmark(newBookmark);
clearInputs();
});
}
function clearInputs() {
document.getElementById('urlInput').value = '';
document.getElementById('titleInput').value = '';
}
function displayBookmark(bookmark) {
const bookmarkList = document.getElementById('bookmarkList');
const li = document.createElement('li');
li.textContent = bookmark.title;
li.addEventListener('click', () => {
chrome.tabs.create({ url: bookmark.url });
});
bookmarkList.appendChild(li);
}
// Load existing bookmarks on popup open
document.addEventListener('DOMContentLoaded', loadBookmarks);
function loadBookmarks() {
chrome.bookmarks.getTree(function(bookmarkTreeNodes) {
bookmarkTreeNodes.forEach(node => {
if (node.children) {
node.children.forEach(child => {
displayBookmark(child);
});
}
});
});
}
< /code>
html < /p>
Bookmark Manager
Save Bookmark
Your Bookmarks
Подробнее здесь: https://stackoverflow.com/questions/795 ... on-working
Мобильная версия