-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
342 lines (289 loc) · 9.68 KB
/
script.js
File metadata and controls
342 lines (289 loc) · 9.68 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
// State management
let currentValue = '0';
let previousValue = '';
let operation = null;
let trustLevel = 100;
let calculationCount = 0;
let isAIMode = false;
// DOM elements
const display = document.getElementById('display');
const trustFill = document.getElementById('trustFill');
const trustPercent = document.getElementById('trustPercent');
const loadingBar = document.getElementById('loadingBar');
const toast = document.getElementById('toast');
const aiModeToggle = document.getElementById('aiMode');
const buttonGrid = document.getElementById('buttonGrid');
// Sarcastic messages
const roastMessages = [
"Bro really used a calculator for this? 💀",
"Try using your brain next time 🧠",
"My grandma calculates faster than you",
"Are you even trying?",
"This is basic math, come on...",
"Error: User intelligence too low",
"Math.exe has stopped working",
"Result too intelligent for you",
"Did you skip elementary school?",
"Even a potato could do this faster",
"Calculating your IQ... Error: Number too small",
"Have you considered using your fingers?",
"This is why aliens won't visit us",
"Your math teacher is crying somewhere"
];
const fakeErrors = [
"Error: Math is temporarily unavailable",
"Error 404: Brain not found",
"System overload: Too much stupidity detected",
"Warning: Calculation may cause brain damage",
"Error: Numbers are on strike today",
"Critical: Math.dll is corrupted",
"Fatal: Intelligence buffer overflow"
];
// Initialize
function init() {
const buttons = document.querySelectorAll('.btn');
buttons.forEach(btn => {
btn.addEventListener('click', handleButtonClick);
// Random button movement on hover
btn.addEventListener('mouseenter', () => {
if (Math.random() < 0.15) { // 15% chance
btn.classList.add('moving');
setTimeout(() => btn.classList.remove('moving'), 300);
}
});
});
aiModeToggle.addEventListener('change', (e) => {
isAIMode = e.target.checked;
showToast(isAIMode ?
"AI Mode Activated: Now 200% more accurate! 🤖" :
"AI Mode Deactivated: Back to normal chaos 😈"
);
});
updateDisplay();
}
function handleButtonClick(e) {
const value = e.target.dataset.value;
// Easter egg: 69 or 420
if (currentValue === '69' || currentValue === '420') {
if (Math.random() < 0.3) {
showToast('Nice. 😏');
}
}
// Random button swap (10% chance)
if (Math.random() < 0.1) {
swapRandomButtons();
}
if (value === 'C') {
clear();
} else if (value === 'backspace') {
backspace();
} else if (value === '=') {
handleEquals();
} else if (['+', '-', '*', '/'].includes(value)) {
handleOperator(value);
} else {
handleNumber(value);
}
decreaseTrust();
}
function handleNumber(num) {
if (currentValue === '0' || currentValue === 'Error') {
currentValue = num;
} else {
currentValue += num;
}
updateDisplay();
}
function handleOperator(op) {
if (previousValue === '') {
previousValue = currentValue;
currentValue = '0';
operation = op;
} else {
handleEquals();
operation = op;
}
}
async function handleEquals() {
calculationCount++;
// 20% chance the equals button just clears everything
if (Math.random() < 0.2) {
showToast("You thought 💀");
clear();
return;
}
// 15% chance of fake error
if (Math.random() < 0.15) {
showFakeError();
return;
}
// Show fake loading
await fakeLoading();
if (operation && previousValue !== '') {
const prev = parseFloat(previousValue);
const curr = parseFloat(currentValue);
let result;
// Calculate the CORRECT result first
switch (operation) {
case '+':
result = prev + curr;
break;
case '-':
result = prev - curr;
break;
case '*':
result = prev * curr;
break;
case '/':
result = curr !== 0 ? prev / curr : 'Error';
break;
}
// Now apply chaos
if (result !== 'Error') {
result = applyChaoticLogic(prev, curr, operation, result);
}
currentValue = result.toString();
previousValue = '';
operation = null;
updateDisplay();
// Random roast after calculation
if (Math.random() < 0.25) {
setTimeout(() => showToast(getRandomRoast()), 500);
}
}
}
function applyChaoticLogic(prev, curr, op, correctResult) {
// AI Mode makes it WORSE
const chaosChance = isAIMode ? 0.6 : 0.3;
// Easter eggs for specific calculations
if (prev === 2 && curr === 2 && op === '+') {
if (Math.random() < 0.5) {
showToast("2 + 2 = 5 (for large values of 2) 🤓");
return 5;
}
}
if (prev === 9 && curr === 10 && op === '+') {
if (Math.random() < 0.4) {
showToast("9 + 10 = 21 (obviously) 📱");
return 21;
}
}
// Random wrong answer
if (Math.random() < chaosChance) {
const wrongResults = [
correctResult + Math.floor(Math.random() * 10) - 5,
correctResult * 1.1,
correctResult * 0.9,
correctResult + 1,
correctResult - 1,
Math.floor(Math.random() * 100),
42, // The answer to everything
69,
420,
Math.PI,
correctResult * -1
];
return wrongResults[Math.floor(Math.random() * wrongResults.length)];
}
// Sometimes return correct result (to keep them guessing)
return correctResult;
}
function clear() {
currentValue = '0';
previousValue = '';
operation = null;
updateDisplay();
}
function backspace() {
if (currentValue.length > 1) {
currentValue = currentValue.slice(0, -1);
} else {
currentValue = '0';
}
updateDisplay();
}
function updateDisplay() {
display.textContent = currentValue;
}
function decreaseTrust() {
trustLevel = Math.max(0, trustLevel - Math.random() * 3);
trustFill.style.width = trustLevel + '%';
trustPercent.textContent = Math.floor(trustLevel) + '%';
if (trustLevel < 50) {
trustFill.classList.add('low');
}
if (trustLevel < 20 && Math.random() < 0.1) {
showToast("Trust Level Critical: Calculator may lie at any moment ⚠️");
}
}
async function fakeLoading() {
// Random delay between 0.5 and 2.5 seconds
const delay = 500 + Math.random() * 2000;
const steps = 50;
const stepDelay = delay / steps;
for (let i = 0; i <= steps; i++) {
loadingBar.style.width = (i / steps * 100) + '%';
// 10% chance to reset at 99%
if (i === steps - 1 && Math.random() < 0.1) {
showToast("Loading failed. Retrying... 🔄");
i = 0;
}
await sleep(stepDelay);
}
loadingBar.style.width = '0%';
}
function swapRandomButtons() {
const buttons = Array.from(document.querySelectorAll('.btn:not(.equals)'));
if (buttons.length < 2) return;
const idx1 = Math.floor(Math.random() * buttons.length);
let idx2 = Math.floor(Math.random() * buttons.length);
while (idx2 === idx1) {
idx2 = Math.floor(Math.random() * buttons.length);
}
const temp = buttons[idx1].dataset.value;
buttons[idx1].dataset.value = buttons[idx2].dataset.value;
buttons[idx2].dataset.value = temp;
const tempText = buttons[idx1].textContent;
buttons[idx1].textContent = buttons[idx2].textContent;
buttons[idx2].textContent = tempText;
showToast("Buttons shuffled for your convenience 😊");
}
function showFakeError() {
const error = fakeErrors[Math.floor(Math.random() * fakeErrors.length)];
currentValue = 'Error';
updateDisplay();
display.classList.add('shake');
setTimeout(() => display.classList.remove('shake'), 500);
showToast(error);
}
function showToast(message) {
toast.textContent = message;
toast.classList.add('show');
setTimeout(() => {
toast.classList.remove('show');
}, 3000);
}
function getRandomRoast() {
return roastMessages[Math.floor(Math.random() * roastMessages.length)];
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// Initialize the calculator
init();
// Secret accurate mode (Konami code: up, up, down, down, left, right, left, right)
let konamiCode = [];
const konamiSequence = ['ArrowUp', 'ArrowUp', 'ArrowDown', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowLeft', 'ArrowRight'];
let accurateMode = false;
document.addEventListener('keydown', (e) => {
konamiCode.push(e.key);
konamiCode = konamiCode.slice(-8);
if (konamiCode.join(',') === konamiSequence.join(',')) {
accurateMode = !accurateMode;
showToast(accurateMode ?
"🎮 Accurate Mode Unlocked! (Just kidding, it barely works)" :
"Accurate Mode Disabled. Back to chaos!"
);
konamiCode = [];
}
});