From e5cca7573740d03d3ee22c95e441288a8091ec7a Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Fri, 17 Feb 2023 17:55:41 +0100 Subject: [PATCH] More work --- index2.js | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/index2.js b/index2.js index fc27b87..0c734d3 100644 --- a/index2.js +++ b/index2.js @@ -4,6 +4,9 @@ const fs = require('fs').promises; const process = require('process'); const puppeteer = require('puppeteer'); +// Size of the rendering of the web page +const size = { width: 1280, height: 720 }; + async function main() { if (process.argv[2] === undefined) { @@ -24,19 +27,30 @@ async function main() { process.exit(1); } - // Size of the rendering of the web page - const size = { width: 1280, height: 720 }; - // Initialize browser const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.setViewport(size); await page.goto("file://" + path); - let root = await page.$("#\\31"); - let hierarchy = {}; + let currentSlide = 1; + let hierarchy = []; - await analyseElement(root); + while (true) { + let root = await page.$("#\\3" + currentSlide); + + if (root === null) { + break; + } + + let currentInfo = {}; + hierarchy.push(currentInfo); + await analyseElement(root, currentInfo); + + currentSlide++; + } + + console.log(JSON.stringify(hierarchy, undefined, 4)); await browser.close(); @@ -51,13 +65,22 @@ async function analyseElement(element, hierarchy, tabs = '', stop = false) { let className = await classAttr.jsonValue(); let box = await element.boundingBox(); + hierarchy.tag = tagName; + hierarchy.class = className; + hierarchy.x = box.x / size.width; + hierarchy.width = box.width / size.width; + hierarchy.y = box.y / size.height; + hierarchy.height = box.height / size.height; + hierarchy.children = []; console.log(tabs + tagName + ' "' + className + '" ' + JSON.stringify(box)); let children = await element.$$('> *'); for (let child of children) { - await analyseElement(child, hierarchy, tabs + ' ', true); + let currentInfo = {}; + hierarchy.children.push(currentInfo); + await analyseElement(child, currentInfo, tabs + ' ', true); } }