ProtoShareAuth.tsx2 matches
7}
89function base64urlToBase64(base64url: string): string {
10// Convert base64url to base64
11let base64 = base64url.replace(/-/g, '+').replace(/_/g, '/');
17}
1819export function Auth({ mode, onSuccess }: AuthProps) {
20const [email, setEmail] = useState('');
21const [name, setName] = useState('');
Websocketsmain.tsx1 match
1export default function handler(req: Request) {
2if (req.headers.get("upgrade") != "websocket") {
3return new Response(null, { status: 501 });
8});
910function buildData(response) {
11return {
12status: "connected",
23// we present that at root and embed that into Notion
24// to show everyone that the connection is healthy btw Notion and val.town
25export default async function (interval: Interval) {
26const blobKey = await blobKeyForDemoCache(import.meta.url, "healthCheck");
27try {
1export default async function(req: Request) {
2const html = `<!DOCTYPE html>
3<html lang="en">
243244<script>
245// Theme toggle functionality
246const themeToggle = document.getElementById('theme-toggle');
247const themeIcon = document.getElementById('theme-icon');
262});
263264function updateThemeIcon(theme) {
265themeIcon.textContent = theme === 'dark' ? '☀️' : '🌙';
266}
267268// Add some interactive animations
269document.addEventListener('DOMContentLoaded', function() {
270// Smooth scroll for any internal links
271document.querySelectorAll('a[href^="#"]').forEach(anchor => {
272anchor.addEventListener('click', function (e) {
273e.preventDefault();
274const target = document.querySelector(this.getAttribute('href'));
Weather_Cardmain.tsx13 matches
1// 在Val.town上创建一个新的HTTP Val
23export default async function(req: Request): Promise<Response> {
4const url = new URL(req.url);
5480481// 更新时间显示
482function updateDateTime() {
483const now = new Date();
484const options = {
491492// 显示/隐藏加载状态
493function setLoading(show, text = '正在获取数据...') {
494const loadingOverlay = document.getElementById('loadingOverlay');
495const loadingText = document.getElementById('loadingText');
501502// 显示错误信息
503function showError(message) {
504const errorMessage = document.getElementById('errorMessage');
505errorMessage.textContent = message;
512513// 获取用户位置
514async function getUserLocation() {
515try {
516setLoading(true, '正在获取位置信息...');
554555// 获取天气数据
556async function fetchWeatherData(location = currentLocation) {
557if (!location || isLoading) return;
558
593594// 更新天气显示
595function updateWeatherDisplay(data) {
596// 更新数据
597document.getElementById('temperature').textContent = \`\${data.degree}°\`;
621622// 根据天气更新背景
623function updateBackground(weatherCode) {
624const body = document.body;
625const gradients = {
635636// 初始化应用
637async function initApp() {
638updateDateTime();
639const location = await getUserLocation();
642643// 事件监听器
644document.addEventListener('DOMContentLoaded', function() {
645initApp();
646
660661// 键盘快捷键
662document.addEventListener('keydown', function(e) {
663if (e.key.toLowerCase() === 'r') fetchWeatherData();
664if (e.key.toLowerCase() === 'l') document.getElementById('locationBtn').click();
674675// 获取客户端IP地址
676function getClientIP(req) {
677const forwarded = req.headers.get("x-forwarded-for");
678const realIP = req.headers.get("x-real-ip");
687688// 获取城市的默认区县
689function getDefaultCounty(city) {
690const defaultCounties = {
691"广州市": "天河区",
HN-fetch-callmain.tsx1 match
2import { spider } from "./fetch.tsx";
34export async function main(req: Request) {
5const url = new URL(req.url);
6
Glancer-backup-as-of-5-31README.md6 matches
86```typescript
87// Client-side event recording
88window.recordClick = function (action) {
89fetch(`/api/setAction`, {
90method: "POST",
116│ └── index.tsx # Frontend JavaScript entry point
117└── shared/ # Utilities used by both frontend and backend
118└── utils/ # Shared helper functions
119```
120129### Shared (`/shared`)
130131Contains utilities and functions that work in both browser and server environments, ensuring code reusability across the application.
132133## Framework and Technology Stack
189### Shared Utilities (`/shared`)
190191Contains helper functions that work in both frontend and backend environments:
192193```typescript
220221```typescript
222export default async function (interval: Interval) {
223const pages = await notion.databases.query({
224database_id: Deno.env.get("GLANCE_DEMOS_DB_ID"),
280| Aspect | Controller | Utility |
281| ------------ | --------------------------------------------- | ------------------------------------------------- |
282| Purpose | Orchestrates business logic and workflows | Provides small, stateless helper functions |
283| Scope | High-level, involves services or side effects | Low-level, narrow focus (string, date operations) |
284| State | Works with application or user-specific data | Stateless - input in, output out |
HN-fetch-callfetch.tsx3 matches
8}
910// Function to extract posts from HTML content
11function extractPosts(html: string): Post[] {
12const dom = new JSDOM(html);
13const document = dom.window.document;
3839// cat: /newest or blank
40export function spider(cat: string) {
41return fetch(`${BaseUrl}/${cat}`).then(res => res.text()).then(str => extractPosts(str));
42}
my-first-val04_email.tsx1 match
2// Click "Run", copy and paste the email address and send an email to it.
3// This example will log the email details received.
4export default async function emailHandler(email: Email){
5console.log("Email received!", email.from, email.subject, email.text);
6for (const file of email.attachments) {
my-first-val03_cron.tsx1 match
2// Configure the timer with the 🕒 icon in the top right.
3// This example just logs the current time.
4export function scheduledHandler() {
5const timestamp = new Date().toISOString();
6console.log(`Cron val executed at: ${timestamp}`);