通过使用此模块,只需将鼠标悬停在浏览器中,即可快速查看DOM米素的属性。基本上它是一个即时检查器。
将鼠标悬停在 DOM 米素上会显示其属性!
复制下面的整个代码块,并将其粘贴到浏览器 Web 控制台中。现在将鼠标悬停在你正在浏览的任何网页上。 看到了什么?
(function SpyOn() { const _id = 'spyon-container', _posBuffer = 3; function init() { document.body.addEventListener('mousemove', glide); document.body.addEventListener('mouseover', show); document.body.addEventListener('mouseleave', hide); } function hide(e) { document.getElementById(_id).style.display = 'none'; } function show(e) { const spyContainer = document.getElementById(_id); if (!spyContainer) { create(); return; } if (spyContainer.style.display !== 'block') { spyContainer.style.display = 'block'; } } function glide(e) { const spyContainer = document.getElementById(_id); if (!spyContainer) { create(); return; } const left = e.clientX + getScrollPos().left + _posBuffer; const top = e.clientY + getScrollPos().top + _posBuffer; spyContainer.innerHTML = showAttributes(e.target); if (left + spyContainer.offsetWidth > window.innerWidth) { spyContainer.style.left = left - spyContainer.offsetWidth + 'px'; } else { spyContainer.style.left = left + 'px'; } spyContainer.style.top = top + 'px'; } function getScrollPos() { const ieEdge = document.all ? false : true; if (!ieEdge) { return { left : document.body.scrollLeft, top : document.body.scrollTop }; } else { return { left : document.documentElement.scrollLeft, top : document.documentElement.scrollTop }; } } function showAttributes(el) { const nodeName = `<span>${el.nodeName.toLowerCase()}</span><br/>`; const attrArr = Array.from(el.attributes); const attributes = attrArr.reduce((attrs, attr) => { attrs += `<span>${attr.nodeName}</span>="${attr.nodeValue}"<br/>`; return attrs; }, ''); return nodeName + attributes; } function create() { const div = document.createElement('div'); div.id = _id; div.setAttribute('style', ` position: absolute; left: 0; top: 0; width: auto; height: auto; padding: 10px; box-sizing: border-box; color: #fff; background-color: #444; z-index: 100000; font-size: 12px; border-radius: 5px; line-height: 20px; max-width: 45%; ` ); document.body.appendChild(div); } init(); })();
此模块以IIFE的形式实现。这样只要需要一些 DOM 监视辅助,就可以将代码复制并粘贴到 Web 控制台中。将 div 插入到文档的正文中,并在正文上启用鼠标事宜侦听器。从目的米素中检索属性,将其简化为单个字符串,最后在工具提醒中显示。
你可以在这里找到源代码,希望你能做得更好!也许你不希望将其作为 IIFE 来实现,或者是去显示其他数据。
原文:https://dev.to/eddieaich/spy-on-the-dom-3d471.阿里云: 本站现在使用的是阿里云主机,平安/可靠/稳固。点击领取2000米代金券、领会最新阿里云产物的种种优惠流动点击进入
auto 你可以理解为一种 自动/自顺应 的观点,好比现在项目需要一个宽度为960px的整体结构居中,你可使用margin:0 auto;来实现。 无论用户浏览器宽度为若干。 css中的auto是自动...
远程控制别人的手机是可以的,下一个远程监控软件就可以了,但是把别人的手机摄像头变成自己的好像不太可能,你可以下载天眼远控软件试试 自己手机摄像头有没有被黑客侵入是无法判断的;原因是因为黑客研究智取计...
云顶之弈在10.14到10.15版本更新时,不仅出来了爆金币星系,现在同时也出来了压缩饼干星系。基本功能就是整个云顶之弈棋盘禁用第一排和最后一排的站位格子。顾名思义,也就是说棋盘被缩小了,棋子活动的空...
关于日常护眼,我们除了要做好必要的护眼措施,也需注意眼部营养的补充。说及补充眼部营养,不可不知越橘、叶黄素,那么,越橘与叶黄素,能够起到什么护眼作用呢? 越橘 越橘,是杜鹃花科植物,其果实外形跟蓝莓相...
英国黑客朱奈德·侯赛因和美国中央司令部官方推特遭受的网络袭击有关。英国前首相托尼·布莱尔也曾是侯赛因黑客行为的受害者。另一方面,美国军方亡羊补牢,已经加强了网络密码的安保措施。 英国黑客牵头?...
全国高端商务资源,三个办法预约国内空姐【吕雪】 今天给大家分享的内容是“全国高端商务资源,三个办法预约国内空姐【吕雪】”,我是吕雪,来自汕尾市,今年28岁,作为职业:普通服务行业,我热爱我的职业:...