aboutsummaryrefslogtreecommitdiff
path: root/docker/nginx/sites/www/src/main.ts
blob: 043cb94751222ec973c1257b77f982a90a117b07 (plain)
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
import "./style.css";

class Emotion {
  static opposite_map = new Map<Emotion, Emotion>();

  constructor(public name: string) {
  }

  get opposite(): Emotion {
    return Emotion.opposite_map.get(this)!;
  }

  get element(): HTMLDivElement {
    return document.querySelector<HTMLDivElement>(`.slogan.${this.name}`)!
  }

  get elementHeight(): number {
    return this.element.clientHeight;
  }

  updateBodyTopPadding(): void {
  }

  apply() {
    localStorage.setItem(emotionKey, this.name);
    document.body.dataset.emotion = this.name;
    document.body.style.paddingTop = `${this.elementHeight}px`;
  }
}

const happy = new Emotion("happy")
const angry = new Emotion("angry")
Emotion.opposite_map.set(happy, angry)
Emotion.opposite_map.set(angry, happy)

const emotionKey = "emotion";
const savedEmotionName = localStorage.getItem(emotionKey) ?? happy.name;
document.body.dataset.emotion = savedEmotionName;

for (const emotion of [happy, angry]) {
  if (emotion.name == savedEmotionName) {
    emotion.apply();
  }
  emotion.element.addEventListener("click", () => {
    emotion.opposite.apply();
  });
}

setTimeout(() => {
  document.body.style.transition = "padding-top 0.8s";
});