Chrome extension to add "Run in Val.Town" to all typescript Github gists.
- Go to
chrome://extensions. Then go to releases, and downloadgistal.crx(here). Drag and drop it into the extensions page. - Click the extensions dropdown on the top right, right click the
gistalextension, clickoptions, and then on the options page set your val town API token.
Now all github gists will show "Run in Val.Town"!
Pretty straightforward: on gist.github.com/*, it matches all the "View Raw" button containers, and gets the URL of the raw code. The filename is in the url; if it's *.ts we add a "Run in Val Town" button to the group of buttons with the "View Raw" one, with a callback that uses the Val Town SDK to create a val, and then use the window object to navigate to it.
For regex nerds, fun trick: (?<=/) is a lookbehind that matches onto the first / from the back. So (?<=/)[^/]+.w*$ matches "url...stuff/test.ts" (yes we could use .split("."), but that's less fun).
I'm using Bun to bundle the typescript files. To build the extension, run bun run build. The output will be in ./dist.

