From a6a7b37a8bd46cfed857187153d68d85dd55631c Mon Sep 17 00:00:00 2001 From: Nicholas Jitkoff Date: Wed, 27 Apr 2022 21:01:03 -0600 Subject: [PATCH] Adjusted debug --- docs/index.js | 23 +++++++++++------------ docs/render.js | 3 +-- docs/render/recipe.js | 21 ++++++++++++--------- docs/worker.js | 3 ++- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/docs/index.js b/docs/index.js index 973c4f1..8566340 100644 --- a/docs/index.js +++ b/docs/index.js @@ -6,7 +6,7 @@ if ('serviceWorker' in navigator) { navigator.serviceWorker .register('/worker.js') - .then(function() { console.log("Service Worker Registered"); }); + .then(function() { console.debug("Service Worker Registered"); }); } function dismiss() { @@ -32,9 +32,8 @@ } window.addEventListener("message", function(e) { - console.group("HI") - console.log("Message:", e.origin, e.data) - console.groupEnd("HI") + console.debug("Message:", e.origin, e.data) + // if (e.origin == 'null' || e.origin = ) { if (e.data.title) document.title = e.data.title; if (e.data.favicon) setFavicon(e.data.favicon); @@ -44,17 +43,17 @@ }, false); // window.onhashchange = - window.onload = function() { + window.onload = function() { + var fragment = window.location.hash.substring(1); + if (window.location.search) { // Redirect search to path (coming out of server opengraph forwarding) - console.log("window.location.search.substring(1)", window.location.search.substring(1)) - return window.history.replaceState(null, null, window.location.search.substring(1) + "#" + fragment); + window.history.replaceState(null, null, window.location.search.substring(1) + "#" + fragment); } var isIE = navigator.userAgent.match(/rv:11/); var isEdge = navigator.userAgent.match(/Edge\//); var isWatch = (window.outerWidth < 200); - var fragment = window.location.hash.substring(1); if (fragment.length < 3) { return location.href = "/edit"; } @@ -83,7 +82,8 @@ if (fragment.startsWith("data:")) { let info = bitty.infoForDataURL(fragment); - + const renderer = info.params?.render || renderers[info.mediatype].script; + if (info.mediatype == "text/html") { dataPrefix = HEAD_TAGS; } else if (info.mediatype == "text/plain") { @@ -91,12 +91,11 @@ renderMode = "data"; } else if (info.type == "text") { } else if (info.type == "image") { - } else { + } else if (!renderer) { console.log("unknown type, rendering as download") renderMode = "download"; } - const renderer = info.params?.render || renderers[info.mediatype].script; if (renderer) { var script = renderer; if (script.indexOf("/") == -1) script = location.origin + '/render/' + script + '.js' @@ -144,7 +143,7 @@ if (isWatch) { contentTarget = document; } - console.log("Rendering via", renderMode) + console.log("Rendering mode: " + "\x1B[1m" + renderMode) // dataURL = dataURL.replace("application/ld+json", "text/plain"); if (renderMode == "download") { try { diff --git a/docs/render.js b/docs/render.js index 4c4b16f..16d5bf5 100644 --- a/docs/render.js +++ b/docs/render.js @@ -8,7 +8,7 @@ window.el = function (tagName, attrs, ...children) { function loadScript(src, callback) { let script = el("script", { src }); script.addEventListener('load', function(e) { - console.log("Loaded", src); + console.debug("Loaded script", src); if (callback) callback(e); }); document.head.appendChild(script); @@ -35,5 +35,4 @@ window.addEventListener("message", function(e) { window.params.origin = e.origin; console.log("Rendering with", e.data.script, e.data) loadScript(e.data.script); - console.log("document.head", document.head) }, false); diff --git a/docs/render/recipe.js b/docs/render/recipe.js index 4aacc44..c30b0a1 100644 --- a/docs/render/recipe.js +++ b/docs/render/recipe.js @@ -1,6 +1,5 @@ let script = document.currentScript; let reformat = true; -console.log("localStorage") FRACTION_MAP = { '1/4': '\u00BC', @@ -144,6 +143,8 @@ function highlightStep(e) { } const ingredientMatch = /^(?:A )?([\/0-9 \-\u00BC-\u00BE\u2153-\u215E\u2009]*) ?(.*)/ + + function ingredientEl(string, terms) { if (string == "-") return m("hr"); @@ -175,7 +176,7 @@ function render() { } console.log("Recipe", json); } catch (e) { - console.log("Data", e, {data}); + console.debug("Data", e, {data}); } @@ -194,8 +195,6 @@ function render() { var ingredientTerms = new Set( Array.from(ingredients.join("\n").matchAll(/[A-Za-z\-]+/g)).map(m => m[0].length > 2 ? m[0].toLowerCase(): "") ); - - console.log("instructions", instructions) if (typeof instructions === "string") instructions = [instructions] instructions = flattenInstructions(instructions) let intructionTerms = new Set( @@ -209,14 +208,18 @@ function render() { } }) ingredientTerms.delete(""); - console.log(ingredientTerms); + //console.log(ingredientTerms); - console.log("1 tablespoon".replace(/(tablespoon)/, (a) => { - return replacements[a]; - })) + // console.log("1 tablespoon".replace(/(tablespoon)/, (a) => { + // return replacements[a]; + // })) ingredients = ingredients.map(i => m("div.ingredient", { onclick: markIngredient }, ingredientEl(clean(i), ingredientTerms))); - console.log("instructions", instructions) + + console.group("instructions") + console.log(instructions) + console.groupEnd("instructions") + let step = 1; function renderInstructions(instruction, terms) { if (Array.isArray(instruction)) { diff --git a/docs/worker.js b/docs/worker.js index 8a69af7..81617f0 100644 --- a/docs/worker.js +++ b/docs/worker.js @@ -20,7 +20,8 @@ self.addEventListener('install', function(e) { }); self.addEventListener('fetch', function(event) { - console.info("Requested", event.request.url); + console.debug("Requested", event.request.url); + event.respondWith( caches.match(event.request).then(function(response) { return response || fetch(event.request);