Created
July 1, 2017 21:32
-
-
Save softwarespot/9ee80dc82b474998ff1b4ad717f227a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// URL: https://github.com/wildpeaks/package-snapshot-dom/blob/master/src/snapshot.js | |
console.clear(); | |
function snapshotDOM(node, nodes, path) { | |
nodes = nodes || []; | |
if (!isObject(node)) { | |
return nodes; | |
} | |
var snapshot = {}; | |
snapshot.node = node.cloneNode(true); | |
snapshot.path = (path ? path + '.' : '') + node.nodeName.toLowerCase(); | |
const childNodes = Array.from(node.childNodes); | |
if (childNodes.length) { | |
childNodes.forEach(childNode => snapshotDOM(childNode, nodes, snapshot.path)); | |
} | |
nodes.push(snapshot); | |
return nodes; | |
} | |
function isObject(obj) { | |
return Object(obj) === obj; | |
} | |
console.log(snapshotDOM(document.body)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment