const Stand_list = { list: [], init: async () => { let html = await fetch('/lib/pages/stand/list/index.html').then((response) => response.text()); app.innerHTML = html; Stand_list.setHTML(); if (USER.possibilities.can_add_stand) { document.getElementById("buttons-list").style.display = "flex"; document.getElementById("constructorButton").style.display = ""; } }, loadAPI: async function (url) { const uuid = localStorage.getItem("uuid"); const response = await fetch(url, { method: 'GET', headers: { "Content-Type": "application/json", "Authorization": uuid } }); Stand_list.list = await response.json(); return Stand_list.list; }, setHTML: async function () { const block = document.getElementById('list'); const null_list = document.getElementById('null-list'); const load_list = document.getElementById('load-list'); null_list.setAttribute("data-visible", "false"); load_list.setAttribute("data-visible", "true"); const url = `${CONFIG.api}stand/list`; let list = this.list.length > 0 ? this.list : await this.loadAPI(url); if (list.length == 0) { null_list.setAttribute("data-visible", "true"); load_list.setAttribute("data-visible", "false"); return; } else { null_list.setAttribute("data-visible", "false"); load_list.setAttribute("data-visible", "false"); let html = ""; for (const element of list) { html += this.renderCard({ element }); } block.innerHTML = html; } }, renderCard: ({ element, pack=0 }) => { const images = [ ['stand_1.png', 'stand_2.png', 'stand_3.png'], ['stand_4.png', 'stand_5.png'] ]; const randomImage = images[pack][Math.floor(Math.random() * images[pack].length)]; const editor = USER.possibilities.can_add_stand ? `` : ``; return `

${element.title}

${editor}
`; }, }