Untitled

mail@pastecode.io avatar
unknown
javascript
a year ago
15 kB
2
Indexable
Never
/**

 */
const puppeteer = require('puppeteer');
const fs = require('fs');
const readlineSync = require('readline-sync');
const colors = require('colors');


(async () => {
    //untuk pilih tanggal
    const xy = await readlineSync.question("yx|yx : ")
	const start = await readlineSync.question("start : ")
	const end = await readlineSync.question("end : ")
    splited = xy.split("|");

    x_dan_y = []

    for (var i = 0; i < splited.length; i++) {

        split_again = splited[i].split('')

        new_array = [split_again[0], split_again[1]]

        x_dan_y.push(new_array)
    }

    console.log(x_dan_y)


    const browser = await puppeteer.launch({
        headless: true
    })
    const page = await browser.newPage()
	await page.setDefaultNavigationTimeout(0);

    await page.setViewport({
        width: 1280,
        height: 800
    })
    await page.goto('https://simpeg.kemenkumham.go.id/devp/siap/signin.php', {
        waitUntil: ['networkidle0']
    })
    await page.reload({
        waitUntil: ["networkidle0", "domcontentloaded"]
    });

    const navigationPromise = page.waitForNavigation({
        waitUntil: ['networkidle2']
    })

    await page.waitForSelector('[name="user_nip"]')
    //console.log("Found input nip");
    await page.type('input[name="user_nip"]', '199809032017121005', {
        delay: 20
    })
    //console.log("input nip");
    await page.waitForSelector('[name="masuk"]')
    //console.log("Found button login");
    await page.click('[name="masuk"]')
    await page.waitForSelector('input[name="vpassword"]', {
        visible: true
    })
    //console.log("Found input password");
    await page.type('input[name="vpassword"]', 'Sinergi123', {
        delay: 20
    })
    //console.log("input password");
    await page.keyboard.press('Enter')
    console.log("Login SIMPEG");
    await page.waitForTimeout(5000);
    await page.waitForSelector('[title="KINERJA"]')
    //console.log("Found kinerja");
    await page.click('[title="KINERJA"]')
    //console.log("go to kinerja");
    for (var i = 0; i < x_dan_y.length; i++) {
        cell = x_dan_y[i][0]
        kolom = x_dan_y[i][1]
        await page.goto('https://simpeg.kemenkumham.go.id/devp/siap/skp_journal.php', {
            waitUntil: ['networkidle0']
        })
        await page.reload({
            waitUntil: ["networkidle0", "domcontentloaded"]
        });


        //pilih tanggal
        await page.waitForSelector('[name="tgla"]')
        console.log("Found tanggal");
        await page.click('[name="tgla"]')
        await page.waitForSelector('#tgla')
		//await page.waitForSelector('body > div.datepicker.datepicker-dropdown.dropdown-menu > div.datepicker-days > table > thead > tr:nth-child(1) > th.prev')
		//await page.waitForTimeout(2000)
		//const mundur = ("body > div.datepicker.datepicker-dropdown.dropdown-menu > div.datepicker-days > table > thead > tr:nth-child(1) > th.prev")
		//await page.evaluate((mundur) => document.querySelector(mundur).click(), mundur);

        //console.log("found2");
        await page.waitForSelector('div.datepicker.datepicker-dropdown.dropdown-menu > div.datepicker-days > table > tbody > tr:nth-child(' + cell + ') > td:nth-child(' + kolom + ')')
        //console.log("valid");
        await page.waitForTimeout(2000)
        const selector = (" div.datepicker.datepicker-dropdown.dropdown-menu > div.datepicker-days > table > tbody > tr:nth-child(" + cell + ") > td:nth-child(" + kolom + ")")
        await page.evaluate((selector) => document.querySelector(selector).click(), selector);
        await page.waitForTimeout(5000);
        console.log("wait 5s");
        await page.click('[id="tambah"]')
        await page.waitForTimeout(5000);
        console.log("wait 5s");
        //mulai isi form
        await page.waitForSelector('#jammulai')
        //console.log("found2");
        await page.select("#jammulai", start)
        await page.waitForSelector('#menitmulai')
        //console.log("found3");
        await page.select("#menitmulai", "01")
        await page.waitForSelector('#jamselesai')
        //console.log("found4");
        await page.select("#jamselesai", end)
        await page.waitForSelector('#menitselesai')
        //console.log("found5");
        await page.select("#menitselesai", "01")

        //1. 
        await page.waitForSelector('[value="202319980903532210101_01"]')
        //console.log("found1");
        await page.select("#skpkgid", "202319980903532210101_01")
        await page.waitForSelector('[name="keterangan"]')
        //console.log("Found keterangan");
        await page.type('#keterangan', 'Menjaga pintu keluar masuk pengunjung, WBP/Tahanan yang dikunjungi, melakukan penggeledahan, melakukan pencatatan, pencocokan ID, memegang timer, mengawasi aktivitas dalam area kunjungan.', {
            delay: 20
        })
        await page.waitForSelector('[id="jumlah"]')
        //console.log("jumlah");
        await page.click("input[id=jumlah]", {
            clickCount: 3
        });
        await page.keyboard.press('Backspace')
        await page.type('input[id="jumlah"]', '1', {
            delay: 20
        })
        //console.log("set jumlah");
        await page.click('[id="btnsimpan"]')
        await page.waitForTimeout(3000)
        await page.waitForSelector('[id="btnok"]')
        await page.click('[id="btnok"]')
        console.log('202319980903532210101_01'.random);
        await page.waitForTimeout(4000)

        //2. 
        await page.click('[id="tambah"]')
        await page.waitForTimeout(5000);
        //console.log("wait 5s");
        await page.waitForSelector('[value="202319980903532210101_02"]')
        //console.log("found1");
        await page.select("#skpkgid", "202319980903532210101_02")
        await page.waitForSelector('[name="keterangan"]')
        //console.log("Found keterangan");
        await page.type('#keterangan', 'Menjaga pintu steril dan melakukan pengamanan lalu lintas pada area tersebut.', {
            delay: 20
        })
        await page.waitForSelector('[id="jumlah"]')
        //console.log("jumlah");
        await page.click("input[id=jumlah]", {
            clickCount: 3
        });
        await page.keyboard.press('Backspace')
        await page.type('input[id="jumlah"]', '1', {
            delay: 20
        })
        //console.log("set jumlah");
        await page.click('[id="btnsimpan"]')
        await page.waitForTimeout(3000)
        await page.waitForSelector('[id="btnok"]')
        await page.click('[id="btnok"]')
        console.log('202319980903532210101_02'.random);
        await page.waitForTimeout(4000)

        //3.
        await page.click('[id="tambah"]')
        await page.waitForTimeout(5000);
        //console.log("wait 5s");
        await page.waitForSelector('[value="202319980903532210101_03"]')
        //console.log("found1");
        await page.select("#skpkgid", "202319980903532210101_03")
        await page.waitForSelector('[name="keterangan"]')
        //console.log("Found keterangan");
        await page.type('#keterangan', 'Mengawasi kegiatan yang berlangsung di dapur.', {
            delay: 20
        })
        await page.waitForSelector('[id="jumlah"]')
        //console.log("jumlah");
        await page.click("input[id=jumlah]", {
            clickCount: 3
        });
        await page.keyboard.press('Backspace')
        await page.type('input[id="jumlah"]', '1', {
            delay: 20
        })
        //console.log("set jumlah");
        await page.click('[id="btnsimpan"]')
        await page.waitForTimeout(3000)
        await page.waitForSelector('[id="btnok"]')
        await page.click('[id="btnok"]')
        await page.waitForTimeout(2000)
        console.log('202319980903532210101_03'.random);

        //4.
        await page.click('[id="tambah"]')
        await page.waitForTimeout(5000);
        //console.log("wait 5s");
        await page.waitForSelector('[value="202319980903532210101_04"]')
        //console.log("found1");
        await page.select("#skpkgid", "202319980903532210101_04")
        await page.waitForSelector('[name="keterangan"]')
        //console.log("Found keterangan");
        await page.type('#keterangan', 'Mengawasi kegiatan yang berlangsung di area tempat ibadah.', {
            delay: 20
        })
        await page.waitForSelector('[id="jumlah"]')
        //console.log("jumlah");
        await page.click("input[id=jumlah]", {
            clickCount: 3
        });
        await page.keyboard.press('Backspace')
        await page.type('input[id="jumlah"]', '1', {
            delay: 20
        })
        //console.log("set jumlah");
        await page.click('[id="btnsimpan"]')
        await page.waitForTimeout(3000)
        await page.waitForSelector('[id="btnok"]')
        await page.click('[id="btnok"]')
        await page.waitForTimeout(2000)
        console.log('202319980903532210101_04'.random);

        //5.
        await page.click('[id="tambah"]')
        await page.waitForTimeout(5000);
        //console.log("wait 5s");
        await page.waitForSelector('[value="202319980903532210101_05"]')
        //console.log("found1");
        await page.select("#skpkgid", "202319980903532210101_05")
        await page.waitForSelector('[name="keterangan"]')
        //console.log("Found keterangan");
        await page.type('#keterangan', 'Mengawasi lalu lintas pasien tahanan/WBP di poliklinik.', {
            delay: 20
        })
        await page.waitForSelector('[id="jumlah"]')
        //console.log("jumlah");
        await page.click("input[id=jumlah]", {
            clickCount: 3
        });
        await page.keyboard.press('Backspace')
        await page.type('input[id="jumlah"]', '1', {
            delay: 20
        })
        //console.log("set jumlah");
        await page.click('[id="btnsimpan"]')
        await page.waitForTimeout(3000)
        await page.waitForSelector('[id="btnok"]')
        await page.click('[id="btnok"]')
        await page.waitForTimeout(2000)
        console.log('202319980903532210101_05'.random);

        //6.
        await page.click('[id="tambah"]')
        await page.waitForTimeout(5000);
        //console.log("wait 5s");
        await page.waitForSelector('[value="202319980903532210101_06"]')
        //console.log("found1");
        await page.select("#skpkgid", "202319980903532210101_06")
        await page.waitForSelector('[name="keterangan"]')
        //console.log("Found keterangan");
        await page.type('#keterangan', 'Mengawasi jalannya kegiatan di dalam perpustakaan.', {
            delay: 20
        })
        await page.waitForSelector('[id="jumlah"]')
        //console.log("jumlah");
        await page.click("input[id=jumlah]", {
            clickCount: 3
        });
        await page.keyboard.press('Backspace')
        await page.type('input[id="jumlah"]', '1', {
            delay: 20
        })
        //console.log("set jumlah");
        await page.click('[id="btnsimpan"]')
        await page.waitForTimeout(3000)
        await page.waitForSelector('[id="btnok"]')
        await page.click('[id="btnok"]')
        await page.waitForTimeout(2000)
        console.log('202319980903532210101_06'.random);

        //7.
        await page.click('[id="tambah"]')
        await page.waitForTimeout(5000);
        //console.log("wait 5s");
        await page.waitForSelector('[value="202319980903532210101_07"]')
        //console.log("found1");
        await page.select("#skpkgid", "202319980903532210101_07")
        await page.waitForSelector('[name="keterangan"]')
        //console.log("Found keterangan");
        await page.type('#keterangan', 'Mengawasi jalannya kegiatan kerja/ bimbingan kerja pada area yang telah disediakan, memastikan para WBP/Tahanan tidak membawa alat-alat yang digunakan saat melakukan kegiatan kerja ke dalam area steril dan blok.', {
            delay: 20
        })
        await page.waitForSelector('[id="jumlah"]')
        //console.log("jumlah");
        await page.click("input[id=jumlah]", {
            clickCount: 3
        });
        await page.keyboard.press('Backspace')
        await page.type('input[id="jumlah"]', '1', {
            delay: 20
        })
        //console.log("set jumlah");
        await page.click('[id="btnsimpan"]')
        await page.waitForTimeout(3000)
        await page.waitForSelector('[id="btnok"]')
        await page.click('[id="btnok"]')
        await page.waitForTimeout(2000)
        console.log('202319980903532210101_07'.random);

        //8.
        await page.click('[id="tambah"]')
        await page.waitForTimeout(5000);
        //console.log("wait 5s");
        await page.waitForSelector('[value="202319980903532210101_08"]')
        //console.log("found1");
        await page.select("#skpkgid", "202319980903532210101_08")
        await page.waitForSelector('[name="keterangan"]')
        //console.log("Found keterangan");
        await page.type('#keterangan', 'Melakukan pengawasan secara keliling atau melakukan pengawalan kegiatan di luar/asimilasi.', {
            delay: 20
        })
        await page.waitForSelector('[id="jumlah"]')
        //console.log("jumlah");
        await page.click("input[id=jumlah]", {
            clickCount: 3
        });
        await page.keyboard.press('Backspace')
        await page.type('input[id="jumlah"]', '1', {
            delay: 20
        })
        //console.log("set jumlah");
        await page.click('[id="btnsimpan"]')
        await page.waitForTimeout(3000)
        await page.waitForSelector('[id="btnok"]')
        await page.click('[id="btnok"]')
        await page.waitForTimeout(2000)
        console.log('202319980903532210101_08'.random);

        //9.
        await page.click('[id="tambah"]')
        await page.waitForTimeout(5000);
        //console.log("wait 5s");
        await page.waitForSelector('[value="202319980903532210101_09"]')
        //console.log("found1");
        await page.select("#skpkgid", "202319980903532210101_09")
        await page.waitForSelector('[name="keterangan"]')
        //console.log("Found keterangan");
        await page.type('#keterangan', 'Menjaga pos di menara.', {
            delay: 20
        })
        await page.waitForSelector('[id="jumlah"]')
        //console.log("jumlah");
        await page.click("input[id=jumlah]", {
            clickCount: 3
        });
        await page.keyboard.press('Backspace')
        await page.type('input[id="jumlah"]', '1', {
            delay: 20
        })
        //console.log("set jumlah");
        await page.click('[id="btnsimpan"]')
        await page.waitForTimeout(3000)
        await page.waitForSelector('[id="btnok"]')
        await page.click('[id="btnok"]')
        await page.waitForTimeout(2000)
        console.log('202319980903532210101_09'.random);
    }


    await navigationPromise

    await browser.close()
})()