const headers = document.querySelectorAll('section > h2');
const menu = document.querySelector('что здесь должно быть, понятия не имею, сами разберётесь');
menu.innerHTML = Array
.from(headers, n => `<a href="#${n.parentNode.id}">${n.innerHTML}</a>`)
.join('');
for (const { parentNode: p, textContent: t } of headers) {
menu.insertAdjacentHTML(
'beforeend',
'<a href="#' + p.getAttribute('id') + '">' + t + '</a>'
);
}
menu.append(...Array.prototype.map.call(headers, n => {
const a = document.createElement('a');
a.href = '#'.concat(n.parentNode.attributes.id.value);
a.innerText = n.innerText;
return a;
}));
headers.forEach(({ parentNode: { outerHTML } }) => {
const a = document.createElement('a');
a.setAttribute('href', outerHTML.match(/id="(.*?)"/).pop().replace(/^/, '#'));
a.appendChild(document.createTextNode(outerHTML.match(/h2>(.*)<\/h2/)[1]));
menu.insertAdjacentElement('beforeend', a);
});
class AsyncQueue {
constructor(result) {
this.queue = [];
this.result = result;
}
isStreaming = false;
add(promise) {
this.queue.push(promise);
if(!this.isStreaming)
this.stream();
}
async stream() {
this.isStreaming = true;
for await (const result of this.queue) {
this.result(result);
}
this.queue.length = 0;
this.isStreaming = false;
}
}
data() {
const schedulesQueue = new AsyncQueue(this.showLoadedSchedules);
return {
schedulesQueue,
// ...
}
},
methods: {
showLoadedSchedules(response) {
if(this.curDateEvent) {
this.changeMobileDay(this.curDateEvent);
}
// ...
},
addSchedulesToQueue(locationId, gameModeId, selectedHeadsets, day) {
let param = 'locationId=' + locationId + '&gameModeId=' + gameModeId + '&headsets=' + selectedHeadsets
if (day)
param += '&day=' + day;
return this.schedulesQueue.add(
axios({
method: 'get',
url: 'schedules?' + param
}).catch((error) => {})
);
}
}