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
// vanilla js client script for jxnblk.com
const API = "https://jxnblk-jxnblkio.web.val.run/";
let color = localStorage.getItem("color") || "light";
document.body.className = color;
const colors = [
"light",
"foliage",
"paper",
"amber",
"tomato",
"brown reverse",
"dark reverse",
"black reverse",
];
let button = document.getElementById("color-button");
let grid = document.getElementById("grid-button");
let dotgrid = document.getElementById("dotgrid");
const cycleColor = () => {
let index = colors.indexOf(color);
if (index < 0) index = 0;
index = (index + 1) % colors.length;
color = colors[index];
localStorage.setItem("color", color);
document.body.className = color;
};
const toggleGrid = () => {
dotgrid.classList.toggle("dotgrid");
};
button.addEventListener("click", cycleColor);
grid.addEventListener("click", toggleGrid);
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
August 14, 2024