mirror of
https://github.com/vladocar/screenshoteer.git
synced 2024-12-22 13:42:19 +01:00
Clean up path string and title
This commit is contained in:
parent
a0e425353a
commit
bb9afa157a
1 changed files with 7 additions and 13 deletions
20
index.js
20
index.js
|
@ -20,7 +20,7 @@ program
|
|||
if (program.url) urlvalue = program.url
|
||||
else process.exit(console.log("Please add --url parameter. Something like this: $ screenshoteer --url http:www.example.com"));
|
||||
|
||||
!program.fullpage ? fullPage = true : fullPage = JSON.parse(program.fullpage);
|
||||
!program.fullpage ? fullPage = true : fullPage = JSON.parse(program.fullpage);
|
||||
|
||||
console.log(urlvalue);
|
||||
console.log(fullPage);
|
||||
|
@ -37,28 +37,22 @@ console.log(fullPage);
|
|||
async function execute() {
|
||||
const browser = await puppeteer.launch()
|
||||
const page = await browser.newPage()
|
||||
const d = new Date()
|
||||
const timestamp = new Date().getTime()
|
||||
if (program.w && program.h) await page.setViewport({width: Number(program.w), height: Number(program.h)})
|
||||
if (program.emulate) await page.emulate(devices[program.emulate]);
|
||||
await page.goto(urlvalue)
|
||||
const title = await page.title()
|
||||
const t = title.replace(/[/\\?%*:|"<>]/g, '-')
|
||||
const title = (await page.title()).replace(/[/\\?%*:|"<>]/g, '-')
|
||||
if (program.waitfor) await page.waitFor(Number(program.waitfor))
|
||||
if (program.el) {
|
||||
const el = await page.$(program.el);
|
||||
await el.screenshot({
|
||||
path: `${t} ${program.emulate} ${program.el} ${d.getTime()}.png`
|
||||
});
|
||||
await el.screenshot({path: `${title} ${program.emulate} ${program.el} ${timestamp}.png`});
|
||||
} else {
|
||||
await page.screenshot({path: t + " " + program.emulate + " " + d.getTime() + '.png', fullPage: fullPage})
|
||||
await page.screenshot({path: `${title} ${program.emulate} ${timestamp}.png`, fullPage: fullPage})
|
||||
}
|
||||
await page.emulateMedia('screen')
|
||||
if (program.pdf) await page.pdf({ path: t + " " + program.emulate + " " + d.getTime() + '.pdf' })
|
||||
console.log(t)
|
||||
if (program.pdf) await page.pdf({path: `${title} ${program.emulate} ${timestamp}.pdf`})
|
||||
console.log(title)
|
||||
await browser.close()
|
||||
}
|
||||
|
||||
})()
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue