Skip to content

Instantly share code, notes, and snippets.

@LoggeL
Last active October 28, 2021 14:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LoggeL/ffe3204649be0aefa178dab79b5a1a1f to your computer and use it in GitHub Desktop.
Save LoggeL/ffe3204649be0aefa178dab79b5a1a1f to your computer and use it in GitHub Desktop.
PrimitiveJS Automation
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