From 7f62119e0d437f985a6ed13fcc96937523909eba Mon Sep 17 00:00:00 2001 From: Brian Kardell Date: Sat, 27 Apr 2019 13:59:58 -0400 Subject: [PATCH] Create element_count.js (#158) Per https://github.com/HTTPArchive/httparchive.org/issues/141 --- custom_metrics/element_count.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 custom_metrics/element_count.js diff --git a/custom_metrics/element_count.js b/custom_metrics/element_count.js new file mode 100644 index 00000000..11eb245f --- /dev/null +++ b/custom_metrics/element_count.js @@ -0,0 +1,12 @@ +return JSON.stringify( + Array.from( + document + .querySelectorAll('*')) + .reduce((acc, el) => { + let tag = el.tagName.toLowerCase() + acc[tag] = (typeof acc[tag] !== 'undefined') ? acc[tag] : 0 + acc[tag]++ + return acc + }, {} + ) +)