improve handling when JS is disabled; use dark theme hint and request hints on all routes
diff --git a/src/app/components/NavRoot.tsx b/src/app/components/NavRoot.tsx
index f6719dd..5736c4a 100644
--- a/src/app/components/NavRoot.tsx
+++ b/src/app/components/NavRoot.tsx
@@ -68,7 +68,7 @@
active: location.pathname === pathname,
href: pathname,
onClick: (e) => {
- if (tool.id !== "ua") { // UA page needs client hints
+ if (tool.id !== "http") { // HTTP page should see the full HTTP request
e.preventDefault();
navigate(pathname);
}
diff --git a/src/app/components/ip/IPDetailsPage.tsx b/src/app/components/ip/IPDetailsPage.tsx
index 4c9eb6e..4d2250d 100644
--- a/src/app/components/ip/IPDetailsPage.tsx
+++ b/src/app/components/ip/IPDetailsPage.tsx
@@ -79,7 +79,7 @@
<p className="font-mono">{data.geo.city}, {data.geo.region} {data.geo.postal} {data.geo.country}</p>
</Widget>
<Widget name="Map" icon="map">
- <div className="h-80 rounded-lg shadow relative">
+ <div className="h-80 rounded-lg shadow relative overflow-hidden">
<Map data={data} />
</div>
</Widget>
diff --git a/src/app/entry.server.tsx b/src/app/entry.server.tsx
index de9df11..3a56572 100644
--- a/src/app/entry.server.tsx
+++ b/src/app/entry.server.tsx
@@ -4,6 +4,7 @@
import { HelmetProvider } from "react-helmet-async";
import type { HelmetServerState } from "react-helmet-async";
import { ServerStyleSheet } from "styled-components";
+import secCHHeaders from "./util/ua/secCHHeaders";
export default function handleRequest(
request: Request,
@@ -28,6 +29,12 @@
html = html.replace("__JOTTOCRAFT_BURYA_SSR_HEAD", SSRHead);
responseHeaders.set("Content-Type", "text/html");
+
+ const CHstr = secCHHeaders.join(", ");
+ responseHeaders.set("Accept-CH", CHstr);
+ responseHeaders.set("Vary", CHstr);
+ responseHeaders.set("Critical-CH", CHstr);
+
return new Response("<!DOCTYPE html>" + html, {
status: responseStatusCode,
headers: responseHeaders
diff --git a/src/app/root.tsx b/src/app/root.tsx
index 4aafd90..cec7a76 100644
--- a/src/app/root.tsx
+++ b/src/app/root.tsx
@@ -1,4 +1,4 @@
-import type { LinksFunction, LoaderFunction, MetaFunction } from "@remix-run/cloudflare";
+import type { HeadersFunction, LinksFunction, LoaderFunction, MetaFunction } from "@remix-run/cloudflare";
import {
Links,
LiveReload,
@@ -23,6 +23,7 @@
tools: ToolGroup[];
auth?: hqNetAuth;
ip?: IPData;
+ clientThemeHint?: "light" | "dark";
};
export const rootContext = createContext<RootData>({ tools: [] });
@@ -48,7 +49,8 @@
const isDedicatedIPPage = url.hostname.startsWith("ip.");
const rootData: RootData = {
- tools: getTools(request, ctx.hqAuth)
+ tools: getTools(request, ctx.hqAuth),
+ clientThemeHint: ctx.clientThemeHint
};
if (isDedicatedIPPage) rootData.ip = await getIPData(request, ctx.cf, true, ctx.hqAuth);
@@ -58,7 +60,8 @@
};
export default function App() {
- const root = useLoaderData();
+ const root = useLoaderData() as RootData;
+ const ssr = typeof document === "undefined";
return (
<>
@@ -67,7 +70,7 @@
<head>
<Meta />
<Links />
- {typeof document === "undefined"
+ {ssr
? "__JOTTOCRAFT_BURYA_SSR_HEAD"
: null}
</head>
@@ -92,7 +95,7 @@
}
}
}
- }} jottocraft>
+ }} jottocraft pref={ssr ? root.clientThemeHint : undefined}>
<rootContext.Provider value={root}>
<NavRoot>
<Outlet />
diff --git a/src/app/routes/base64.tsx b/src/app/routes/base64.tsx
index 89613a5..fb35b3b 100644
--- a/src/app/routes/base64.tsx
+++ b/src/app/routes/base64.tsx
@@ -2,6 +2,7 @@
import { useState } from "react";
import { Helmet } from "react-helmet-async";
import { Button, Icon } from "shamrock-ux";
+import StatusBox from "../components/StatusBox";
export default function Base64() {
const [base64, setBase64] = useState("");
@@ -39,6 +40,15 @@
<Icon>swap_horiz</Icon>
<h1>Base64 Converter</h1>
</div>
+ <noscript>
+ <div className="mt-10">
+ <StatusBox type="error">
+ <p>
+ This tool requires JavaScript. Please enable it to enable functionality.
+ </p>
+ </StatusBox>
+ </div>
+ </noscript>
<div style={{ minHeight: 40 }} className="mt-4 text-red-500 leading-none">
<p className="text-sm"><b>{error?.title}</b></p>
<p className="text-xs">{error?.message}</p>
diff --git a/src/app/routes/binary.tsx b/src/app/routes/binary.tsx
index a3a6f04..1dda058 100644
--- a/src/app/routes/binary.tsx
+++ b/src/app/routes/binary.tsx
@@ -4,6 +4,7 @@
import { Action, Button, ButtonGroup, Clickable, Dropdown } from "shamrock-ux";
import clsx from "clsx";
import Widget from "../components/Widget";
+import StatusBox from "../components/StatusBox";
export type InterpreterMode = "uint" | "twos" | "char";
@@ -202,6 +203,15 @@
<title>Binary tools</title>
</Helmet>
<div>
+ <noscript>
+ <div className="mb-10">
+ <StatusBox type="error">
+ <p>
+ This tool requires JavaScript. Please enable it to enable functionality.
+ </p>
+ </StatusBox>
+ </div>
+ </noscript>
<Widget name="Bits" icon="memory_alt">
<div className="font-mono flex flex-row items-center space-x-8">
<table>
@@ -218,7 +228,7 @@
</div>
<div className="flex flex-row items-center space-x-4">
<Widget name="Length" icon="width">
- <Dropdown items={[
+ <Dropdown side="right" items={[
{ name: "1 byte", onClick: () => changeBinLength(1) },
{ name: "2 bytes", onClick: () => changeBinLength(2) },
{ name: "3 bytes", onClick: () => changeBinLength(3) },
@@ -232,7 +242,7 @@
</Dropdown>
</Widget>
<Widget name="Interpret as" icon="document_scanner">
- <Dropdown items={Object.keys(INTERPRETERS).map((interpreter) => (
+ <Dropdown side="right" items={Object.keys(INTERPRETERS).map((interpreter) => (
{ name: INTERPRETERS[interpreter as InterpreterMode].name, onClick: () => setInterpreter(interpreter as InterpreterMode) }
))}>
<Button icon="arrow_drop_down" align="right" style="outline">{INTERPRETERS[interpreter].name}</Button>
diff --git a/src/app/routes/ua.tsx b/src/app/routes/ua.tsx
index 6334f85..c7a4d49 100644
--- a/src/app/routes/ua.tsx
+++ b/src/app/routes/ua.tsx
@@ -8,16 +8,6 @@
import SecCH from "../components/ua/SecCH";
import Widget from "../components/Widget";
import loadParseUA, { AvailableUAData } from "../util/ua/loadParseUA";
-import secCHHeaders from "../util/ua/secCHHeaders";
-
-export const headers: HeadersFunction = () => {
- const CHstr = secCHHeaders.join(", ");
- return {
- "Accept-CH": CHstr,
- "Vary": CHstr,
- "Critical-CH": CHstr
- };
-}
export const loader: LoaderFunction = async ({ request, context }) => {
return loadParseUA(request);
diff --git a/src/app/tools.ts b/src/app/tools.ts
index df91f8f..c6b4fa6 100644
--- a/src/app/tools.ts
+++ b/src/app/tools.ts
@@ -33,13 +33,14 @@
{ name: "Browser HTTP request", desc: "Show all the data your browser sends to load websites", icon: "swap_vert", id: "http" },
// { name: "Route and connection", desc: "Get information about your network connection", icon: "cable", id: "connection" },
// { name: "Query public DNS", desc: "Resolve DNS names with public resolvers", icon: "dns", id: "dns" },
+ // { name: "Analyze email message", desc: "Analyze an email message's route and data", icon: "email", id: "mha" },
...hqTools
]
},
{
title: "Data encodings", icon: "🧮", items: [
{ name: "Base64 converter", desc: "Encode and/or decode base64 strings", icon: "calculate", id: "base64" },
- { name: "Binary tools", desc: "Convert and visualize binary and hexadecimal digits", icon: "pin", id: "binary" }
+ { name: "Binary visualizer", desc: "Convert and visualize binary and hexadecimal digits", icon: "pin", id: "binary" }
]
},
// {
diff --git a/src/worker/index.ts b/src/worker/index.ts
index 3d9a7ab..855f37e 100644
--- a/src/worker/index.ts
+++ b/src/worker/index.ts
@@ -23,6 +23,7 @@
ctx: ExecutionContext;
cf: IncomingRequestCfProperties;
hqAuth: hqNetAuth | null;
+ clientThemeHint?: "dark" | "light";
};
export default {
@@ -57,7 +58,8 @@
env,
ctx,
cf: (request as any).cf as IncomingRequestCfProperties,
- hqAuth: await getHQAuth(request)
+ hqAuth: await getHQAuth(request),
+ clientThemeHint: (request.headers.get("Sec-CH-Prefers-Color-Scheme") as "dark" | "light" | null) ?? undefined
};
return await handleRemixRequest(request, loadContext);
} catch (error) {