Skip to content

Instantly share code, notes, and snippets.

@mvasilkov
Created May 29, 2015 12:51
Show Gist options
  • Save mvasilkov/96e6361f49a95b3a0f4e to your computer and use it in GitHub Desktop.
Save mvasilkov/96e6361f49a95b3a0f4e to your computer and use it in GitHub Desktop.
var res = []
parse(document.documentElement)
chrome.runtime.sendMessage(res)
function parse(node) {
var i, a, name = node.tagName.toLowerCase()
res.push({type: 'o', name: name})
for (i = 0; i < node.attributes.length; ++i) {
a = node.attributes[i]
res.push({type: 'a', name: a.name, value: a.value})
}
for (i = 0; i < node.childNodes.length; ++i) {
a = node.childNodes[i]
if (a.nodeType === Node.ELEMENT_NODE)
parse(a)
else if (a.nodeType === Node.TEXT_NODE)
res.push({type: 't', text: a.textContent})
}
res.push({type: 'c', name: name})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment