const puppeteer = require('puppeteer');
const readline = require('readline');


const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

async function loginAndComment(email, password, targetUrl, comment) {
    const browser = await puppeteer.launch({ headless: false });
    const page = await browser.newPage();

    await page.goto('https://www.facebook.com/');

    await page.waitForSelector('input#email');
    await page.type('input#email', email); 
    
    await page.waitForSelector('input#pass');
    await page.type('input#pass', password); 
    

    await page.click('button[name="login"]');
    

    await page.waitForNavigation();


    await page.goto(targetUrl);


    await page.waitForSelector('[contenteditable="true"]'); 

    let startTime = Date.now();
    let timeLimit = 15 * 60 * 1000; 

    while (Date.now() - startTime < timeLimit) {
     
        const commentBox = await page.waitForSelector('[contenteditable="true"]');

    
        await page.type('[contenteditable="true"]', comment);  

       
        await page.keyboard.press('Enter');

        await page.waitForTimeout(3000);
    }

    console.log('Proses komentar selesai.');
    

    await browser.close();
}


rl.question('Masukkan email Facebook Anda: ', (email) => {
    rl.question('Masukkan password Facebook Anda: ', (password) => {
        const targetUrl = 'https://web.facebook.com/photo/?fbid=122109899384635535&set=a.122107172762635535'; 
        const comment = 'Ming Cibai Was Here';
        
        loginAndComment(email, password, targetUrl, comment).catch(console.error);
        
   
        rl.close();
    });
});
