Public
Script
Readme

Dot Shortcut

This val adds a github-like dot shortcut to your website, redirecting to the val.town edit.

Usage

Add the following script tag to your website head.

<script type="module" src="https://esm.town/v/pomdtr/dotShortcut"></script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
document.addEventListener("keydown", async (event) => {
if (event.key != ".") {
return;
}
if (document.activeElement != document.body) {
return;
}
event.preventDefault();
const [subdomain] = window.location.hostname.split(".");
const [author, name] = subdomain.split("-");
const resp = await fetch(`https://api.val.town/v1/alias/${author}/${name}`);
if (!resp.ok) {
console.error("failed to fetch val infos");
return;
}
const val = await resp.json() as { id: string };
window.open(`https://val.town/editor?id=${val.id}`);
});
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
September 9, 2024