More work

This commit is contained in:
Thomas Forgione 2023-02-17 17:55:41 +01:00
parent accb2d4f3a
commit e5cca75737
1 changed files with 30 additions and 7 deletions

View File

@ -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);
}
}