document.addEventListener('DOMContentLoaded', () => {
const title = document.getElementById('title');
const isbn = document.getElementById('isbn');
const author = document.getElementById('author');
const publisher = document.getElementById('publisher');
const isbncode = '9784003101117'; //ISBNコード
const api_url = `https://ndlsearch.ndl.go.jp/api/sru?operation=searchRetrieve&recordPacking=xml&maximumRecords=1&query=isbn=${isbncode}`;
async function xmlLoad() {
const res = await fetch(api_url);
const text = await res.text();
const xml = new DOMParser().parseFromString(text, 'application/xml');
title.textContent = xml.getElementsByTagName('dc:title')[0].textContent;
isbn.textContent = isbncode;
author.textContent = xml.getElementsByTagName('dc:creator')[0].textContent;
publisher.textContent = xml.getElementsByTagName('dc:publisher')[0].textContent;
const cover = document.getElementById('cover');
const cover_api = `https://ndlsearch.ndl.go.jp/thumbnail/${isbncode}.jpg`;
const checkIfImage = (cover_url) => {
return new Promise((resolve, reject) => {
img.onload = () => resolve(cover_url);
img.onerror = () => reject(cover_url);
cover.innerHTML = `<img src="${cover_api}" alt="カバー画像" width="190" height="280">`;
cover.textContent = '画像なし';