summaryrefslogtreecommitdiffstats
path: root/public/trail.js
blob: d11c44dddc20dd2d746dc6a313a5548f34f7a5d2 (plain) (blame)
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
let mouseText = `char *
auth_mkvalue(char *value)
{
	char *big, *p;

	big = malloc(strlen(value) * 4 + 1);
	if (big == NULL)
		return (NULL);

	for (p = big; *value; ++value) {
		switch (*value) {
		case '\r':
			*p++ = '\\';
`;

const textUrl = "https://raw.githubusercontent.com/openbsd/src/refs/heads/master/lib/libc/gen/authenticate.c";

fetch(textUrl).then(body => {
  body.text().then(text => {
    mouseText = text.substring(text.indexOf("#include")).replaceAll(/\s+/g, " ");
  });
});

const grid = document.getElementById("chars");
const minDistance = 4;
const disappearTime = 2000;
let curChar = 0;
let lastX = 0;
let lastY = 0;

window.addEventListener("mousemove", (event) => {
  const x = event.pageX;
  const y = event.pageY;
  const diffX = Math.abs(lastX-x);
  const diffY = Math.abs(lastY-y);
  const distance = Math.sqrt(diffX*2+diffY*2);
  const reversed = x < lastX;
  if (distance < minDistance) {
    return;
  }
  lastY = y;
  lastX = x;
  placeText(x+"px",y+"px", reversed);
});

function placeText(x, y, reversed) {
  const char = mouseText[curChar++ % mouseText.length];
  const el = document.createElement("div");
  el.className = "chr";
  el.style.left = x;
  el.style.top = y;
  el.innerText = char;
  if (reversed) {
    el.style.transform = "scaleX(-1)";
  }
  window.setTimeout(() => {
    el.remove();
  }, 2000);
  grid.appendChild(el);
}