Scraping the page for microdata
Now that we've got our content script in place, we can interact with any web page that the user of the extension visits and check whether it has any microdata attributes.
At this point, any element containing microdata is highlighted to the user, so we need to add the functionality that will allow the user to view the microdata and save it if he/she wishes, which is what we'll be covering in this task.
Engage Thrusters
Directly after where we add a class name to each element that has an itemtype
attribute in content.js
, add the following code:
person.children().each(function (j) { var child = person.children().eq(j), iProp = child.attr("itemprop"); if (iProp) { if (child.attr("itemscope") !== "") { if (iProp === "email" || iProp === "telephone") { contactMethods[iProp] = child.text(); } else { data[iProp] = child.text(); } } else { var content ...