Skip to content

Instantly share code, notes, and snippets.

@Eunoia
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Eunoia/4c83a5ca2dd4e168e99a to your computer and use it in GitHub Desktop.
Save Eunoia/4c83a5ca2dd4e168e99a to your computer and use it in GitHub Desktop.
Get the itemprop after javascript blasts away fetched html, and og:tags
jQuery.get(document.location.href, function(html) {
itemprops = Array.prototype.slice.call(jQuery(html).find("[itemprop]"))
properties = itemprops.reduce(function(memo, curr) {
if (curr.tagName == "META") {
memo[curr.attributes.getNamedItem('itemprop').value] = curr.attributes.getNamedItem('content').value
} else {
memo[curr.attributes.getNamedItem('itemprop').value] = curr.innerText.trim();
}
return memo;
}, {})
og_tags = Array.prototype.slice.call(document.querySelectorAll("[property^=og]"))
properties = og_tags.reduce(function(memo, curr){
memo[curr.attributes.getNamedItem('property').value] = curr.attributes.getNamedItem('content').value
return memo
}, properties)
var wanelo = document.querySelector(".wanelo-save-button").attributes;
properties['wanelo-price'] = wanelo.getNamedItem("data-price").value;
properties['wanelo-title'] = wanelo.getNamedItem("data-title").value;
properties['wanelo-image'] = wanelo.getNamedItem("data-image").value;
console.log(properties);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment