diff --git a/README.md b/README.md index e9d6921..4dd9cea 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This tool allows you to automatically check-in and check-out on HRLog (MAC only 2. Create a scripts folder under `~/.scripts` -3. Place the `hrlog-auto-...` script under `~/.scripts`. The script accepts 3 params in the following order: email, password, showWindow (this last is for debug purposes only) +3. Place the `hrlog-auto-...` script under `~/.scripts`. The script accepts 4 params in the following order: email(string), password(string), type(string, 'check-in' or 'check-out'), showWindow(boolean/number, this last is for debug purposes only) 4. Modify the `crontab.txt` call to the script to include your credentials by replacing "YOUR_EMAIL" and "YOUR_PASSWORD" diff --git a/crontab.txt b/crontab.txt index 1945116..8b286b1 100644 --- a/crontab.txt +++ b/crontab.txt @@ -1,2 +1,2 @@ -05 9 * * 1-5 ~/.scripts/hrlog-auto-macos YOUR_EMAIL YOUR_PASSWORD -05 17 * * 1-5 ~/.scripts/hrlog-auto-macos YOUR_EMAIL YOUR_PASSWORD +05 9 * * 1-5 ~/.scripts/hrlog-auto-macos YOUR_EMAIL YOUR_PASSWORD check-in +05 17 * * 1-5 ~/.scripts/hrlog-auto-macos YOUR_EMAIL YOUR_PASSWORD check-out diff --git a/main.js b/main.js index 926f083..41f4dce 100644 --- a/main.js +++ b/main.js @@ -1,12 +1,11 @@ const { chromium } = require('playwright'); (async () => { - const [email, password, showWindow] = process.argv.slice(2) + const [email, password, type, showWindow] = process.argv.slice(2) // Setup const browser = await chromium.launch(showWindow ? {headless: false} : {headless: true}); const context = await browser.newContext({permissions: ['geolocation']}); const page = await context.newPage(); - // The actual interesting bit await page.goto('https://app.hrlog.es/admin/login'); @@ -19,7 +18,8 @@ const { chromium } = require('playwright'); await page.waitForURL('**/secure/dashboard'); - await page.locator('#div-fichaje-action').click(); + const textToSearch = type === 'check-in' ? 'Entrada trabajo' : 'Salida trabajo'; + await page.getByText(textToSearch).click(); await page.waitForResponse((response) => response.url().includes("/secure/ajax-ultimo-fichaje")); // Teardown diff --git a/package-lock.json b/package-lock.json index c593d49..5fb733f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,37 +1,53 @@ { "name": "hrlog-auto", - "version": "1.1.0", + "version": "2.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "hrlog-auto", - "version": "1.1.0", + "version": "2.1.0", "license": "ISC", "devDependencies": { - "playwright": "1.36.1" + "playwright": "1.38.0" } }, - "node_modules/playwright": { - "version": "1.36.1", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.36.1.tgz", - "integrity": "sha512-2ZqHpD0U0COKR8bqR3W5IkyIAAM0mT9FgGJB9xWCI1qAUkqLxJskA1ueeQOTH2Qfz3+oxdwwf2EzdOX+RkZmmQ==", + "node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", "dev": true, "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/playwright": { + "version": "1.38.0", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.38.0.tgz", + "integrity": "sha512-fJGw+HO0YY+fU/F1N57DMO+TmXHTrmr905J05zwAQE9xkuwP/QLDk63rVhmyxh03dYnEhnRbsdbH9B0UVVRB3A==", + "dev": true, "dependencies": { - "playwright-core": "1.36.1" + "playwright-core": "1.38.0" }, "bin": { "playwright": "cli.js" }, "engines": { "node": ">=16" + }, + "optionalDependencies": { + "fsevents": "2.3.2" } }, "node_modules/playwright-core": { - "version": "1.36.1", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.36.1.tgz", - "integrity": "sha512-7+tmPuMcEW4xeCL9cp9KxmYpQYHKkyjwoXRnoeTowaeNat8PoBMk/HwCYhqkH2fRkshfKEOiVus/IhID2Pg8kg==", + "version": "1.38.0", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.38.0.tgz", + "integrity": "sha512-f8z1y8J9zvmHoEhKgspmCvOExF2XdcxMW8jNRuX4vkQFrzV4MlZ55iwb5QeyiFQgOFCUolXiRHgpjSEnqvO48g==", "dev": true, "bin": { "playwright-core": "cli.js" diff --git a/package.json b/package.json index 3c4c4c3..87a02b5 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { "name": "hrlog-auto", - "version": "2.1.0", + "version": "3.0.0", "description": "", "main": "main.js", "keywords": [], "author": "", "license": "ISC", "devDependencies": { - "playwright": "1.36.1" + "playwright": "1.38.0" } }