Last active
August 29, 2015 14:22
-
-
Save Eunoia/4c83a5ca2dd4e168e99a to your computer and use it in GitHub Desktop.
Get the itemprop after javascript blasts away fetched html, and og:tags
This file contains 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
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