diff --git a/index.js b/index.js index f31721b..778b70e 100644 --- a/index.js +++ b/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);