sasteren:boeken-nieuw
Verschillen
Dit geeft de verschillen weer tussen de geselecteerde revisie en de huidige revisie van de pagina.
| Beide kanten vorige revisieVorige revisieVolgende revisie | Vorige revisie | ||
| sasteren:boeken-nieuw [2023/08/13 17:48] – oude revisie hersteld (2023/08/07 17:19) admin_sasteren | sasteren:boeken-nieuw [2026/04/20 06:12] (huidige) – oude revisie hersteld (2023/08/14 07:11) admin_sasteren | ||
|---|---|---|---|
| Regel 1: | Regel 1: | ||
| < | < | ||
| - | |||
| action template : | action template : | ||
| struct_schema " | struct_schema " | ||
| Regel 6: | Regel 5: | ||
| </ | </ | ||
| + | |||
| + | < | ||
| + | < | ||
| + | const isbnField = document.getElementsByName(" | ||
| + | const itemTypeField = document.getElementsByName(' | ||
| + | const titleField = document.getElementsByName(' | ||
| + | const subtitleField = document.getElementsByName(' | ||
| + | const originalTitleField = document.getElementsByName(' | ||
| + | const authorField = document.getElementsByName(' | ||
| + | const languageField = document.getElementsByName(' | ||
| + | const yearPublishedField = document.getElementsByName(' | ||
| + | const monthPublishedField = document.getElementsByName(' | ||
| + | const dayPublishedField = document.getElementsByName(' | ||
| + | const pageCountField = document.getElementsByName(' | ||
| + | const publisherField = document.getElementsByName(' | ||
| + | const descriptionField = document.getElementsByName(' | ||
| + | const statusField = document.getElementsByName(' | ||
| + | const plaatsingField = document.getElementsByName(' | ||
| + | |||
| + | isbnField.addEventListener(' | ||
| + | const isbn = isbnField.value; | ||
| + | console.log(isbn); | ||
| + | if (isbn) { | ||
| + | fetchGoogleBookData(isbn) | ||
| + | .then(googleBookData => { | ||
| + | if (googleBookData) { | ||
| + | populateFieldsFromGoogle(googleBookData); | ||
| + | openThumbnailImage(googleBookData); | ||
| + | } else { | ||
| + | console.error(' | ||
| + | } | ||
| + | }) | ||
| + | .catch(error => { | ||
| + | console.error(' | ||
| + | }); | ||
| + | } | ||
| + | }); | ||
| + | |||
| + | function openThumbnailImage(data) { | ||
| + | const imagelinks = data.imageLinks || {}; | ||
| + | const thumbnailUrl = imagelinks.thumbnail || ''; | ||
| + | if (thumbnailUrl) { | ||
| + | window.open(thumbnailUrl, | ||
| + | } | ||
| + | } | ||
| + | |||
| + | function fetchGoogleBookData(isbn) { | ||
| + | const apiUrl = `https:// | ||
| + | |||
| + | return fetch(apiUrl) | ||
| + | .then(response => { | ||
| + | if (!response.ok) { | ||
| + | throw new Error(' | ||
| + | } | ||
| + | return response.json(); | ||
| + | }) | ||
| + | .then(data => { | ||
| + | return data.items && data.items.length > 0 ? data.items[0].volumeInfo : null; | ||
| + | }); | ||
| + | } | ||
| + | |||
| + | function populateFieldsFromGoogle(data) { | ||
| + | const title = data.title || ''; | ||
| + | const subtitle = data.subtitle || ''; | ||
| + | const authors = data.authors || []; | ||
| + | const languageCode = data.language || ''; | ||
| + | const languages = { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | // Add more languages as needed | ||
| + | }; | ||
| + | const language = languages[languageCode] || ' | ||
| + | const yearPublished = data.publishedDate ? data.publishedDate.substring(0, | ||
| + | const monthPublished = data.publishedDate ? data.publishedDate.substring(5, | ||
| + | const dayPublished = data.publishedDate ? data.publishedDate.substring(8, | ||
| + | const pageCount = data.pageCount || ''; | ||
| + | const publisher = data.publisher || ''; | ||
| + | const bookDescription = data.description || ''; | ||
| + | |||
| + | if (itemTypeField.value === '' | ||
| + | itemTypeField.value = ' | ||
| + | } | ||
| + | |||
| + | if (titleField.value === '' | ||
| + | titleField.value = title; | ||
| + | } | ||
| + | |||
| + | if (subtitleField.value === '' | ||
| + | subtitleField.value = subtitle; | ||
| + | } | ||
| + | |||
| + | if (authorField.value === '' | ||
| + | authorField.value = (" | ||
| + | } | ||
| + | |||
| + | languageField.value = language; | ||
| + | |||
| + | if (yearPublishedField.value === '' | ||
| + | yearPublishedField.value = yearPublished; | ||
| + | } | ||
| + | |||
| + | if (monthPublishedField.value === '' | ||
| + | monthPublishedField.value = monthPublished; | ||
| + | } | ||
| + | |||
| + | if (dayPublishedField.value === '' | ||
| + | dayPublishedField.value = dayPublished; | ||
| + | } | ||
| + | |||
| + | if (pageCountField.value === '' | ||
| + | pageCountField.value = pageCount; | ||
| + | } | ||
| + | |||
| + | if (publisherField.value === '' | ||
| + | publisherField.value = (": | ||
| + | } | ||
| + | |||
| + | if (descriptionField.value === '' | ||
| + | descriptionField.value = bookDescription; | ||
| + | } | ||
| + | |||
| + | if (statusField.value === '' | ||
| + | statusField.value = 'niet gestart'; | ||
| + | } | ||
| + | |||
| + | if (plaatsingField.value === '' | ||
| + | plaatsingField.value = ' | ||
| + | } | ||
| + | | ||
| + | // Open thumbnail image in a new window if available | ||
| + | const imagelinks = data.imageLinks || {}; | ||
| + | const thumbnailUrl = imagelinks.thumbnail || ''; | ||
| + | if (thumbnailUrl) { | ||
| + | const thumbnailLink = document.createElement(' | ||
| + | thumbnailLink.href = thumbnailUrl; | ||
| + | thumbnailLink.target = ' | ||
| + | thumbnailLink.textContent = 'Open Thumbnail Image'; | ||
| + | document.body.appendChild(thumbnailLink); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | </ | ||
/var/www/dokuwiki/data/attic/sasteren/boeken-nieuw.1691948884.txt.gz · Laatst gewijzigd: door admin_sasteren
