giftSuggestionAppmain.tsx6 matches
27useEffect(() => {
28if ((age.length > 0 && budget.length > 0) || buttonPressed) {
29fetchSuggestions();
30setButtonPressed(false);
31}
32}, [age, budget, buttonPressed]);
3334const fetchSuggestions = async (isMoreSuggestions: boolean = false) => {
35setLoading(true);
36setError(null);
4041try {
42const response = await fetch("/api/shopping-assistant", {
43method: "POST",
44headers: { "Content-Type": "application/json" },
60setShownSuggestions(prevShown => [...prevShown, ...data.suggestions.map(s => s.text)]);
61} catch (err) {
62console.error("Error in fetchSuggestions:", err);
63setError(`An error occurred while fetching suggestions: ${err.message}`);
64} finally {
65setLoading(false);
7374const handleMoreSuggestions = async () => {
75await fetchSuggestions(true);
76};
77
sanguineCyanMastodonREADME.md16 matches
9Fun fact generation about the text (e.g., average word length)
10Summary generation
11The tool is implemented in JavaScript using Hono as a lightweight framework and integrates web APIs for fetching external content and analyzing it in real-time.
1213Code Structure
16Hono: Used for routing and handling API requests.
17encode (from JS Base64): Utility for encoding data.
18parse (from Node HTML Parser): Parses HTML content, used in fetchUrlContent to clean and extract text.
19Core Modules
2062Usage: Included in /analyse for quick overviews.
63cleanText(text)
64Purpose: Cleans HTML and unwanted characters from the fetched content.
65Parameters:
6667text (string): Raw HTML/text. Returns: Cleaned text string.
68Usage: Essential for preprocessing content in fetchUrlContent.
69fetchUrlContent(url)
70Purpose: Fetches HTML content from a URL, removes unwanted elements, and extracts main text.
71Parameters:
7273url (string): URL to fetch and clean content from. Returns: Cleaned text string or an error message.
74Usage: This function powers the URL input functionality.
75Core Functionalities
76Text Analysis Form (HTML)
77The form on the main page allows users to submit either raw text or a URL. The client-side JavaScript processes the form submission and, if needed, triggers a URL fetch to obtain content.
7879Backend Processing (Routes)
81GET /: Serves the main HTML page.
82POST /analyse: Analyzes submitted text and returns word count, sentiment, summary, TF-IDF, and word frequency results.
83POST /fetch-url: Retrieves and cleans content from a URL, then prepares it for analysis.
84Dark Mode and Interactivity
8590Testing
9192Integration Tests: Ensure calculateTFIDF, calculateWordFrequency, and fetchUrlContent produce consistent outputs.
93Client-Side Testing: Regularly test URL fetching functionality to ensure robustness, particularly with dynamic sites.
94Error Handling
9596Maintain try/catch blocks in asynchronous functions like fetchUrlContent to capture network issues.
97Update error messages to be user-friendly and provide feedback if inputs are invalid or exceed size limits.
98Data Sanitization
99100Verify that cleanText removes sensitive information from fetched URLs to prevent accidental disclosure.
101Rate Limits and API Usage
102119The Radical Text Analyser code primarily uses the following APIs:
1201. Hono Framework API
121* Purpose: Used to set up routing and serve responses for different endpoints (GET /, POST /analyse, and POST /fetch-url).
122* Usage: The Hono framework handles HTTP requests and responses, forming the backbone of the server-side API.
1232. External Content Fetching API (via fetch)
124* Purpose: Retrieves HTML content from external URLs when users input a URL for analysis.
125* Usage: The fetchUrlContent function uses fetch to make a GET request to the user-provided URL, which allows the application to process content from web pages.
126* Error Handling: Includes logic to check response status and handle various network errors.
1273. Google Fonts API
scraper_templatemain.tsx1 match
9const variable: string = await blob.getJSON(blobKey) ?? "";
1011const response = await fetch(scrapeURL);
12const body = await response.text();
13const $ = cheerio.load(body);
71# Long-term memory
7273At some point the user might ask you to do something with "memory". Things like "remember", "save to memory", "forget", "update memory", etc. Please use corresponding actions to achieve those tasks. User might also ask you to perform some task with the context of your "memory" - in that case fetch all memories before proceeding with the task. The memories should be formed in a clear and purely informative language, void of unnecessary adjectives or decorative language forms. An exception to that rule might be a case when the language itself is the integral part of information (snippet of writing to remember for later, examples of some specific language forms, quotes, etc.).
7475Structure of a memory:
2526useEffect(() => {
27fetchComments();
28fetchRating();
29}, []);
3031const fetchComments = async () => {
32const response = await fetch(`/${type}/${item.id}/comments`);
33if (response.ok) {
34const data = await response.json();
37};
3839const fetchRating = async () => {
40const response = await fetch(`/${type}/${item.id}/rating`);
41if (response.ok) {
42const data = await response.json();
4647const addComment = async () => {
48const response = await fetch(`/${type}/${item.id}/comments`, {
49method: 'POST',
50headers: { 'Content-Type': 'application/json' },
53if (response.ok) {
54setNewComment('');
55fetchComments();
56}
57};
5859const addRating = async (newRating) => {
60const response = await fetch(`/${type}/${item.id}/rating`, {
61method: 'POST',
62headers: { 'Content-Type': 'application/json' },
108109useEffect(() => {
110fetchInitialData();
111fetchFavorites();
112}, [page]);
113114const fetchInitialData = async () => {
115const response = await fetch(`/search?type=${page}&query=`);
116if (response.ok) {
117const data = await response.json();
123};
124125const fetchFavorites = async () => {
126const response = await fetch("/favorites");
127if (response.ok) {
128const data = await response.json();
133const handleSearch = async (e) => {
134if (e.key === "Enter" || e.type === "click") {
135const response = await fetch(`/search?type=${page}&query=${encodeURIComponent(search)}`);
136if (response.ok) {
137const data = await response.json();
146const toggleFavorite = async (item, type) => {
147const method = favorites[type].some(fav => fav.id === item.id) ? 'DELETE' : 'POST';
148const response = await fetch(`/favorites/${type}`, {
149method,
150headers: { 'Content-Type': 'application/json' },
152});
153if (response.ok) {
154fetchFavorites();
155}
156};
157158const addLostPet = async (petData) => {
159const response = await fetch("/lostPets", {
160method: "POST",
161headers: { 'Content-Type': 'application/json' },
163});
164if (response.ok) {
165fetchInitialData();
166}
167};
11setLoading(true);
12try {
13const response = await fetch("/create-checkout-session", {
14method: "POST",
15headers: {
passwordGenmain.tsx1 match
222}
223224const response = await fetch("/generate", {
225method: "POST",
226headers: { "Content-Type": "application/json" },
sendNtifyNotificationmain.tsx2 matches
1import { fetch } from 'https://esm.town/v/std/fetch';
23export type NtfyPayload = {
2223const body = JSON.stringify({ ...payload, topic });
24const res = await fetch(server, {
25method: 'POST',
26headers: {
fullPageWebsiteScrapermain.tsx14 matches
55}
56}
57// Link Fetching Helper
58export class LinkFetcher {
59static discoveredUrls = new Set();
60static pageDepths = new Map();
61static processQueue = [];
6263static async fetchLinksFromWebsite(websiteUrl) {
64console.log(`\nFetching links from website: ${websiteUrl}`);
65console.log("Initial HTML structure analysis begin");
66const query = `
7980console.log(`Making LSD API request for ${websiteUrl}`);
81const response = await fetch(
82`https://lsd.so/api?query=${encodeURIComponent(query)}`,
83);
8485if (!response.ok) {
86console.log(`Failed to fetch links from ${websiteUrl}`);
87return [];
88}
148const currentBatch = pagesToProcess.splice(0, 10);
149const batchPromises = currentBatch.map(async (pageUrl) => {
150console.log(`Fetching links from: ${pageUrl}`);
151const pageQuery = `
152SELECT
162163console.log(`Making LSD API request for ${pageUrl}`);
164const response = await fetch(
165`https://lsd.so/api?query=${encodeURIComponent(pageQuery)}`,
166);
167168if (!response.ok) {
169console.log(`Failed to fetch links from ${pageUrl}`);
170return [];
171}
235}
236237console.log(`Successfully fetched ${allLinks.length} links from ${discoveredPages.size} pages`);
238return allLinks;
239}
279try {
280console.log(`Attempting HEAD request for: ${url}`);
281const response = await fetch(url, { method: "HEAD" });
282283if (!response.ok) {
284console.log(`HEAD request failed, attempting GET request for: ${url}`);
285const getResponse = await fetch(url, { method: "GET" });
286return { ok: getResponse.ok, status: getResponse.status };
287}
431};
432433// Fetch all links with progress tracking
434const links = await LinkFetcher.fetchLinksFromWebsite(websiteUrl);
435const totalPages = new Set(links.map(link =>
436new URL(link.link, websiteUrl).origin + new URL(link.link, websiteUrl).pathname
sqliteExplorerAppmain.tsx4 matches
1/** @jsxImportSource https://esm.sh/hono@latest/jsx **/
23import { modifyFetchHandler } from "https://esm.town/v/andreterron/codeOnValTown?v=50";
4import { iframeHandler } from "https://esm.town/v/nbbaier/iframeHandler";
5import { resetStyle } from "https://esm.town/v/nbbaier/resetStyle";
16import { verifyToken } from "https://esm.town/v/pomdtr/verifyToken";
17import { ResultSet, sqlite } from "https://esm.town/v/std/sqlite";
18import { reloadOnSaveFetchMiddleware } from "https://esm.town/v/stevekrouse/reloadOnSave";
19import { Hono } from "npm:hono";
20import type { FC } from "npm:hono/jsx";
175});
176177export const handler = app.fetch;
178export default iframeHandler(modifyFetchHandler(passwordAuth(handler, { verifyPassword: verifyToken })));