Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#79 prise en compte du shadow dom #80

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
#79 prise en compte du shadow dom
  • Loading branch information
Timothee DEMARES committed Dec 20, 2024
commit c3762d345d783c0df533fca373edec4eedebb2fc
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