Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/** @jsxImportSource https://esm.sh/react */
import React, { useState } from "https://esm.sh/react";
import { createRoot } from "https://esm.sh/react-dom/client";
const LOFI_GIRL_URL = "https://www.youtube.com/embed/jfKfPfyJRdk?autoplay=1";
const LOFI_BOY_URL = "https://www.youtube.com/embed/4xDzrJKXOOY?autoplay=1";
function App() {
const [selectedPlaylist, setSelectedPlaylist] = useState(null);
const selectPlaylist = (url) => {
setSelectedPlaylist(url);
};
return (
<div className="container">
<h1>Lofi Playlist Selector</h1>
<div className="button-container">
<button onClick={() => selectPlaylist(LOFI_GIRL_URL)}>Lofi Girl</button>
<button onClick={() => selectPlaylist(LOFI_BOY_URL)}>Lofi Boy</button>
</div>
{selectedPlaylist && (
<div className="video-container">
<iframe
src={selectedPlaylist}
title="YouTube video player"
frameBorder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
allowFullScreen
width="560"
height="315"
></iframe>
</div>
)}
<p className="source-link">
<a href={import.meta.url.replace("esm.town", "val.town")} target="_blank" rel="noopener noreferrer">
View Source
</a>
</p>
</div>
);
}
function client() {
createRoot(document.getElementById("root")).render(<App />);
}
if (typeof document !== "undefined") {
client();
}
async function server(request: Request): Promise<Response> {
return new Response(
`
<html>
<head>
<title>Lofi Playlist Selector</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>${css}</style>
</head>
<body>
<div id="root"></div>
<script src="https://esm.town/v/std/catch"></script>
<script type="module" src="${import.meta.url}"></script>
</body>
</html>
`,
{
headers: {
"content-type": "text/html",
},
}
);
}
const css = `
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f0f0f0;
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
text-align: center;
}
h1 {
color: #333;
}
.button-container {
margin-bottom: 20px;
}
button {
background-color: #4CAF50;
macro21kgb-lofigirlsimplerunner.web.val.run
September 19, 2024