// Recipe Importer screenshots for the website card: on scratch guest 9202, headless Chrome through the box's own // traefik, passing the setup gate as the household. No recipe site is contacted (a scraped recipe would be a third // party's text and picture). The app's own settings form is saved with an INVENTED Mealie address and a placeholder // key (no Mealie exists behind it), which is what opens its import page; the shots are its import and settings pages. const puppeteer = require('puppeteer'); const fs = require('fs'); const sleep = ms => new Promise(r => setTimeout(r, ms)); const S = JSON.parse(fs.readFileSync('/out/secrets.json')); const D = process.env.DOMAIN, URL = `https://${process.env.SUB}.${D}`; const DEMO_URL = 'https://www.example.com/receptek/rakott-krumpli'; (async () => { const b = await puppeteer.launch({args: ['--no-sandbox', '--ignore-certificate-errors', '--lang=hu-HU', '--host-resolver-rules=MAP * ' + process.env.TRAEFIK]}); const p = await b.newPage(); await p.setCookie({name: 'felhom_session', value: S.session, domain: `felhom.${D}`, path: '/', secure: true}); await p.setViewport({width: 1280, height: 800}); await p.goto(URL + '/settings', {waitUntil: 'networkidle2'}); await sleep(1000); const set = async (sel, v) => { const f = await p.$(sel); if (f) { await f.click({clickCount: 3}); await f.type(v); } else console.log('no field', sel); }; await set('input[name=mealie_url]', 'https://recipes.example.hu'); await set('input[name=mealie_api_key]', 'demo-placeholder'); await Promise.all([p.waitForNavigation({waitUntil: 'networkidle2'}).catch(() => {}), p.$eval('input[name=mealie_url]', el => el.form.submit())]); await sleep(1000); console.log('after save', p.url()); await p.screenshot({path: '/out/settings.png'}); await p.goto(URL + '/import', {waitUntil: 'networkidle2'}); await sleep(1500); console.log('import ->', p.url()); const ta = await p.$('textarea, input[type=url], input[name=url]'); if (ta) await ta.type(DEMO_URL); else console.log('no url field'); await sleep(500); await p.screenshot({path: '/out/import.png'}); // the bulk tab: several invented addresses at once await p.click('::-p-text(Tömeges importálás)').catch(e => console.log('no bulk tab', e.message)); await sleep(800); const bulk = await p.$$('textarea'); const vis = []; for (const t of bulk) if (await t.isVisible()) vis.push(t); if (vis.length) await vis[0].type(['https://www.example.com/receptek/rakott-krumpli', 'https://www.example.com/receptek/gulyasleves', 'https://www.example.com/receptek/turos-csusza', 'https://www.example.com/receptek/meggyes-pite'].join('\n')); else console.log('no visible bulk textarea'); await sleep(500); await p.screenshot({path: '/out/bulk.png'}); await b.close(); })().catch(e => { console.error(e); process.exit(1); });