Fix bug and adds text mask
This commit is contained in:
parent
51a0f26d97
commit
90dbd18b26
35
index.js
35
index.js
|
@ -207,10 +207,11 @@ async function main() {
|
|||
await fs.mkdir(outputDir);
|
||||
}
|
||||
|
||||
let lock = await fs.open(outputDir + "/.locator", 'a');
|
||||
await lock.close();
|
||||
|
||||
}
|
||||
|
||||
let lock = await fs.open(outputDir + "/.locator", 'a');
|
||||
await lock.close();
|
||||
}
|
||||
|
||||
// Path to the HTML file to analyse (given as relative path from current directory)
|
||||
|
@ -291,6 +292,36 @@ async function main() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (outputDir !== null) {
|
||||
// Produce a screenshot without text
|
||||
|
||||
// Adds a style that makes text invisible
|
||||
await page.evaluate(() => {
|
||||
let style = document.createElement('style');
|
||||
style.innerHTML = "* { color: rgba(0, 0, 0, 0) !important;";
|
||||
style.id = "no-text-style";
|
||||
document.head.appendChild(style);
|
||||
});
|
||||
|
||||
// Perform the screenshot / mask computation
|
||||
await page.screenshot({path: outputDir + '/' + 'no-text-' + pageIndex + '.png'});
|
||||
await image.segmentationMask(
|
||||
outputDir + '/screenshot2.png',
|
||||
outputDir + '/no-text-' + pageIndex + '.png',
|
||||
outputDir + '/no-text-mask-' + pageIndex + '.png',
|
||||
threshold,
|
||||
);
|
||||
|
||||
// Restore original element
|
||||
await page.evaluate(() => {
|
||||
let style = document.getElementById('no-text-style');
|
||||
document.head.removeChild(style);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Analyse the root and output the result
|
||||
info("performing analysis");
|
||||
let analyse = await analyseElement(root, page, outputDir, threshold);
|
||||
|
|
Loading…
Reference in New Issue