feat: add book metadata editor with Google Books and OpenLibrary integration

This commit is contained in:
2025-05-17 15:49:26 -04:00
parent f4f227b24d
commit d2b88f4e59
11 changed files with 981 additions and 30 deletions

View File

@@ -0,0 +1,30 @@
document.addEventListener('DOMContentLoaded', () => {
const searchButton = document.getElementById('search-button');
const searchQueryInput = document.getElementById('search-query');
const apiResponseOutput = document.getElementById('api-response');
searchButton.addEventListener('click', async () => {
const query = searchQueryInput.value.trim();
if (!query) {
apiResponseOutput.textContent = 'Please enter a search query.';
return;
}
apiResponseOutput.textContent = 'Searching...';
try {
// Note: For extensive use, you should use an API key.
// Add &key=YOUR_API_KEY to the URL if you have one.
const response = await fetch(`https://www.googleapis.com/books/v1/volumes?q=${encodeURIComponent(query)}`);
if (!response.ok) {
const errorText = await response.text();
throw new Error(`HTTP error! status: ${response.status}, message: ${errorText}`);
}
const data = await response.json();
apiResponseOutput.textContent = JSON.stringify(data, null, 2);
} catch (error) {
console.error('Error fetching from Google Books API:', error);
apiResponseOutput.textContent = `Error: ${error.message}`;
}
});
});