(() => { var quiz = [], nQuiz, pos=0; var csvfile = "gourmet-men.csv"; function putValues(row) { for (let key of Object.keys(row)) { let id = "__" + key + "__"; let elem = document.getElementById(id); if (elem) { if(id == "__写真img__"|| id == "__メニュー写真1__" || id == "__メニュー写真2__" || id == "__メニュー写真3__"||id == "__VR__"){ elem.src = row[key]; } else{ elem.innerText = row[key]; } } } } function slide(n) { pos = (nQuiz+pos+n) % nQuiz; putValues(quiz[pos]); } function left() {slide(-1);} function right() {slide(1);} function init() { fetch(csvfile) .then((resp) => { if (resp.ok) return resp.text(); }).then((txt) => { quiz = new CSV(txt, {header: true}).parse(); nQuiz = quiz.length; putValues(quiz[pos]); });; document.getElementById("left").addEventListener("click", left); document.getElementById("right").addEventListener("click", right); } document.addEventListener("DOMContentLoaded", ()=>{ init(); }, false); })();