查找当前页面中出现最多的 html 标签
1 2 3 4 5 6 7 8 9 10
| const maxBy = (list, keyBy) => list.reduce((x, y) => keyBy(x) > keyBy(y) ? x : y)
function getFrequentTag () { const tags = [...document.querySelectorAll('*')].map(x => x.tagName).reduce((o, tag) => { o[tag] = o[tag] ? o[tag] + 1 : 1; return o }, {}) return maxBy(Object.entries(tags), tag => tag[1]) }
|
转载文章:
(原文连接)[https://juejin.cn/post/6922229465468633095]