|
1 | | -body { |
2 | | - margin: 0; |
3 | | - background: #0f0f0f; |
4 | | - color: #00ffcc; |
5 | | - font-family: 'Courier New', monospace; |
6 | | - display: flex; |
7 | | - flex-direction: column; |
8 | | - justify-content: center; |
9 | | - align-items: center; |
10 | | - height: 100vh; |
11 | | - padding: 2rem; |
12 | | - overflow: hidden; |
13 | | - text-align: center; |
14 | | -} |
| 1 | +const logo = document.getElementById("logo"); |
| 2 | +const intervals = new Map(); |
| 3 | +const editModal = document.getElementById("editModal"); |
| 4 | +const editInput = document.getElementById("editInput"); |
| 5 | +const submitEdit = document.getElementById("submitEdit"); |
15 | 6 |
|
16 | | -.logo { |
17 | | - display: flex; |
18 | | - flex-wrap: wrap; |
19 | | - justify-content: center; |
20 | | - align-content: center; |
21 | | - font-size: clamp(1.5rem, 8vw, 4rem); |
22 | | - letter-spacing: 0.25rem; |
23 | | - max-width: 100%; |
24 | | - line-height: 1.2; |
25 | | - padding: 0.5rem; |
26 | | - gap: 0.5rem; |
27 | | -} |
| 7 | +let userText = "WELCOME TO MY WORLD"; // fallback default |
28 | 8 |
|
29 | | -.word { |
30 | | - display: inline-flex; |
31 | | - flex-wrap: nowrap; |
32 | | - white-space: pre; |
33 | | - margin: 0 clamp(0.3rem, 2vw, 1rem); |
34 | | - max-width: 100%; |
35 | | -} |
| 9 | +renderLogo(userText); |
36 | 10 |
|
37 | | -.char { |
38 | | - position: relative; |
39 | | - padding: 0 0.1em; |
40 | | - transition: color 0.2s ease; |
41 | | - white-space: pre-wrap; |
| 11 | +function getRandomChar() { |
| 12 | + const pool = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*"; |
| 13 | + return pool[Math.floor(Math.random() * pool.length)]; |
42 | 14 | } |
43 | 15 |
|
44 | | -.controls { |
45 | | - position: absolute; |
46 | | - bottom: 2rem; |
47 | | - display: flex; |
48 | | - gap: 1rem; |
49 | | - padding: 0 2rem; |
50 | | - width: 100%; |
51 | | - justify-content: center; |
52 | | -} |
| 16 | +function startRandomizing(char) { |
| 17 | + if (char.dataset.char === " ") return; |
| 18 | + if (intervals.has(char)) return; |
53 | 19 |
|
54 | | -#editBtn, |
55 | | -#refreshBtn { |
56 | | - padding: 0.5rem 1rem; |
57 | | - font-size: 1rem; |
58 | | - font-family: 'Courier New', monospace; |
59 | | - background-color: #00ffcc; |
60 | | - color: #0f0f0f; |
61 | | - border: none; |
62 | | - border-radius: 4px; |
63 | | - cursor: pointer; |
64 | | - transition: background-color 0.3s ease; |
65 | | -} |
| 20 | + const interval = setInterval(() => { |
| 21 | + char.textContent = getRandomChar(); |
| 22 | + }, 50); |
66 | 23 |
|
67 | | -#editBtn:hover, |
68 | | -#refreshBtn:hover { |
69 | | - background-color: #00ddb3; |
| 24 | + intervals.set(char, interval); |
70 | 25 | } |
71 | 26 |
|
72 | | -.edit-modal { |
73 | | - position: absolute; |
74 | | - bottom: 6rem; |
75 | | - display: none; |
76 | | - flex-direction: column; |
77 | | - align-items: center; |
78 | | - gap: 0.5rem; |
79 | | - background: #0f0f0f; |
80 | | - padding: 1rem; |
81 | | - border: 1px solid #00ffcc; |
82 | | - border-radius: 6px; |
83 | | - z-index: 20; |
| 27 | +function stopRandomizing(char) { |
| 28 | + if (char.dataset.char === " ") return; |
| 29 | + if (intervals.has(char)) { |
| 30 | + clearInterval(intervals.get(char)); |
| 31 | + intervals.delete(char); |
| 32 | + } |
| 33 | + char.textContent = char.dataset.char; |
84 | 34 | } |
85 | 35 |
|
86 | | -.edit-modal input { |
87 | | - font-family: 'Courier New', monospace; |
88 | | - font-size: 1rem; |
89 | | - padding: 0.5rem; |
90 | | - width: 250px; |
91 | | - background: #1a1a1a; |
92 | | - color: #00ffcc; |
93 | | - border: 1px solid #00ffcc; |
94 | | - border-radius: 4px; |
95 | | -} |
| 36 | +function renderLogo(text) { |
| 37 | + logo.innerHTML = ""; |
| 38 | + const words = text.match(/(\S+|\s)/g); |
96 | 39 |
|
97 | | -.edit-modal button { |
98 | | - background-color: #00ffcc; |
99 | | - color: #0f0f0f; |
100 | | - border: none; |
101 | | - padding: 0.5rem 1rem; |
102 | | - font-family: 'Courier New', monospace; |
103 | | - border-radius: 4px; |
104 | | - cursor: pointer; |
| 40 | + words.forEach((word) => { |
| 41 | + const wordSpan = document.createElement("span"); |
| 42 | + wordSpan.classList.add("word"); |
| 43 | + |
| 44 | + if (word === " ") { |
| 45 | + const space = document.createElement("span"); |
| 46 | + space.classList.add("char"); |
| 47 | + space.textContent = " "; |
| 48 | + wordSpan.appendChild(space); |
| 49 | + } else { |
| 50 | + word.split("").forEach((char, i) => { |
| 51 | + const span = document.createElement("span"); |
| 52 | + span.classList.add("char"); |
| 53 | + span.dataset.index = i; |
| 54 | + span.dataset.char = char; |
| 55 | + span.textContent = char; |
| 56 | + wordSpan.appendChild(span); |
| 57 | + }); |
| 58 | + } |
| 59 | + |
| 60 | + logo.appendChild(wordSpan); |
| 61 | + }); |
105 | 62 | } |
106 | 63 |
|
107 | | -@media (max-width: 480px) { |
108 | | - .logo { |
109 | | - font-size: clamp(1.2rem, 10vw, 2.5rem); |
110 | | - letter-spacing: 0.1rem; |
111 | | - padding: 0 0.5rem; |
112 | | - } |
| 64 | +document.addEventListener("mousemove", (e) => { |
| 65 | + const chars = document.querySelectorAll(".char"); |
| 66 | + |
| 67 | + chars.forEach((char) => { |
| 68 | + const charX = char.getBoundingClientRect().left + char.offsetWidth / 2; |
| 69 | + if (e.clientX < charX) { |
| 70 | + startRandomizing(char); |
| 71 | + } else { |
| 72 | + stopRandomizing(char); |
| 73 | + } |
| 74 | + }); |
| 75 | +}); |
113 | 76 |
|
114 | | - .controls { |
115 | | - flex-direction: column; |
116 | | - align-items: center; |
117 | | - gap: 0.5rem; |
118 | | - bottom: 1rem; |
| 77 | +document.getElementById("editBtn").addEventListener("click", () => { |
| 78 | + editInput.value = userText; |
| 79 | + editModal.style.display = "flex"; |
| 80 | + editInput.focus(); |
| 81 | +}); |
| 82 | + |
| 83 | +submitEdit.addEventListener("click", () => { |
| 84 | + const newText = editInput.value.trim(); |
| 85 | + if (newText) { |
| 86 | + userText = newText; |
| 87 | + renderLogo(userText); |
119 | 88 | } |
120 | | -} |
| 89 | + editModal.style.display = "none"; |
| 90 | +}); |
| 91 | + |
| 92 | +document.getElementById("refreshBtn").addEventListener("click", () => { |
| 93 | + window.location.href = window.location.href; |
| 94 | +}); |
0 commit comments