Handle multiple ldjson instances on a page

This commit is contained in:
Nicholas Jitkoff 2022-06-16 21:41:50 -07:00
parent 05013dcba7
commit ce40b98969

View file

@ -4,7 +4,11 @@
// LD+JSON extraction
((ib) => {
ld = document.querySelector('script[type="application/ld+json"]').innerText
ld = Array.from(document.querySelectorAll('script[type="application/ld+json"]'))
.map(e => e.innerText)
.sort((a,b) => a.length - b.length)
.pop();
if (!ld) alert("No recipe data found on this page. Sorry!");
ld = JSON.parse(ld);
if (ld["@type"] != "Recipe"){ ld=(ld["@graph"]??ld).find((item)=>item["@type"]=="Recipe") }
delete ld.review;