From: Ardis Lu Date: Sat, 14 Jan 2023 04:08:10 +0000 (-0800) Subject: Allow pre-specified input in URL X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=cb1eb6a;p=utf-8-visualizer Allow pre-specified input in URL --- diff --git a/index.html b/index.html index 2d51e61..db9c823 100644 --- a/index.html +++ b/index.html @@ -20,7 +20,7 @@
- +
@@ -50,6 +50,7 @@ padding: 4px; animation: 800ms fadeIn both; transition: filter 800ms; + position: relative; } :host(:hover), @@ -57,6 +58,20 @@ filter: drop-shadow(0 0 4px hsl(222deg 50% 50%)); transition: filter 400ms; } + + :host::before { + content: "\a Unicode code point \a Code point in binary \a UTF-8"; + position: absolute; + top: 0; + left: 0; + transform: translateX(calc(-100% - 8px)); + white-space: pre; + display: none; + } + + :is(:host(:hover), :host(:focus-within))::before { + display: block; + } ::slotted(*) { animation-name: slideIn, fadeIn; diff --git a/script.js b/script.js index b9c7044..feabc15 100644 --- a/script.js +++ b/script.js @@ -88,9 +88,14 @@ function render(output) { } function handleChange(value) { + // Update URL with the input but do not spam the history + const url = new URL(`?q=${value}`, window.location.origin); + window.history.replaceState({}, '', url); + const output = calculateOutput(value); render(output); } input.addEventListener('input', e => handleChange(e.target.value)); +input.value = new URL(document.location).searchParams.get('q') ?? '🏴‍☠️'; handleChange(input.value); // Render the default value on first load