More work
This commit is contained in:
parent
accb2d4f3a
commit
e5cca75737
37
index2.js
37
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue