From f46fd759a26b290dda3d79a966857f269a312def Mon Sep 17 00:00:00 2001 From: titi_2115 <73474137+jasiukiewicztymon@users.noreply.github.com> Date: Sun, 20 Mar 2022 12:31:20 +0100 Subject: [PATCH] Update index.js --- index.js | 68 ++++++++++++++++++++++++++------------------------------ 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/index.js b/index.js index 45709c7..4d4f192 100644 --- a/index.js +++ b/index.js @@ -29,47 +29,43 @@ var date = "", convocation = "", res = "", ok = false; await page.waitForSelector('strong'); const text = await page.evaluate(() => Array.from(document.querySelectorAll('strong')[document.querySelectorAll('strong').length - 1].parentElement.querySelectorAll('strong'), element => element.textContent)); while (text.length != 0) { - for (var i = 0; i < text.length; i++) { - if (i == 0) - break; - convocation = text[0]; - text.shift() - date = convocation.substr((convocation.indexOf('.') - 2), 5) - if (!data.date.includes(date)) { - for (var i = 0; i < data.place.length; i++) { - e = data.place[i]; - if (convocation.toLowerCase().includes(e)) { - (async function type() { - res = date + " " + e + ", " + data.name + " dispo" - - for (var j = 0; j < res.length; j++) { - page.keyboard.press(res[j]); - ok = true; - } - - try { - page.click("span[data-testid='send']") - } - catch {} - - data.date.push(date); - fs.writeFile('./data.json', JSON.stringify(data), function writeJSON(err) { - if (err) return console.log(err); - }); - })(); - break; - } + convocation = text[text.length - 1]; + text.pop() + date = convocation.substr((convocation.indexOf('.') - 2), 5) + if (!data.date.includes(date)) { + for (var i = 0; i < data.place.length; i++) { + e = data.place[i]; + if (convocation.toLowerCase().includes(e)) { + (async function type() { + res = date + " " + e + ", " + data.name + " dispo" + + for (var j = 0; j < res.length; j++) { + page.keyboard.press(res[j]); + ok = true; + } + + page.keyboard.down('Shift') + page.keyboard.press('Enter') + page.keyboard.up('Shift') + + data.date.push(date); + fs.writeFile('./data.json', JSON.stringify(data), function writeJSON(err) { + if (err) return console.log(err); + }); + })(); + break; } } } - - if (ok) { - page.keyboard.press('Enter'); - ok = false; - } } + if (ok) { + page.click("span[data-testid='send']") + ok = false; + } + } + catch (e) { + console.log(e) } - catch {} } } catch (err) {