Val Town Code SearchReturn to Val Town

API Access

You can access search results via JSON API by adding format=json to your query:

https://codesearch.val.run/$1?q=function&page=49&format=json

For typeahead suggestions, use the /typeahead endpoint:

https://codesearch.val.run/typeahead?q=function

Returns an array of strings in format "username" or "username/projectName"

Found 29309 results for "function"(3285ms)

base2getNewsBatches.js1 match

@tehaUpdated 1 day ago
3import { sqlite } from "https://esm.town/v/YOUR_USERNAME/database"; // ⚠️ CHANGE YOUR_USERNAME
4
5export default async function(req: Request) {
6 const results = await sqlite.execute(`
7 SELECT batch_id, MIN(fetched_at) as fetch_time, COUNT(*) as article_count

base2getNewsByBatch.js1 match

@tehaUpdated 1 day ago
4import { sqlite } from "https://esm.town/v/YOUR_USERNAME/database"; // ⚠️ CHANGE YOUR_USERNAME
5
6export default async function(req: Request) {
7 const url = new URL(req.url);
8 const batchId = url.pathname.split("/").pop(); // Get batchId from path

base2getLatestNews.js1 match

@tehaUpdated 1 day ago
3import { sqlite } from "https://esm.town/v/YOUR_USERNAME/database"; // ⚠️ CHANGE YOUR_USERNAME
4
5export default async function(req: Request) {
6 const latestBatch = await sqlite.execute(`SELECT batch_id FROM news ORDER BY fetched_at DESC LIMIT 1`);
7 if (latestBatch.rows.length === 0) {

base2fetchAndStoreNews.js5 matches

@tehaUpdated 1 day ago
1// Val Name: fetchAndStoreNews.js
2// Type: Scheduled Function (e.g., every 3 hours)
3
4import { blob } from "https://esm.town/v/std/blob";
9const GNEWS_API_KEY = "973de7360b49225b484c14a98fcc0a7f"; // It's better to store this as an environment variable in Val Town
10
11// Function to generate TTS and save it to blob storage
12async function generateTtsAudio(text, newsId) {
13 // Check if audio already exists
14 const existing = await sqlite.execute({
46}
47
48// Main function to be scheduled
49export default async function fetchAndStoreNews() {
50 console.log("Fetching fresh news...");
51 const response = await fetch(

base2database.js2 matches

@tehaUpdated 1 day ago
2import { sqlite } from "https://esm.town/v/std/sqlite";
3
4// This function runs only once to set up the tables if they don't exist.
5async function initialize() {
6 await sqlite.execute(`
7 CREATE TABLE IF NOT EXISTS news (

base2index.html37 matches

@tehaUpdated 1 day ago
211 const API_NEWS_BY_BATCH = '/api/news/batch/';
212
213 async function init() {
214 await lucide.createIcons();
215
251 }
252
253 function setupEventListeners() {
254 prevBtn.addEventListener('click', goToPrevious);
255 nextBtn.addEventListener('click', goToNext);
282 }
283
284 function handleAudioEnded() {
285 audioEnded = true;
286 console.log("Audio ended");
297
298
299 function speakNewsItem() {
300 audioEnded = false;
301 ttsAbortController.abort();
424
425
426 function stopSpeaking() {
427 ttsAbortController.abort();
428 ttsAudio.pause();
437
438
439 function userActive() {
440 carouselContainer.classList.remove('user-inactive');
441 carouselContainer.classList.add('user-active');
450 }
451
452 function startUserActivityMonitor() {
453 userActive();
454 }
455
456 function updateHeadline() {
457 if (newsItems.length === 0) {
458 headline.textContent = 'No news available.';
463 }
464
465 function updateFullContent() {
466 if (newsItems.length === 0) return;
467
489 }
490
491 async function goToNext() {
492 if (isTransitioning) return;
493 isTransitioning = true;
497 }
498
499 async function goToPrevious() {
500 if (isTransitioning) return;
501 isTransitioning = true;
505 }
506
507 function updateCarousel() {
508 updateHeadline();
509 updateFullContent();
515
516
517 async function restartVideo() {
518 stopSpeaking();
519 audioEnded = false;
535 }
536
537 function togglePlayPause() {
538 isPlaying = !isPlaying;
539
559
560
561 function updatePlayPauseIcon() {
562 const btn = document.getElementById('play-pause-btn');
563 btn.innerHTML = `<i data-lucide="${isPlaying ? 'pause' : 'play'}"></i>`;
565 }
566
567 function startAutoAdvance() {
568 stopAutoAdvance();
569 if (isPlaying) {
576 }
577
578 function stopAutoAdvance() {
579 if (autoAdvanceInterval) {
580 clearInterval(autoAdvanceInterval);
583 }
584
585 function toggleMute() {
586 if (video.volume > 0) {
587 lastVolume = video.volume;
597 userActive();
598 }
599 function updateVolume() {
600 const volume = parseFloat(volumeSlider.value);
601 video.volume = volume;
610 }
611 }
612 function updateVolumeIcon(volume) {
613 const btn = document.getElementById('mute-btn');
614 let iconName = 'volume-x';
620 }
621
622 function updateProgressBar() {
623 if (video.duration) {
624 const progress = (video.currentTime / video.duration) * 100;
628 }
629
630 function seekVideo(e) {
631 const rect = progressContainer.getBoundingClientRect();
632 const percent = (e.clientX - rect.left) / rect.width;
637 }
638
639 function updateTimeDisplay() {
640 if (video.duration) {
641 const currentTime = formatTime(video.currentTime);
645 }
646
647 function updateVideoDurationDisplay() {
648 if (video.duration) {
649 timeDisplay.textContent = `0:00 / ${formatTime(video.duration)}`;
653 }
654
655 function formatTime(seconds) {
656 if (!seconds || isNaN(seconds)) return '0:00';
657
661 }
662
663 function handleVideoEnded() {
664 // Let the audio ended event handle navigation
665 }
666
667 function showContentPanel() {
668 contentVisible = true;
669 newsContent.classList.add('active');
676 }
677
678 function hideContentPanel() {
679 contentVisible = false;
680 newsContent.classList.remove('active');
682 }
683
684 async function openHistoryPanel() {
685 loadingOverlay.style.display = 'flex';
686 loadingOverlay.querySelector('.loading-text').textContent = 'Loading news history...';
707 }
708
709 function populateHistoryPanel() {
710 historyList.innerHTML = '';
711
741 }
742
743 async function loadNewsBatch(batchId) {
744 loadingOverlay.style.display = 'flex';
745 loadingOverlay.querySelector('.loading-text').textContent = 'Loading news batch...';
777 }
778
779 function closeHistoryPanel() {
780 historyPanel.classList.remove('active');
781 userActive();
782 }
783
784 function toggleFullscreen() {
785 if (!document.fullscreenElement) {
786 document.querySelector('.carousel-container').requestFullscreen().catch(err => {
793 }
794
795 function updateFullscreenIcon() {
796 const icon = document.fullscreenElement ? 'minimize' : 'maximize';
797 fullscreenBtn.innerHTML = `<i data-lucide="${icon}"></i>`;
799 }
800
801 function handleMediaError(e) {
802 console.error('Media error:', e);
803 const mediaElement = e.target;
813 }
814
815 function showError(message) {
816 errorMessage.textContent = message;
817 errorMessage.classList.add('active');
822 }
823
824 function handleKeyboardShortcuts(e) {
825 if (e.code === 'Space') {
826 e.preventDefault();

base2main.tsx1 match

@tehaUpdated 1 day ago
1export default async function (req: Request): Promise<Response> {
2 return Response.json({ ok: true })
3}

anmkimain.tsx4 matches

@temptempUpdated 1 day ago
32 break;
33 case 2:
34 function c(e) {
35 var a;
36 for (var r = 2; r !== 11;) {
41 case 6:
42 a = Y7j7u.M2F(
43 Y7j7u.N_m(B, function() {
44 for (var e = 2; e !== 1;) {
45 switch (e) {
95 var $ = Y7j7u.s$f($, "{");
96 var k = 0;
97 function J(e) {
98 for (var a = 2; a !== 23;) {
99 switch (a) {
188 }
189 }
190 function n(e) {
191 for (var a = 2; a !== 1;) {
192 switch (a) {
Gardenon

Gardenonindex.ts1 match

@LladUpdated 1 day ago
20
21// Initialize database
22async function initDatabase() {
23 // Create gardens table
24 await sqlite.execute(`CREATE TABLE IF NOT EXISTS ${GARDENS_TABLE_NAME} (
Gardenon

Gardenonindex.html24 matches

@LladUpdated 1 day ago
488
489 // Load all gardens
490 async function loadGardens() {
491 try {
492 const response = await fetch('/api/gardens');
520
521 // Load current garden and its plants
522 async function loadCurrentGarden() {
523 if (!currentGarden) return;
524
532
533 // Fetch plants for current garden
534 async function fetchPlants() {
535 if (!currentGarden) {
536 plants = [];
551
552 // Render plants on the map and in the list
553 function renderPlants() {
554 // Clear existing plants (but preserve placeholder)
555 gardenMap.querySelectorAll('.plant:not(.placeholder)').forEach(el => el.remove());
628
629 // Create a new garden
630 async function createGarden() {
631 const name = newGardenNameInput.value.trim();
632 const width = parseInt(newGardenWidthInput.value);
674
675 // Update current garden settings
676 async function updateGardenSettings() {
677 if (!currentGarden) return;
678
722
723 // Delete current garden
724 async function deleteGarden() {
725 if (!currentGarden) return;
726
759
760 // Create a placeholder plant on the map
761 function createPlaceholderPlant(x, y) {
762 // Remove existing placeholder if any
763 removePlaceholderPlant();
792
793 // Remove placeholder plant from the map
794 function removePlaceholderPlant() {
795 if (placeholderPlant && placeholderPlant.element) {
796 placeholderPlant.element.remove();
800
801 // Select a plant to edit
802 function selectPlant(plant) {
803 // Cancel move mode if active
804 if (isMovingPlant) {
833
834 // Clear the form
835 function clearForm() {
836 // Remove placeholder plant if it exists
837 removePlaceholderPlant();
859
860 // Start move mode
861 function startMoveMode() {
862 if (!selectedPlant) {
863 alert('Please select a plant to move.');
873
874 // Cancel move mode
875 function cancelMoveMode() {
876 isMovingPlant = false;
877 mapInstructions.textContent = 'Tap anywhere on the map to add a plant';
882
883 // Move plant to new position
884 function movePlantTo(x, y) {
885 if (!selectedPlant) return;
886
906
907 // Add a new plant at the clicked position
908 function addPlantAt(x, y) {
909 if (!currentGarden) {
910 alert('Please select a garden first.');
937
938 // Save plant data
939 async function savePlant(plantData) {
940 if (!currentGarden) {
941 alert('Please select a garden first.');
984
985 // Update placeholder plant when diameter changes
986 function updatePlaceholderPlant() {
987 if (placeholderPlant && placeholderPlant.element) {
988 const newDiameter = parseFloat(plantDiameterInput.value) || 50;
994
995 // Delete a plant
996 async function deletePlant(id) {
997 if (!confirm('Are you sure you want to delete this plant?')) {
998 return;
1020 }
1021
1022 // Modal functions
1023 function openGardenSettingsModal() {
1024 if (!currentGarden) {
1025 alert('Please select a garden first.');
1033 }
1034
1035 function closeGardenSettingsModal() {
1036 gardenSettingsModal.style.display = 'none';
1037 }
1038
1039 function openNewGardenModal() {
1040 newGardenNameInput.value = '';
1041 newGardenWidthInput.value = 700;
1044 }
1045
1046 function closeNewGardenModal() {
1047 newGardenModal.style.display = 'none';
1048 }
1176
1177 // Initialize
1178 async function initialize() {
1179 await loadGardens();
1180 }
tuna

tuna9 file matches

@jxnblkUpdated 1 day ago
Simple functional CSS library for Val Town

getFileEmail4 file matches

@shouserUpdated 1 month ago
A helper function to build a file's email
lost1991
import { OpenAI } from "https://esm.town/v/std/openai"; export default async function(req: Request): Promise<Response> { if (req.method === "OPTIONS") { return new Response(null, { headers: { "Access-Control-Allow-Origin": "*",
webup
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.