Add binary tools
diff --git a/package-lock.json b/package-lock.json
index b22d509..c3f95b9 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -11,6 +11,7 @@
"@remix-run/cloudflare": "^1.7.6",
"@remix-run/cloudflare-workers": "^1.7.6",
"@remix-run/react": "^1.7.6",
+ "clsx": "^1.2.1",
"cross-env": "^7.0.3",
"mapbox-gl": "^2.11.0",
"react": "^18.2.0",
@@ -4413,6 +4414,14 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
+ "node_modules/clsx": {
+ "version": "1.2.1",
+ "resolved": "https://registry.npmjs.org/clsx/-/clsx-1.2.1.tgz",
+ "integrity": "sha512-EcR6r5a8bj6pu3ycsa/E/cKVGuTgZJZdsyUYHOksG/UHIiKfjxzRxYJpyVBwYaQeOvghal9fcc4PidlgzugAQg==",
+ "engines": {
+ "node": ">=6"
+ }
+ },
"node_modules/collection-visit": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/collection-visit/-/collection-visit-1.0.0.tgz",
@@ -18542,6 +18551,11 @@
"mimic-response": "^1.0.0"
}
},
+ "clsx": {
+ "version": "1.2.1",
+ "resolved": "https://registry.npmjs.org/clsx/-/clsx-1.2.1.tgz",
+ "integrity": "sha512-EcR6r5a8bj6pu3ycsa/E/cKVGuTgZJZdsyUYHOksG/UHIiKfjxzRxYJpyVBwYaQeOvghal9fcc4PidlgzugAQg=="
+ },
"collection-visit": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/collection-visit/-/collection-visit-1.0.0.tgz",
diff --git a/package.json b/package.json
index e2dc74a..5183369 100644
--- a/package.json
+++ b/package.json
@@ -19,6 +19,7 @@
"@remix-run/cloudflare": "^1.7.6",
"@remix-run/cloudflare-workers": "^1.7.6",
"@remix-run/react": "^1.7.6",
+ "clsx": "^1.2.1",
"cross-env": "^7.0.3",
"mapbox-gl": "^2.11.0",
"react": "^18.2.0",
diff --git a/src/app/components/NavRoot.tsx b/src/app/components/NavRoot.tsx
index f20c946..a5bca7b 100644
--- a/src/app/components/NavRoot.tsx
+++ b/src/app/components/NavRoot.tsx
@@ -1,6 +1,6 @@
import React from "react";
import { Navbar, Sidebar, Container, Clickable, SidebarItem, SidebarGroup, Icon } from "shamrock-ux";
-import { useLoaderData, useLocation } from "@remix-run/react";
+import { useLoaderData, useLocation, useNavigate } from "@remix-run/react";
import tools from "../tools";
import IPDetailsPage from "./ip/IPDetailsPage";
import { Helmet } from "react-helmet-async";
@@ -8,6 +8,7 @@
export default function NavRoot({ children }: { children: React.ReactNode }) {
const loaderData = useLoaderData();
const location = useLocation();
+ const navigate = useNavigate();
if (loaderData?.dedicatedPanel) return (
<>
@@ -18,7 +19,7 @@
</div>
</Container>
<div className="mt-40">
- <div className="bg-ui-10 rounded-lg py-12">
+ <div className="bg-ui-5 rounded-lg py-12">
<Container>
<div className="flex flex-col space-y-4 md:space-y-0 md:flex-row items-center justify-between">
<Clickable href={"https://jottocraft.com"}>
@@ -27,7 +28,7 @@
<h5 className="text-2xl font-medium">jottocraft</h5>
</div>
</Clickable>
- <p className="text-type-30">(c) jottocraft 2022. All rights reserved.</p>
+ <p className="text-type-30">(c) jottocraft 2022-2023. All rights reserved.</p>
</div>
</Container>
</div>
@@ -56,6 +57,13 @@
const pathname = `/${tool.id}`;
tool.active = location.pathname === pathname;
tool.href = pathname;
+ if (pathname !== "/ua") { //UA page needs client hints
+ console.log(pathname);
+ tool.onClick = (e) => {
+ e.preventDefault();
+ navigate(pathname);
+ }
+ }
return tool;
});
@@ -65,7 +73,7 @@
{children}
</div>
<div className="mt-40">
- <div className="bg-ui-10 rounded-lg m-4 p-8">
+ <div className="bg-ui-5 rounded-lg m-4 p-8">
<div className="flex flex-col space-y-4 md:space-y-0 md:flex-row items-center justify-between">
<Clickable href={"https://jottocraft.com"}>
<div className="flex flex-row items-center space-x-4">
@@ -73,7 +81,7 @@
<h5 className="text-2xl font-medium">jottocraft</h5>
</div>
</Clickable>
- <p className="text-type-30">(c) jottocraft 2022. All rights reserved.</p>
+ <p className="text-type-30">(c) jottocraft 2022-2023. All rights reserved.</p>
</div>
</div>
</div>
diff --git a/src/app/routes/base64.tsx b/src/app/routes/base64.tsx
new file mode 100644
index 0000000..89613a5
--- /dev/null
+++ b/src/app/routes/base64.tsx
@@ -0,0 +1,63 @@
+import { LoaderFunction } from "@remix-run/cloudflare";
+import { useState } from "react";
+import { Helmet } from "react-helmet-async";
+import { Button, Icon } from "shamrock-ux";
+
+export default function Base64() {
+ const [base64, setBase64] = useState("");
+ const [plaintext, setPlaintext] = useState("");
+ const [error, setError] = useState<{ title: string; message: string; } | null>(null);
+
+ function decode() {
+ try {
+ const binary = atob(base64);
+ setPlaintext(binary);
+ setError(null);
+ } catch (e: any) {
+ setError({ title: "Invalid base64", message: e.message });
+ }
+
+ }
+
+ function encode() {
+ try {
+ const ascii = btoa(plaintext);
+ setBase64(ascii);
+ setError(null);
+ } catch (e: any) {
+ setError({ title: "Invalid plain text", message: e.message });
+ }
+ }
+
+ return (
+ <>
+ <Helmet>
+ <title>Base64</title>
+ </Helmet>
+ <div>
+ <div className="text-3xl flex flex-row items-center space-x-2 font-medium">
+ <Icon>swap_horiz</Icon>
+ <h1>Base64 Converter</h1>
+ </div>
+ <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>
+ </div>
+ <div className="pt-2">
+ <div className="font-mono">
+ <textarea value={base64} onChange={e => setBase64(e.target.value)} className="block bg-ui-0 rounded-md p-2 border-2 border-ui-10 w-full h-40 outline-none focus:outline-none focus:ring-1 focus:ring-ui-accentElement transition-all focus:border-ui-accentElement" placeholder="Enter base64 to decode" />
+ </div>
+ <div className="py-10 flex flex-row items-center justify-between">
+ <div className="flex flex-row items-center space-x-6">
+ <Button onClick={decode} icon="arrow_downward">Decode base64 to plain text</Button>
+ <Button onClick={encode} icon="arrow_upward">Encode plain text to base64</Button>
+ </div>
+ </div>
+ <div>
+ <textarea value={plaintext} onChange={e => setPlaintext(e.target.value)} className="block bg-ui-0 rounded-md p-2 border-2 border-ui-10 w-full h-40 outline-none focus:outline-none focus:ring-1 focus:ring-ui-accentElement transition-all focus:border-ui-accentElement" placeholder="Enter plain text to encode" />
+ </div>
+ </div>
+ </div>
+ </>
+ );
+}
\ No newline at end of file
diff --git a/src/app/routes/binary.tsx b/src/app/routes/binary.tsx
new file mode 100644
index 0000000..a3a6f04
--- /dev/null
+++ b/src/app/routes/binary.tsx
@@ -0,0 +1,247 @@
+import { LoaderFunction } from "@remix-run/cloudflare";
+import { useMemo, useState, useCallback, useEffect } from "react";
+import { Helmet } from "react-helmet-async";
+import { Action, Button, ButtonGroup, Clickable, Dropdown } from "shamrock-ux";
+import clsx from "clsx";
+import Widget from "../components/Widget";
+
+export type InterpreterMode = "uint" | "twos" | "char";
+
+export type Interpreters = {
+ [mode in InterpreterMode]: {
+ name: string;
+ run: (bin: string) => string;
+ }
+};
+
+export type BitProps = Action & {
+ on: boolean;
+};
+
+export function Bit({ on, ...actionProps }: BitProps) {
+ return (
+ <td>
+ <Clickable className={clsx(
+ "text-3xl font-medium leading-none",
+ on ? "text-type-accent" : "text-type-40",
+ "px-1"
+ )} {...actionProps}>
+ <span>{on ? "1" : "0"}</span>
+ </Clickable>
+ </td>
+ );
+}
+
+const INTERPRETERS: Interpreters = {
+ uint: {
+ name: "Unsigned integer",
+ run: (bin: string): string => {
+ return String(Number.parseInt(bin, 2));
+ }
+ },
+ twos: {
+ name: "Signed integer",
+ run: (bin: string): string => {
+ const uint = Number.parseInt(bin, 2);
+ if (bin[0] === "1") {
+ //The number is negative
+ return String(uint - Math.pow(2, bin.length));
+ }
+
+ return String(uint);
+ }
+ },
+ //smag: {
+ // name: "Unsigned integer",
+ // run: (bin: string): string => {
+ // return String(parseInt(bin, 2));
+ // }
+ //},
+ char: {
+ name: "ASCII character",
+ run: (bin: string): string => {
+ return String.fromCharCode(Number.parseInt(bin, 2));
+ }
+ },
+ //float: {
+ // name: "Floating point",
+ // run: (bin: string): string => {
+ // return String(Number.parseFloat(bin));
+ // }
+ //}
+};
+
+export default function Binary() {
+ const [binLength, setBinLength] = useState(2);
+ const [bin, setBin] = useState<("1" | "0")[]>(new Array(2 * 8).fill("0"));
+ const [hints, setHints] = useState(false);
+ const [interpreter, setInterpreter] = useState<InterpreterMode>("uint");
+
+ useEffect(() => {
+ (window as any).__bin = bin;
+ }, [bin]);
+
+ const interactiveBinaryDigits = useMemo(() => {
+ const binStr = bin.join("");
+
+ const bitHints = [], bits = [], hexNibbles = [];
+
+ function addSpacer(width: string) {
+ const spacer = (
+ <td className={width}></td>
+ );
+
+ bitHints.push(spacer);
+ bits.push(spacer);
+ hexNibbles.push(spacer);
+ }
+
+ const numBits = bin.length;
+ const numBytes = numBits / 8;
+
+ for (let byteNum = 0; byteNum < numBytes; byteNum++) {
+ const byteIndex = 8 * byteNum;
+
+ for (let nibbleNum = 0; nibbleNum < 2; nibbleNum++) {
+ const nibbleIndex = byteIndex + 4 * nibbleNum;
+
+ for (let bitNum = 0; bitNum < 4; bitNum++) {
+ const bitIndex = nibbleIndex + bitNum;
+
+ const bit = bin[bitIndex];
+ const bitIsOn = bit === "1";
+
+ bits.push(
+ <Bit
+ onClick={() => {
+ bin[bitIndex] = bitIsOn ? "0" : "1";
+ setBin([...bin]);
+ }}
+ on={bitIsOn}
+ />
+ );
+
+ if (bitNum === 3) {
+ bitHints.push(
+ <td className="text-right text-sm italic text-type-60 leading-none" colSpan={4}>
+ {numBits - bitIndex - 1}
+ </td>
+ );
+ }
+ }
+
+ hexNibbles.push(
+ <td className="text-center text-lg text-type-20 leading-none" colSpan={4}>
+ {(Number.parseInt(binStr.substring(nibbleIndex, nibbleIndex + 4), 2)).toString(16).toUpperCase()}
+ </td>
+ );
+
+ if (nibbleNum === 0) {
+ addSpacer("w-8");
+ }
+ }
+
+ addSpacer("w-12");
+ }
+
+ return (
+ <>
+ <tr>
+ {bitHints}
+ </tr>
+ <tr>
+ {bits}
+ </tr>
+ <tr>
+ {hexNibbles}
+ </tr>
+ </>
+ );
+ }, [bin]);
+
+ const interpretedData = useMemo((): string => {
+ const binStr = bin.join("");
+ return INTERPRETERS[interpreter].run(binStr);
+ }, [bin, interpreter]);
+
+ const changeBinLength = useCallback((newByteLen: number) => {
+ const newBitLen = newByteLen * 8;
+ const existingBitLen = bin.length;
+
+ if (newBitLen > existingBitLen) {
+ //Extend array
+ for (let i = 0; i < newBitLen - existingBitLen; i++) bin.unshift("0");
+ } else {
+ //Remove from array
+ bin.splice(0, existingBitLen - newBitLen);
+ }
+
+ setBin([...bin]);
+ setBinLength(newByteLen);
+ }, [bin]);
+
+ /*
+ <Widget name="Keyboard" icon="keyboard">
+ <ButtonGroup items={[
+ { label: "Binary", icon: "visibility", active: hints === true, onClick: () => setHints(true) },
+ { label: "Hex", icon: "visibility_off", active: hints === false, onClick: () => setHints(false) },
+ { label: "Off", icon: "visibility_off", active: hints === false, onClick: () => setHints(false) }
+ ]} />
+ </Widget>
+ <Widget name="Hints" icon="info">
+ <ButtonGroup items={[
+ { label: "Show", icon: "visibility", active: hints === true, onClick: () => setHints(true) },
+ { label: "Hide", icon: "visibility_off", active: hints === false, onClick: () => setHints(false) }
+ ]} />
+ </Widget>
+ */
+
+ return (
+ <>
+ <Helmet>
+ <title>Binary tools</title>
+ </Helmet>
+ <div>
+ <Widget name="Bits" icon="memory_alt">
+ <div className="font-mono flex flex-row items-center space-x-8">
+ <table>
+ <tbody>
+ {interactiveBinaryDigits}
+ </tbody>
+ </table>
+ </div>
+ </Widget>
+ <div className="mt-4">
+ <div className="flex flex-row items-center justify-between space-x-10">
+ <div className="font-semibold text-3xl">
+ <span>= {interpretedData}</span>
+ </div>
+ <div className="flex flex-row items-center space-x-4">
+ <Widget name="Length" icon="width">
+ <Dropdown items={[
+ { name: "1 byte", onClick: () => changeBinLength(1) },
+ { name: "2 bytes", onClick: () => changeBinLength(2) },
+ { name: "3 bytes", onClick: () => changeBinLength(3) },
+ { name: "4 bytes", onClick: () => changeBinLength(4) },
+ { name: "5 bytes", onClick: () => changeBinLength(5) },
+ { name: "6 bytes", onClick: () => changeBinLength(6) },
+ { name: "7 bytes", onClick: () => changeBinLength(7) },
+ { name: "8 bytes", onClick: () => changeBinLength(8) }
+ ]}>
+ <Button icon="arrow_drop_down" align="right" style="outline">{binLength} {binLength === 1 ? "byte" : "bytes"}</Button>
+ </Dropdown>
+ </Widget>
+ <Widget name="Interpret as" icon="document_scanner">
+ <Dropdown 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>
+ </Dropdown>
+ </Widget>
+ </div>
+ </div>
+ </div>
+ </div>
+ </>
+ );
+}
\ No newline at end of file
diff --git a/src/app/routes/dns.tsx b/src/app/routes/dns.tsx
index f604f8a..523e5b8 100644
--- a/src/app/routes/dns.tsx
+++ b/src/app/routes/dns.tsx
@@ -1,43 +1,15 @@
import { LoaderFunction } from "@remix-run/cloudflare";
-import { Clickable, Icon } from "shamrock-ux";
-import tools from "../tools";
+import { Helmet } from "react-helmet-async";
export default function DNS() {
-
return (
- <div className="w-full max-w-md mx-auto my-24 space-y-8">
- <div className="space-y-4 text-center">
- <div className="text-4xl font-semibold text-type-0 flex flex-row items-center justify-center space-x-2">
- <Icon>🧰</Icon>
- <h1>WebDiag</h1>
- </div>
- <h2 className="text-type-20">Select a tool below to get started</h2>
+ <>
+ <Helmet>
+ <title>DNS</title>
+ </Helmet>
+ <div>
+ <p>hi</p>
</div>
- <div className="space-y-4">
- {tools.map(group => (
- <div key={group.title} className="space-y-2">
- <div className="flex flex-row items-center space-x-2 mx-1 text-lg text-type-10 font-medium">
- <Icon>{group.icon}</Icon>
- <h3>{group.title}</h3>
- </div>
- <div className="space-y-1">
- {group.items.map(tool => (
- <div key={tool.id}>
- <Clickable href={`/${tool.id}`} className="w-full">
- <div className="hover:bg-ui-10 rounded-lg p-2 text-left">
- <div className="flex flex-row items-center font-medium text-type-20 space-x-1">
- <Icon>{tool.icon}</Icon>
- <h5>{tool.name}</h5>
- </div>
- <p className="text-type-30 text-sm">{tool.desc}</p>
- </div>
- </Clickable>
- </div>
- ))}
- </div>
- </div>
- ))}
- </div>
- </div>
+ </>
);
}
diff --git a/src/app/routes/settings.tsx b/src/app/routes/settings.tsx
new file mode 100644
index 0000000..0cea1dc
--- /dev/null
+++ b/src/app/routes/settings.tsx
@@ -0,0 +1,15 @@
+import { Helmet } from "react-helmet-async";
+import { ThemeSelector } from "shamrock-ux";
+
+export default function Settings() {
+ return (
+ <>
+ <Helmet>
+ <title>Settings</title>
+ </Helmet>
+ <div>
+ <ThemeSelector />
+ </div>
+ </>
+ );
+}
\ No newline at end of file
diff --git a/src/app/tools.ts b/src/app/tools.ts
index 66aeae9..f3dda7d 100644
--- a/src/app/tools.ts
+++ b/src/app/tools.ts
@@ -4,19 +4,25 @@
{ name: "IP address", desc: "Get information about your public network", icon: "travel_explore", id: "ip" },
{ name: "User agent", desc: "Get information about your device and browser", icon: "devices", id: "ua" },
{ name: "Browser HTTP request", desc: "Show all the data your browser sends to load websites", icon: "swap_vert", id: "http" },
- // { name: "Connection info", desc: "Get information about how your browser establishes connections with web servers", icon: "cable", id: "connection" },
- // { name: "Query DNS", desc: "Resolve DNS names with public resolvers", icon: "dns", id: "dns" }
+ //{ name: "Connection info", desc: "Get information about how your browser establishes connections with web servers", icon: "cable", id: "connection" },
+ //{ name: "Query DNS", desc: "Resolve DNS names with public resolvers", icon: "dns", id: "dns" }
]
},
- // {
- // type: "group", title: "JavaScript tools", icon: "📜", items: [
- // { name: "Key codes", desc: "Show pressed keys and keyboard shortcuts", icon: "keyboard", id: "keyboard" },
- // { name: "Mouse tracer", desc: "Monitor for mouse, touch, and pen presses and movement", icon: "mouse", id: "mouse" }
- // ]
- // },
- // {
- // type: "group", title: "Cookies", icon: "🍪", items: [
- // { name: "jottocraft ID", desc: "Troubleshoot your jottocraft ID session", icon: "badge", id: "ratatoskr" }
- // ]
- // }
+ {
+ type: "group", 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" }
+ ]
+ },
+ /*{
+ type: "group", title: "JavaScript tools", icon: "📜", items: [
+ { name: "Key codes", desc: "Show pressed keys and keyboard shortcuts", icon: "keyboard", id: "keyboard" },
+ { name: "Mouse tracer", desc: "Monitor for mouse, touch, and pen presses and movement", icon: "mouse", id: "mouse" }
+ ]
+ },*/
+ /*{
+ type: "group", title: "Cookies", icon: "🍪", items: [
+ { name: "jottocraft ID", desc: "Troubleshoot your jottocraft ID session", icon: "badge", id: "ratatoskr" }
+ ]
+ }*/
];
\ No newline at end of file
diff --git a/src/app/util/dns/queryDNS.ts b/src/app/util/dns/queryDNS.ts
new file mode 100644
index 0000000..9e02349
--- /dev/null
+++ b/src/app/util/dns/queryDNS.ts
@@ -0,0 +1,4 @@
+export async function queryDNS() {
+ const res = await fetch("https://dns.google/resolve?name=google.com&type=A");
+ const data = await res.json();
+}
\ No newline at end of file