diff options
author | Yuqian Yang <crupest@crupest.life> | 2025-02-22 18:11:35 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-02-23 01:36:11 +0800 |
commit | 34704b2090c48d9ab9e7458475fd701a38706ae7 (patch) | |
tree | 2aff2885ecfbef32095daf205bf2ebb32a7f2c34 /docker/nginx/sites/www/src/main.ts | |
parent | 594691a66ceb00536e133ece321846f7ba49f881 (diff) | |
download | crupest-34704b2090c48d9ab9e7458475fd701a38706ae7.tar.gz crupest-34704b2090c48d9ab9e7458475fd701a38706ae7.tar.bz2 crupest-34704b2090c48d9ab9e7458475fd701a38706ae7.zip |
feat(services): refactor structure.
Diffstat (limited to 'docker/nginx/sites/www/src/main.ts')
-rw-r--r-- | docker/nginx/sites/www/src/main.ts | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/docker/nginx/sites/www/src/main.ts b/docker/nginx/sites/www/src/main.ts deleted file mode 100644 index 09e8661..0000000 --- a/docker/nginx/sites/www/src/main.ts +++ /dev/null @@ -1,47 +0,0 @@ -import "./style.css"; - -class Emotion { - static opposite_map = new Map<Emotion, Emotion>(); - - constructor(public readonly 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; - } - - 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; - -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"; -}); |