From 3636d3e9357960f2dfd9b17da917d183db968427 Mon Sep 17 00:00:00 2001 From: tdro Date: Wed, 6 Dec 2023 16:36:24 -0500 Subject: static/js: Organize console filters Info, warning, and errors --- static/js/codecopy.ts | 7 ++----- static/js/fixedsearch.ts | 2 +- static/js/index-bundle.ts | 7 ++----- static/js/index.ts | 2 +- static/js/infinitescroll.ts | 14 +++++++++++--- static/js/pager.ts | 2 +- static/js/timeago.ts | 5 +---- static/js/update.ts | 8 ++++---- 8 files changed, 23 insertions(+), 24 deletions(-) (limited to 'static') diff --git a/static/js/codecopy.ts b/static/js/codecopy.ts index 7c47c65..9885ad8 100644 --- a/static/js/codecopy.ts +++ b/static/js/codecopy.ts @@ -7,15 +7,12 @@ setTimeout( async () => { await navigator.clipboard.writeText(text); - console.log("Info: Code block text copied succesfully."); + console.log("INFO: Code text copied successfully"); }, 3000, ); } catch (error) { - console.error( - "Error: navigator.clipboard.writeText() failed.", - error, - ); + console.error("ERROR: Code text copy failed", error); } }, ); diff --git a/static/js/fixedsearch.ts b/static/js/fixedsearch.ts index f8be575..0a7e9da 100644 --- a/static/js/fixedsearch.ts +++ b/static/js/fixedsearch.ts @@ -212,7 +212,7 @@ search(query.value, data.items, options); }).catch(function (error) { - console.log("Error failed to load fuzzy sort: " + error); + console.error("ERROR: Failed to load fuzzy search", error); }); } } diff --git a/static/js/index-bundle.ts b/static/js/index-bundle.ts index bb9bee7..61dc414 100644 --- a/static/js/index-bundle.ts +++ b/static/js/index-bundle.ts @@ -14,8 +14,5 @@ const fileSize = ((await Deno.stat(file)).size / 1024).toFixed(2) + "kB"; await Deno.writeTextFile(file, output, {}); -console.log( - `Bundle file:///${file}` + - "\n" + - `Emit file:///${file} (${fileSize})`, -); +console.log("INFO:", `Bundle file:///${file}`); +console.log("INFO:", `Emit file:///${file} (${fileSize})`); diff --git a/static/js/index.ts b/static/js/index.ts index 8495c2c..f43183c 100644 --- a/static/js/index.ts +++ b/static/js/index.ts @@ -8,4 +8,4 @@ import "./autoplay.ts"; import "./hoverfix.ts"; import "./timeago.ts"; -console.log("Surface Control: Complete"); +console.log("INFO: Surface Control Complete"); diff --git a/static/js/infinitescroll.ts b/static/js/infinitescroll.ts index 1d9fcf8..8d6a57f 100644 --- a/static/js/infinitescroll.ts +++ b/static/js/infinitescroll.ts @@ -1,4 +1,12 @@ (function () { + const cookiesDisabled = !navigator.cookieEnabled; + + if (cookiesDisabled) { + document.cookie = "disabled"; + document.cookie.indexOf("disabled"); + return console.warn("WARNING: Native pagination fallback due to cookie restrictions"); + } + type percent = number; function fetch(url, method, callback, fallback) { @@ -56,15 +64,15 @@ main.after(paginate); - console.log("Fetch:", next.href, items); + console.log("INFO: Fetch", next.href, items); }, function (event) { - console.log("WARNING: Switching to native pagination", event); + console.warn("WARNING: Switching to native pagination", event); main.insertAdjacentElement("afterend", pagination); abort = true; }); } - console.log("r:", remaining, "t:", traversed, "j:", journey, "%:", ratio, "c:", count); + console.log("INFO:", "r:", remaining, "t:", traversed, "j:", journey, "%:", ratio, "c:", count); }); }); })(); diff --git a/static/js/pager.ts b/static/js/pager.ts index 6133f21..99f88c7 100644 --- a/static/js/pager.ts +++ b/static/js/pager.ts @@ -4,7 +4,7 @@ if (cookiesDisabled) { document.cookie = "disabled"; document.cookie.indexOf("disabled"); - return console.log("Pager is disabled due to cookie restrictions."); + return console.warn("WARNING: Pager disabled due to cookie restrictions"); } let seek; diff --git a/static/js/timeago.ts b/static/js/timeago.ts index edb3e9d..57eb16e 100644 --- a/static/js/timeago.ts +++ b/static/js/timeago.ts @@ -70,10 +70,7 @@ if (-1 * seconds >= 1) { return element.textContent = tiny(relative.format(-1 * seconds, "second",), 2); } } } catch (error) { - console.error( - "Error: Unable to resolve relative time format!", - error, - ); + console.error("ERROR: Relative time resolution failed", error); } })(elements[i]); } diff --git a/static/js/update.ts b/static/js/update.ts index d7fda45..cee1c92 100644 --- a/static/js/update.ts +++ b/static/js/update.ts @@ -28,10 +28,10 @@ indicator.removeAttribute("id"); indicator.dataset.update = "refresh"; self.removeEventListener("blur", update); - console.log("R: " + remote); - console.log("L: " + local); - console.log("D: " + drift); - console.log("M: " + modified); + console.log("INFO: R: " + remote); + console.log("INFO: L: " + local); + console.log("INFO: D: " + drift); + console.log("INFO: M: " + modified); } }); } -- cgit v1.2.3