Skip to content

Instantly share code, notes, and snippets.

@VityaSchel
Last active May 20, 2024 14:37
Show Gist options
  • Select an option

  • Save VityaSchel/28f1a360ee7798511765910b39c6086c to your computer and use it in GitHub Desktop.

Select an option

Save VityaSchel/28f1a360ee7798511765910b39c6086c to your computer and use it in GitHub Desktop.

Revisions

  1. VityaSchel revised this gist Oct 1, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion teachers.js
    Original 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(3, -3)
    const teachers = Array.from(table.querySelectorAll('tbody > tr > td:last-child > a')).slice(1)

    const getTeacherInfo = (url) => {
    return new Promise((resolve, reject) => {
  2. VityaSchel created this gist Oct 1, 2023.
    40 changes: 40 additions & 0 deletions teachers.js
    Original 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')) }))))