Last active
September 23, 2020 06:57
-
-
Save rayros/ae0b46331bd7407c621d0a2b426cbc5c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env node | |
| const puppeteer = require('puppeteer'); | |
| const pixel2 = puppeteer.devices['Pixel 2']; | |
| const args = process.argv.slice(2); | |
| const login = process.env.NC_LOGIN; | |
| const password = process.env.NC_PASSWORD; | |
| const domain = args[0]; | |
| const record = args[1]; | |
| const value = args[2]; | |
| if (!domain) { | |
| throw new Error('Missing domain argument'); | |
| } | |
| if (!record) { | |
| throw new Error('Missing record argument'); | |
| } | |
| if (!value) { | |
| throw new Error('Missing value argument'); | |
| } | |
| (async () => { | |
| const browser = await puppeteer.launch({ | |
| args: ['--no-sandbox'] | |
| }); | |
| try { | |
| const page = await browser.newPage(); | |
| await page.emulate(pixel2); | |
| await page.goto(`https://ap.www.namecheap.com/Domains/DomainControlPanel/${domain}/advancedns`, { | |
| waitUntil: 'networkidle2' | |
| }); | |
| await page.waitForSelector('input.nc_username'); | |
| await page.focus('input.nc_username'); | |
| await page.keyboard.type(login); | |
| await page.waitForSelector('input.nc_password'); | |
| await page.focus('input.nc_password'); | |
| await page.keyboard.type(password); | |
| await page.click('input[type="submit"]'); | |
| const recordElement = await page.waitForXPath(`//tr[descendant::p[text() = '${record}']]`); | |
| const editButton = await recordElement.$('a.mobile-edit'); | |
| await editButton.click(); | |
| const valueInput = await page.waitForSelector('.content .row input[placeholder="Value"]'); | |
| await valueInput.focus(); | |
| await valueInput.evaluate(el => el.value = ''); | |
| await page.keyboard.type(value); | |
| await page.click('.content .actions .btn'); | |
| await page.waitForXPath(`//tr[descendant::p[text() = '${record}'] and descendant::p[text() = '${value}']]`); | |
| } catch (error) { | |
| await browser.close(); | |
| throw error; | |
| } | |
| await browser.close(); | |
| })().catch(error => { | |
| console.error(error); | |
| process.exit(1); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "namecheap-update-dns", | |
| "version": "1.0.0", | |
| "description": "", | |
| "bin": "index.js", | |
| "main": "index.js", | |
| "scripts": { | |
| "test": "echo \"Error: no test specified\" && exit 1" | |
| }, | |
| "author": "", | |
| "license": "ISC", | |
| "dependencies": { | |
| "puppeteer": "^5.3.0" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment