Last active
May 20, 2024 14:37
-
-
Save VityaSchel/28f1a360ee7798511765910b39c6086c to your computer and use it in GitHub Desktop.
Revisions
-
VityaSchel revised this gist
Oct 1, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ const table = document.querySelector('form[action="https://ks.psuti.ru/about/tea 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) => { -
VityaSchel created this gist
Oct 1, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ 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(3, -3) 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')) }))))