Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Secret Click Button</title>
<link rel="stylesheet" href="./styles.css" />
</head>
<body>
<main class="container">
<button id="magicButton" class="btn" type="button" aria-label="Secret button">
Click me
</button>
</main>

<script src="./script.js"></script>
</body>
</html>
52 changes: 52 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
(function () {
const button = document.getElementById('magicButton');
if (!button) return;

const clickTimestamps = [];
let purpleTimeoutId = null;

function isPurpleActive() {
return purpleTimeoutId !== null;
}

function pruneOld(nowMs) {
const cutoff = nowMs - 5000; // 5 seconds window
while (clickTimestamps.length && clickTimestamps[0] < cutoff) {
clickTimestamps.shift();
}
}

function triggerPurple() {
if (purpleTimeoutId !== null) {
clearTimeout(purpleTimeoutId);
}
button.classList.add('purple');

purpleTimeoutId = setTimeout(() => {
button.classList.remove('purple');
purpleTimeoutId = null;
}, 5000); // purple for 5 seconds
}

button.addEventListener('click', () => {
const now = Date.now();

// Always turn red on any click
button.classList.add('red');

// If purple is active, keep it until its timer ends
if (isPurpleActive()) {
return;
}

// Count clicks within last 5 seconds
pruneOld(now);
clickTimestamps.push(now);

if (clickTimestamps.length >= 5) {
triggerPurple();
// Reset sequence so user needs another 5-in-5s after this
clickTimestamps.length = 0;
}
});
})();
55 changes: 55 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
* {
box-sizing: border-box;
}

html, body {
height: 100%;
}

body {
margin: 0;
font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Arial, "Apple Color Emoji", "Segoe UI Emoji";
background: #101319;
color: #e5e7eb;
display: grid;
place-items: center;
}

.container {
display: grid;
place-items: center;
gap: 1rem;
}

.btn {
appearance: none;
border: none;
border-radius: 12px;
padding: 0.9rem 1.2rem;
font-size: 1.05rem;
font-weight: 600;
background: #2d3748; /* slate */
color: white;
cursor: pointer;
box-shadow: 0 6px 24px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.06);
transition: background-color 160ms ease, transform 60ms ease, box-shadow 160ms ease;
}

.btn:hover {
transform: translateY(-1px);
box-shadow: 0 10px 30px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.08);
}

.btn:active {
transform: translateY(0);
}

/* Red state on any click */
.btn.red {
background: #dc2626; /* red-600 */
}

/* Purple easter egg overrides red while active */
.btn.purple {
background: #7c3aed; /* violet-600 */
}