From 992a2ff62b21bc7843f2aa23b99756a0932b0cc5 Mon Sep 17 00:00:00 2001 From: Nicholas Jitkoff Date: Sat, 11 Feb 2023 09:32:28 -0700 Subject: [PATCH] Update parse and share --- docs/render/parse.js | 8 ++++++-- docs/render/recipe.js | 8 +++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/docs/render/parse.js b/docs/render/parse.js index 83caf43..9e995f3 100644 --- a/docs/render/parse.js +++ b/docs/render/parse.js @@ -35,6 +35,10 @@ function findMicrodataRecipe(doc) { } +let textRecipe = async document => { +console.log("text recipe", document, document.documentElement.textContent) +return {}; +} let scrapeRecipe = async document => { @@ -121,13 +125,13 @@ let scrapeRecipe = async document => { console.warn("Extracted", JSON.stringify(recipe,undefined,2)) - // return undefined + if (!recipe.recipeInstructions) return undefined return recipe; } -let recipe = findLDJsonRecipe(doc) || findMicrodataRecipe(doc) || await scrapeRecipe(doc); +let recipe = findLDJsonRecipe(doc) || findMicrodataRecipe(doc) || await scrapeRecipe(doc) || await textRecipe(doc); if (!recipe.recipeInstructions) recipe = undefined; diff --git a/docs/render/recipe.js b/docs/render/recipe.js index 5267f56..c00c544 100644 --- a/docs/render/recipe.js +++ b/docs/render/recipe.js @@ -412,8 +412,10 @@ function startTimer(e, t1, t2) { window.startTimer = startTimer; -function share() { - parent.postMessage({share:{}}, "*"); +function share(e) { + var viewportOffset = e.target.getBoundingClientRect(); + console.log(e, viewportOffset) + parent.postMessage({share:{clientX:e.clientX, clientY:e.clientY, offset:viewportOffset}}, "*"); } function faviconForTitle(title) { @@ -669,7 +671,7 @@ function render() { ), m(".actions.print-hide.watch-hide", // originalURL ? m("a.action", { title:"Open original", href: originalURL, target:"_blank"}, m(".icon.public", {innerHTML:icons.public})) : null, - navigator.share ? m("a.action", { title:"Share", onclick: share}, m(".icon.share", {innerHTML:icons.share})) : undefined, + m("a.action", { title:"Share", onclick: share}, m(".icon.share", {innerHTML:icons.share})), // m("a.action", { title:"Show steps as list", onclick: () => {reformat = !reformat; render(); return false;}}, m(".icon.checklist")), m("a.action", { title:"Print", onclick: () => {window.print(); return false;} }, m(".icon.print", {innerHTML:icons.print})), )