improve: base64 tool
This commit is contained in:
parent
ff0d05542d
commit
24f23b3573
@ -19,6 +19,8 @@ export default function Base64() {
|
||||
const [info, setInfo] = useState("");
|
||||
const [type, setType] = useState("");
|
||||
useEffect(() => {
|
||||
setType("");
|
||||
setInfo("");
|
||||
setHex(false);
|
||||
if (mode == "Encode") {
|
||||
setMessageResult(utoa(message));
|
||||
@ -29,14 +31,18 @@ export default function Base64() {
|
||||
} catch (e) {
|
||||
setMessageResult(normalizeHex(base64ToHex(message)));
|
||||
setHex(true);
|
||||
setType("info");
|
||||
setInfo("Showing HEX result.");
|
||||
}
|
||||
} else if (message.trim() !== "") {
|
||||
setMessageResult("Invalid Base64");
|
||||
setMessageResult("");
|
||||
setType("warning");
|
||||
setInfo("Invalid Base64.");
|
||||
} else {
|
||||
setMessageResult("");
|
||||
}
|
||||
}
|
||||
});
|
||||
}, [mode, message]);
|
||||
return (
|
||||
<div>
|
||||
<h1 className="text-3xl font-semibold">{t("base64.title")}</h1>
|
||||
@ -68,10 +74,9 @@ export default function Base64() {
|
||||
isHex ? "font-mono" : ""
|
||||
}`}
|
||||
>
|
||||
{messageResult.length > 0 ? messageResult : "Waiting for input..."}
|
||||
{messageResult}
|
||||
</div>
|
||||
<Notice type={type} info={info} class="mt-4" />
|
||||
<Notice type="info" info="HI." class="mt-4" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ export default function () {
|
||||
{s.prompt && <span className="text-zinc-700 dark:text-zinc-400">{s.prompt}</span>}
|
||||
<p>{s.suggestion}</p>
|
||||
{devMode && (
|
||||
<span className="absolute text-zinc-700 dark:text-zinc-400 text-sm leading-10 h-10 right-2">
|
||||
<span className="bottom-0 absolute text-zinc-700 dark:text-zinc-400 text-sm leading-10 h-10 right-2">
|
||||
{s.relevance}
|
||||
</span>
|
||||
)}
|
||||
|
@ -2,17 +2,16 @@ export default function (props: { children: React.ReactNode; selected: boolean }
|
||||
if (props.selected) {
|
||||
return (
|
||||
<div
|
||||
className={`w-full h-auto leading-6 break-all py-[0.6rem] bg-zinc-300 dark:bg-zinc-700
|
||||
className={`block w-full h-auto leading-6 break-all py-[0.6rem] bg-zinc-300 dark:bg-zinc-700
|
||||
px-5 z-10 cursor-pointer duration-100`}
|
||||
>
|
||||
{props.children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return (
|
||||
<div
|
||||
className={`w-full h-auto leading-6 break-all py-[0.6rem] bg-zinc-100 hover:bg-zinc-300
|
||||
className={`block w-full h-auto leading-6 break-all py-[0.6rem] bg-zinc-100 hover:bg-zinc-300
|
||||
dark:bg-zinc-800 hover:dark:bg-zinc-700 px-5 z-10 cursor-pointer duration-100`}
|
||||
>
|
||||
{props.children}
|
||||
|
@ -23,10 +23,10 @@ export default function Notice(props: { type: string; info: string; class?: stri
|
||||
<div
|
||||
className={`relative ${props.class} ${
|
||||
typeToColor[props.type]
|
||||
} rounded-md w-full min-h-9 h-fit empty:px-0 px-4 mx-1 z-20 cursor-pointer duration-100`}
|
||||
} rounded-md w-full min-h-12 h-fit empty:px-0 px-4 z-20 cursor-pointer duration-100 `}
|
||||
>
|
||||
<Icon className="text-2xl mt-3" icon={typeToIcon[props.type]} />
|
||||
<span className="">{props.info}</span>
|
||||
<span className="absolute text-base mt-3 ml-1">{props.info}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -48,9 +48,7 @@ export function base64NLP(str: string) {
|
||||
|
||||
let processedQuery = str;
|
||||
if (result.intention === "base64.encode") {
|
||||
const blacklist = Object.keys(keywords).concat(Object.keys(intentions)).concat([
|
||||
"convert", "turn"
|
||||
]);
|
||||
const blacklist = Object.keys(keywords).concat(Object.keys(intentions)).concat(["convert", "turn"]);
|
||||
processedQuery = slotExtract(str, blacklist);
|
||||
} else if (result.intention === "base64.decode") {
|
||||
processedQuery = removeStopwords(str, Object.keys(keywords).concat(Object.keys(intentions))).trim();
|
||||
@ -61,9 +59,7 @@ export function base64NLP(str: string) {
|
||||
} else {
|
||||
result.confidence = 0;
|
||||
}
|
||||
}
|
||||
else if (validBase64(processedQuery) && result.intention !== "base64.encode") {
|
||||
console.log("!!");
|
||||
} else if (validBase64(processedQuery) && result.intention !== "base64.encode") {
|
||||
result.intention = "base64.decode";
|
||||
result.confidence += Math.max(1 / Math.log2(1 / processedQuery.length) + 1, 0);
|
||||
result.probability += Math.max(1 / Math.log2(1 / processedQuery.length) + 1, 0);
|
||||
@ -72,12 +68,19 @@ export function base64NLP(str: string) {
|
||||
switch (result.intention) {
|
||||
case "base64.encode":
|
||||
result.suggestion = btoa(processedQuery);
|
||||
result.prompt = <span>Base64 Encode (Hit <Kbd keys={["enter"]}></Kbd> to copy):</span>;
|
||||
result.prompt = (
|
||||
<span>
|
||||
Base64 Encode (Hit <Kbd keys={["enter"]}></Kbd> to copy):
|
||||
</span>
|
||||
);
|
||||
break;
|
||||
case "base64.decode":
|
||||
if (result.confidence > 0.1)
|
||||
result.suggestion = atob(processedQuery);
|
||||
result.prompt = <span>Base64 Decode (Hit <Kbd keys={["enter"]}></Kbd> to copy):</span>;
|
||||
if (result.confidence > 0.1) result.suggestion = atob(processedQuery);
|
||||
result.prompt = (
|
||||
<span>
|
||||
Base64 Decode (Hit <Kbd keys={["enter"]}></Kbd> to copy):
|
||||
</span>
|
||||
);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user