feat: get biggest element
This commit is contained in:
13
mx-interpreter/browserSide/scraper.js
Normal file
13
mx-interpreter/browserSide/scraper.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
|
|
||||||
|
const area = (element) => element.offsetHeight * element.offsetWidth;
|
||||||
|
|
||||||
|
function getBiggestElement(selector) {
|
||||||
|
const elements = Array.from(document.querySelectorAll(selector));
|
||||||
|
const biggest = elements.reduce(
|
||||||
|
(max, elem) => (
|
||||||
|
area(elem) > area(max) ? elem : max),
|
||||||
|
{ offsetHeight: 0, offsetWidth: 0 },
|
||||||
|
);
|
||||||
|
return biggest;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user