|
#!/usr/bin/env node |
|
|
|
const { chromium } = require('playwright'); |
|
const util = require('util'); |
|
const setTimeoutPromise = util.promisify(setTimeout); |
|
|
|
(async () => { |
|
const browser = await chromium.connectOverCDP('http://localhost:9222'); |
|
const ctx = browser.contexts()[0]; |
|
const pages = await ctx.pages(); |
|
const page = pages[0]; |
|
await page.goto('https://my.15five.com/report/archive/'); |
|
|
|
// wait for page to be ready |
|
await page.waitForSelector('text=Fill out', { timeout: 3000 }); |
|
console.log("I see a check-in to fill out!"); |
|
await page.click('text=Fill out'); |
|
|
|
await page.waitForLoadState(); |
|
if (await page.$('#fillout-report-form')) { |
|
console.log("Found form. Let's get you sorted!"); |
|
await fillOut15Five(page); |
|
} else { |
|
console.log("No form. You already submitted, I think. Bye."); |
|
} |
|
|
|
await setTimeoutPromise(1000); |
|
await browser.close(); |
|
})(); |
|
|
|
async function fillOut15Five(page) { |
|
await page.click('label[for="pulse-input-4"]'); |
|
console.log("happiness=4"); |
|
|
|
let complete = 'button[aria-label="Mark Complete"]'; |
|
if (await page.$(complete)) { |
|
await page.click(complete); |
|
console.log("marked complete"); |
|
} |
|
|
|
let goal = '.is-new-answer[placeholder="Add a new priority"]'; |
|
const input = await page.locator(goal).nth(-1); |
|
if (input) { |
|
await input.fill('code'); |
|
await page.click('body'); |
|
console.log("goal for next week: code"); |
|
} |
|
|
|
console.log("Submitting..."); |
|
await setTimeoutPromise(3000); |
|
await page.click('.js-submit-report >> text=ubmit'); |
|
// if early, there'll be 2nd |
|
let submit2 = 'text=Submit now'; |
|
await page.waitForSelector(submit2, { timeout: 1000 }).then(() => { |
|
console.log("...Now tho. Submit now."); |
|
return page.click(submit2); |
|
}).catch(() => console.log("You're on time! Good job!")); |
|
await page.waitForNavigation(); |
|
console.log("done. great job!"); |
|
} |