if(window.location.href !== 'https://ks.psuti.ru/about/teachers.html') throw new Error('Перейдите на страницу https://ks.psuti.ru/about/teachers.html') const table = document.querySelector('form[action="https://ks.psuti.ru/about/teachers.html"') const limitField = table.querySelector('select[name="limit"]') if(limitField.options[limitField.selectedIndex].text !== 'Все') throw new Error('Выберете "Все" в "Количество строк"') const teachers = Array.from(table.querySelectorAll('tbody > tr > td:last-child > a')).slice(1) const getTeacherInfo = (url) => { return new Promise((resolve, reject) => { const handle = window.open(url) const onLoaded = async () => { try { resolve(handle.document.querySelector('.article-content img').src) handle.close() } catch(e) { reject(e) } } let intervalID = setInterval(() => { try { if (handle && handle.document && handle.location.href !== 'about:blank') { clearInterval(intervalID) if (['complete', 'interactive'].includes(handle.document.readyState)) { onLoaded() } else { handle.addEventListener('DOMContentLoaded', onLoaded) } } } catch (e) { // Keep waiting for load } }, 100) }) } // beware as it opens a lot of windows simultaniously console.log(await Promise.all(teachers.map(async t => ({ name: t.textContent.trim(), picture: await getTeacherInfo(t.getAttribute('href')) }))))