Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //npm install clipboardy
- //npm i puppeteer
- // https://nitayneeman.com/posts/getting-to-know-puppeteer-using-practical-examples/
- // gmail keyboard shortcuts
- // https://support.google.com/mail/answer/6594?co=GENIE.Platform%3DDesktop&hl=en
- const puppeteer = require('puppeteer');
- const clipboard = require('clipboardy');
- var userClipboard = clipboard.readSync();
- //console.log(clipboard.readSync()); // get clipboard contents
- (async () => {
- const browser = await puppeteer.launch({ headless: false });
- const page = await browser.newPage();
- await page.goto('https://accounts.google.com/signin/v2/identifier?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin');
- // enter email username
- console.log("Entering email...");
- await page.keyboard.sendCharacter('#############@gmail.com');
- await page.keyboard.press(String.fromCharCode(13));
- //await new Promise(resolve => setTimeout(resolve, 1500));
- await page.waitForNavigation({ waitUntil: 'networkidle2' });
- // enter email password
- console.log("Entering password...");
- await page.keyboard.sendCharacter('##########', {delay: 100});
- await page.keyboard.press(String.fromCharCode(13));
- await new Promise(resolve => setTimeout(resolve, 5000)); // wait for gmail to load a little bit (wait for navigation doesnt really work for some reason)
- const emailPage = await browser.newPage();
- await emailPage.goto('https://mail.google.com/mail/u/0/#inbox/##################', {waitUntil: 'domcontentloaded'});
- console.log("Thread opened...");
- await emailPage.waitForNavigation({ waitUntil: 'networkidle2' });
- await emailPage.keyboard.press(String.fromCharCode(82));
- await emailPage.keyboard.type('text', {delay: 100});
- await emailPage.keyboard.press(String.fromCharCode(13)); // new line
- await emailPage.keyboard.type(userClipboard, {delay: 100});
- await emailPage.keyboard.down('Command');
- await emailPage.keyboard.press(String.fromCharCode(13));
- await emailPage.keyboard.up('Command');
- //await emailPage.screenshot({path: 'screenshot.png'});
- await new Promise(resolve => setTimeout(resolve, 5000));
- await browser.close();
- console.log("done");
- })();
Add Comment
Please, Sign In to add comment