document.getElementById("app-window").innerHTML = "

Загрузка произведений...

"; function toggleShow(authorId) { document.getElementById(`playlist-author-${authorId}`).hidden = !document.getElementById(`playlist-author-${authorId}`).hidden; } function showAudio(settingsAuthors, settingsAudio) { showAudio.settingsAuthors = settingsAuthors; showAudio.settingsAudio = settingsAudio; const step2 = (music) => { //console.log(music.items); const showedAuthors = [ ...new Set(music.items.map((i) => `author-${i.author_id}`)), ]; [...document.getElementsByClassName("author-element")].forEach((el) => { if ( JSON.stringify(settingsAuthors) === "{}" && JSON.stringify(settingsAudio) === "{}" ) { if (!showedAuthors.includes(el.id)) { const id = el.id.slice(7); document.getElementById(`loader-music-${id}`).innerHTML = "

Пусто. Добавьте произведения

"; } return; } el.hidden = !showedAuthors.includes(el.id); }); music.items .sort((a, b) => a.date - b.date) .forEach((music) => { document.getElementById( `loader-music-${music.author_id}`, ).hidden = true; if (music.is_data_exists) document.getElementById( `playlist-author-${music.author_id}`, ).innerHTML += `

${music.name}

`; else document.getElementById( `playlist-author-${music.author_id}`, ).innerHTML += `

${music.name}

`; }); }; api.getAuthors(settingsAuthors, (authors) => { document.getElementById("app-window").innerHTML = ""; authors.items .sort((a, b) => a.date - b.date) .forEach((author) => { document.getElementById( "app-window", ).innerHTML += `

${author.name}

Произведения


Показать/Скрыть

Загрузка..

`; const addMusicButtonFunct = () => setTimeout( () => (document.getElementById( `add-music-button-${author.id}`, ).onclick = async () => { // console.log('>>', author.id); document.getElementById( `add-music-${author.id}`, ).innerHTML = `

`; setTimeout(() => { document.getElementById( `cancel-add-music-${author.id}`, ).onclick = function () { document.getElementById( `add-music-${author.id}`, ).innerHTML = `
`; addMusicButtonFunct(); }; document.getElementById(`add-music-act-${author.id}`).onclick = function () { if ( document.getElementById(`music-name-input-${author.id}`) .value.length >= 2 ) { api.createMusic( author.id, document.getElementById( `music-name-input-${author.id}`, ).value, document.getElementById(`attach-file-${author.id}`) .filedata, () => { showAudio(settingsAuthors, settingsAudio); }, ); document.getElementById( `add-music-${author.id}`, ).innerHTML = "Добавление файла..."; } }; document.getElementById(`attach-file-${author.id}`).onclick = function () { const input = document.createElement("input"); input.type = "file"; input.accept = "audio/mpeg"; input.click(); input.onchange = function (e) { function arrayBufferToBase64(buffer) { let binary = ""; let bytes = new Uint8Array(buffer); let len = bytes.byteLength; for (let i = 0; i < len; i++) { binary += String.fromCharCode(bytes[i]); } return window.btoa(binary); } const file = e.target.files[0]; // console.log(file); const reader = new FileReader(); reader.readAsArrayBuffer(file); reader.onload = function () { // console.log('reader.result', reader.result); if (file.type === "audio/mpeg") { document.getElementById( `attach-file-${author.id}`, ).filedata = arrayBufferToBase64(reader.result); document.getElementById( `attach-file-${author.id}`, ).innerText = "Загружен файл: " + file.name; } // console.log(arrayBufferToBase64(reader.result)); }; }; }; }, 0); }), 0, ); addMusicButtonFunct(); }); api.getMusic(settingsAudio, step2); document.getElementById("app-window").innerHTML += '
'; }); } setTimeout(() => showAudio({}, {}), 0); document.getElementById("search-input").onchange = function () { console.log(this.value); setTimeout( () => showAudio( {}, { q: this.value, }, ), 0, ); };