1/* global Yun, CONFIG */ 2 3/** 4 * æ¾ç¤ºä¸å¥è¯ 5 * @param {string} content 6 * @param {string} author 7 * @param {string} from 8 */ 9function say(content, author, from) { 10 document.querySelector("#say-content").innerText = content; 11 if (author) { 12 document.querySelector("#say-author").innerText = author; 13 } 14 if (from) { 15 document.querySelector("#say-from").innerText = "ã" + from + "ã"; 16 } 17} 18 19/** 20 * è·åå¨çº¿ API 21 */ 22function fetchApiToSay() { 23 if (CONFIG.say.api) { 24 fetch(CONFIG.say.api) 25 .then((res) => { 26 if (res.ok) { 27 res.json().then((data) => { 28 if (CONFIG.say.hitokoto) { 29 say(data.hitokoto, data.from_who, data.from); 30 } else { 31 let sentence = data[Math.floor(Math.random() * data.length)]; 32 if (sentence.content) { 33 say(sentence.content, sentence.author, sentence.from); 34 } else { 35 say(sentence); 36 } 37 } 38 }); 39 } else { 40 throw new Error( 41 CONFIG.say.api + ", HTTP error, status = " + res.status 42 ); 43 } 44 }) 45 .catch((err) => { 46 console.error(err.message); 47 }); 48 } 49}
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.