1/** 2 * @returns {Promise<{author: string, source: string, date: string, content: string}[]>} 3 */ 4async function loadQuotes() { 5 // æ¬å½ã¯JSON Modulesã使ãããããæ°ããæ©è½ãããã©ã¦ã¶ã§ã®ãµãã¼ããçãããã®ã§`fetch`ã使ã 6 const response = await fetch("/_script/quotes.json"); 7 if (!response.ok) { 8 throw new Error(); 9 } 10 return response.json(); 11} 12 13async function getQuote() { 14 const quotes = await loadQuotes(); 15 const randomIndex = Math.floor(Math.random() * quotes.length); 16 return quotes[randomIndex]; 17} 18 19/** 20 * @param {{author: string, source: string, date: string, content: string}} quote 21 */ 22function showQuote(quote) { 23 const qTag = document.querySelector("#quote-content"); 24 const authorTag = document.querySelector("#quote-author"); 25 const dateTag = document.querySelector("#quote-date"); 26 qTag.textContent = quote.content; 27 authorTag.textContent = quote.author; 28 dateTag.textContent = quote.date.split("T")[0].replaceAll("-", "/"); 29} 30 31document.addEventListener('DOMContentLoaded', async () => { 32 try { 33 const quote = await getQuote(); 34 showQuote(quote); 35 } catch (e) { 36 console.error(e); 37 } 38});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.