Back
Version 47
12/31/2023
// this is running from the browser, so we cannot use `npm:js-base64`
import { Base64 } from "https://cdn.jsdelivr.net/npm/js-base64@3.7.5/base64.mjs";
import { token } from "https://esm.town/v/pomdtr/browser";
const pattern = new URLPattern("https://www.val.town/v/:author/:name");
const res = pattern.exec(window.location.href);
if (!res) {
throw new Error("Not a val url");
}
const { author, name } = res.pathname.groups;
const title = `@${author}/${name}`;
const { code } = await fetch(`https://api.val.town/v1/alias/${author}/${name}`, {
headers: {
authorization: `Bearer ${token}`,
},
}).then(res => res.json());
const hash = `#language=tsx&title=${title}&code=${Base64.encodeURI(code)}`;
window.open(`https://ray.so${hash}`, "_blank");
// #bookmarklet
Updated: February 13, 2024