Public
HTTP
stevekrouse-xeval.web.val.run
October 23, 2023
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { eval_ } from "https://esm.town/v/stevekrouse/eval_";
import { fetchTweet } from "https://esm.town/v/dpetrouk/fetchTweet?v=35";
export let xeval = async (req: Request) => {
let tweet, code, result;
try {
tweet = await fetchTweet(req.url);
code = tweet.text.split("```")[1]
.trim()
.replaceAll(/</g, "<")
.replaceAll(/>/g, ">")
.replaceAll(/&/g, "&");
result = await eval_(code, [req]);
return result;
}
catch (e) {
return Response.json({ code, tweet, result }, { status: 500 });
}
};
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
October 23, 2023
It would be cool to have a bot for this, that answer with the output
FYI this won't work until this PR gets merged because Twitter/X now requires an additional magical token to be sent to the tweet fetching/syndication endpoint ⚠️
Luckily folks from Vercel reverse-engineered it as part of their
react-tweet
package: https://github.com/vercel/react-tweet/blob/a292ca7/packages/react-tweet/src/api/fetch-tweet.ts#L27-L31Great point!
I couldn't resist extending it to support Bluesky posts too, so here it is https://www.val.town/v/vladimyr/postEval 🎉
I had to change the URL format slightly to include the domain and also made it so that you can simply prepend
https://vladimyr-posteval.web.val.run/
in front of the post URL. To give you an example:To make it even easier to play with it here is a bookmarklet that will eval post you are currently viewing: postEval source code:
Since my bookmarklet code got sanitized:
This is awesome!!!
And your code is so simple
Thanks! When it comes to code my personal philosophy is unless it looks and reads like haiku - it sucks 😁 Coincidentally it fits nicely into the following narrative: https://en.wikiquote.org/wiki/Brian_Kernighan#:~:text=Everyone%20knows%20that,edition%2C%20chapter%202.