From ce40b98969efe11477db46694c154a173aff32b4 Mon Sep 17 00:00:00 2001 From: Nicholas Jitkoff Date: Thu, 16 Jun 2022 21:41:50 -0700 Subject: [PATCH] Handle multiple ldjson instances on a page --- docs/render/bookmarklet.url.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/render/bookmarklet.url.js b/docs/render/bookmarklet.url.js index eaaa965..0a9d53b 100644 --- a/docs/render/bookmarklet.url.js +++ b/docs/render/bookmarklet.url.js @@ -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;