Last active
October 28, 2021 14:41
-
-
Save LoggeL/ffe3204649be0aefa178dab79b5a1a1f to your computer and use it in GitHub Desktop.
PrimitiveJS Automation
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
const puppeteer = require('puppeteer') | |
const fs = require('fs'); | |
// Hardcoded for 200 shapes | |
(async () => { | |
const browser = await puppeteer.launch({ headless: true }) | |
const page = await browser.newPage() | |
await page.goto('https://ondras.github.io/primitive.js/', { waitUntil: 'networkidle0' }) | |
const files = fs.readdirSync('img') // Input Folder | |
for (let i = 0; i < files.length; i++) { | |
let input = await page.$('input[type=file]') | |
await input.uploadFile(`img/${files[i]}`) | |
await page.$eval('input[name=steps]', el => el.value = 200); | |
await page.click('input[type=submit]') | |
await page.click('input[value=vector]') | |
await page.waitForFunction(`document.getElementById("steps").innerText.startsWith("(200 of 200")`) | |
const svg = await page.evaluate(elm => elm.value, await page.$('#vector-text')); | |
fs.writeFileSync(`svg/${files[i].split('.').slice(0, -1).join('.') + '.svg'}`, svg) // Output Folder | |
} | |
await browser.close() | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment