40
41 try {
42 const response = await fetch("/api/chat", {
43 method: "POST",
44 headers: { "Content-Type": "application/json" },
1/** @jsxImportSource https://esm.sh/hono@4.0.8/jsx **/
2
3import { modifyFetchHandler } from "https://esm.town/v/andreterron/codeOnValTown?v=50";
4import view_route from "https://esm.town/v/pomdtr/blob_admin_blob";
5import create_route from "https://esm.town/v/pomdtr/blob_admin_create";
137});
138
139export default modifyFetchHandler(
140 passwordAuth(app.fetch, { verifyPassword: (password) => password == Deno.env.get("VAL_PASSWORD") }),
141);
104
105 try {
106 const response = await fetch("/api/chat", {
107 method: "POST",
108 headers: { "Content-Type": "application/json" },
6import { JSDOM } from 'npm:jsdom';
7
8// Function to fetch HTML from a URL and remove <style> and <script> tags
9export async function fetchHtml(url, removeSelectors = "style, script, link, noscript, frame, iframe, comment") {
10 try {
11 const response = await fetch(url);
12 const html = await response.text();
13
17 return $.html();
18 } catch (error) {
19 console.error("Error fetching the URL:", error);
20 return null;
21 }
70 // url = "https://cnn.com";
71 let url = "https://softwareyoga.com/latency-numbers-everyone-should-know";
72 const cleanedHTML = await fetchHtml(url); // Fetch and clean the HTML
73
74 if (cleanedHTML) {
1import { email } from "https://esm.town/v/std/email";
2import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
3
4export async function dailyDadJoke() {
5 let { setup, punchline } = await fetchJSON("https://official-joke-api.appspot.com/random_joke");
6 return email({
7 text: punchline,
21
22 useEffect(() => {
23 fetchPet();
24 }, []);
25
26 const fetchPet = async () => {
27 const response = await fetch("/pet");
28 const data = await response.json();
29 setPet(data);
32
33 const interact = async (action) => {
34 const response = await fetch("/interact", {
35 method: "POST",
36 headers: { "Content-Type": "application/json" },
81
82 useEffect(() => {
83 fetchHighScores();
84 }, []);
85
86 const fetchHighScores = async () => {
87 const response = await fetch('/highscores');
88 const scores = await response.json();
89 setHighScores(scores);
250
251 // Submit high score
252 await fetch('/highscore', {
253 method: 'POST',
254 headers: { 'Content-Type': 'application/json' },
255 body: JSON.stringify({ score: newScore })
256 });
257 fetchHighScores();
258 }, [grid, moves, score]);
259
44})
45
46export default app.fetch
1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
2
3export async function getWeather(location: string): Promise<WeatherResponse> {
4 return fetchJSON(`https://wttr.in/${location}?format=j1`);
5}
6
107async function getSunsetTime(date: Date): Promise<Date> {
108 const formattedDate = `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}`;
109 const response = await fetch(`https://api.sunrise-sunset.org/json?lat=40.7128&lng=-74.0060&date=${formattedDate}&formatted=0`);
110
111 if (!response.ok) {