Skip to content

Commit

Permalink
cnumr#79 prise en compte du shadow dom
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothee DEMARES committed Dec 20, 2024
1 parent ca1d15b commit c3762d3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
20 changes: 19 additions & 1 deletion script/analyseFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

function countShadom() {
const countElements = (element) => {
let count = 1;
Array.from(element.children).forEach(child => {
count += countElements(child);
});

if (element.shadowRoot) {
Array.from(element.shadowRoot.children).forEach(sChild => {
count += countElements(sChild);
});
}
return count;
};

return countElements(document.body)
}

function start_analyse() {
const analyseStartingTime = Date.now();
const dom_size = getDomSizeWithoutSvg();
Expand All @@ -28,7 +46,7 @@ function start_analyse() {
}

function getDomSizeWithoutSvg(){
let dom_size = document.getElementsByTagName("*").length;
let dom_size = countShadom();
const svgElements = document.getElementsByTagName("svg");
for (let i = 0 ; i< svgElements.length ; i++) {
dom_size -= getNbChildsExcludingNestedSvg(svgElements[i])-1;
Expand Down
20 changes: 19 additions & 1 deletion script/analyseFrameWithBestPractices.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

function countShadom() {
const countElements = (element) => {
let count = 1;
Array.from(element.children).forEach(child => {
count += countElements(child);
});

if (element.shadowRoot) {
Array.from(element.shadowRoot.children).forEach(sChild => {
count += countElements(sChild);
});
}
return count;
};

return countElements(document.body)
}

function start_analyse() {
const analyseStartingTime = Date.now();
const dom_size = getDomSizeWithoutSvg();
Expand All @@ -42,7 +60,7 @@ function start_analyse() {
}

function getDomSizeWithoutSvg() {
let dom_size = document.getElementsByTagName("*").length;
let dom_size = countShadom();
const svgElements = document.getElementsByTagName("svg");
for (let i = 0; i < svgElements.length; i++) {
dom_size -= getNbChildsExcludingNestedSvg(svgElements[i]) - 1;
Expand Down

0 comments on commit c3762d3

Please sign in to comment.