-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththr.html
More file actions
385 lines (328 loc) · 14.1 KB
/
thr.html
File metadata and controls
385 lines (328 loc) · 14.1 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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<!DOCTYPE html PUBLIC '-//WAPFORUM//DTD XHTML Mobile 1.0//EN' 'http://www.wapforum.org/DTD/xhtml-mobile10.dtd'>
<head>
<title>Tunjangan THR Raya</title>
<meta charset="UTF-8">
<meta name="author" content="Hardiansyah">
<meta name="viewport" content="width=device-width, initial-scale=1, minimal-scale=1, maximal-scale=1">
<link href="https://fonts.googleapis.com/css2?family=Rubik&display=swap" rel="stylesheet">
<meta name="theme-color" content="#3498DB">
<meta property="og:title" content="THR nih wkwkwk 🗿">
<meta property="og:description" content="Cek kamu dapet berapa THR nya? 😂">
<meta property="og:url" content="https://webstockid.github.io/thr">
<meta property="og:type" content="website">
<style>
:root {
--primary: #e63946; /* Merah */
--secondary: #a8dadc; /* Biru Muda */
--dark: #1d3557; /* Biru Tua */
--accent: #fca311; /* Emas */
--bg: #f1faee; /* Putih Abu */
}
body {
font-family: 'Rubik', sans-serif;
background-color: var(--dark);
color: #fff;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
overflow-x: hidden;
}
h1 { margin-bottom: 0.5rem; text-shadow: 0 2px 5px rgba(0,0,0,0.5); }
/* === 1. OVERLAY PENDAFTARAN === */
#registration-overlay {
position: fixed;
inset: 0;
background: rgba(0,0,0,0.95);
display: flex;
align-items: center;
justify-content: center;
z-index: 999;
backdrop-filter: blur(5px);
}
.input-card {
background: #fff;
color: var(--dark);
padding: 2.5rem;
border-radius: 20px;
text-align: center;
box-shadow: 0 15px 40px rgba(0,0,0,0.6);
width: 90%;
max-width: 400px;
}
.input-card h2 { margin-top: 0; color: var(--primary); }
input[type="text"] {
width: 100%;
padding: 12px 15px;
margin: 1rem 0;
border: 2px solid var(--secondary);
border-radius: 8px;
font-size: 1rem;
box-sizing: border-box;
}
input[type="text"]:focus {
outline: none;
border-color: var(--accent);
box-shadow: 0 0 5px rgba(252, 163, 17, 0.5);
}
.btn {
background: var(--primary);
color: #fff;
border: none;
padding: 12px 30px;
font-size: 1.1rem;
border-radius: 8px;
cursor: pointer;
font-weight: bold;
transition: transform 1s;
}
.btn:hover { transform: scale(1.05); }
/* === 2. AREA RODA PUTAR === */
#main-app { display: none; text-align: center; width: 100%; max-width: 500px; padding: 20px; box-sizing: border-box; }
.wheel-area {
position: relative;
width: 320px;
height: 320px;
margin: 1.5rem auto;
}
canvas {
width: 100%;
height: 100%;
border-radius: 50%;
border: 8px solid var(--accent);
box-shadow: 0 0 25px rgba(252, 163, 17, 0.6);
/* Jarum ada di atas (angle 270) secara default,
jadi kita offset kanvas agar slice pertama ada di bawah jarum */
transform: rotate(-90deg);
}
/* Penunjuk / Jarum (Wajib ada di Atas) */
.pointer {
position: absolute;
top: -20px;
left: 50%;
transform: translateX(-50%);
width: 0;
height: 0;
border-left: 18px solid transparent;
border-right: 18px solid transparent;
border-top: 35px solid var(--accent);
filter: drop-shadow(0 2px 3px rgba(0,0,0,0.5));
z-index: 10;
}
/* === 3. POPUP KARTU HASIL (AMPLOP) === */
#result-popup {
display: none; /*none*/
position: fixed; /*fixed*/
inset: 0;
background: rgba(0,0,0,0.85);
justify-content: center;
align-items: center;
z-index: 1000;
}
.envelope-card {
background: dodgerblue; /* Merah Amplop */
border: 3px solid #fafafa; /* Emas Pinggiran */
color: #fff;
padding: 3rem 2rem;
border-radius: 20px;
text-align: center;
width: 90%;
max-width: 380px;
box-shadow: 0 10px 40px rgba(0,0,0,0.8);
transform: scale(0.6);
animation: popIn 0.5s forwards ease-out;
}
@keyframes popIn {
to { transform: scale(1); }
}
.envelope-card h2 { color: #fee440; margin-top: 0; }
.envelope-card p { font-size: 1.2rem; font-weight: bold; margin: 1.5rem 0; }
.prize-amount {
display: block;
font-size: 2rem;
color: #fff;
background: rgba(0,0,0,0.3);
padding: 10px;
border-radius: 8px;
margin-top: 10px;
}
.hidden { display: none !important; }
</style>
</head>
<body>
<div id="registration-overlay">
<div class="input-card">
<h2>🎉 Gacha THR Kelas</h2>
<p>Masukin Nama Kamu: </p>
<input type="text" id="username" placeholder="Isi Nama Kamu..." autocomplete="off">
<br>
<button class="btn" onclick="startApp()">Mulai</button>
</div>
</div>
<div id="main-app">
<h1>Semoga Beruntung Guys 🗿🗿</h1>
<p>Halo, <b id="display-name">...</b>!</p>
<div class="wheel-area">
<div class="pointer"></div>
<canvas id="wheel"></canvas>
</div>
<button id="spin-btn" class="btn btn-spin" onclick="spin()">PUTAR SEKARANG!</button>
<p style="font-size: 0.8rem; color: #ccc;">*Kesempatan putar hanya sekali.</p>
</div>
<div id="result-popup">
<div class="envelope-card">
<h2>😂 SELAMAT!</h2>
<p id="congrats-text"></p>
<p style="font-size: 1rem; color: #fee440;">Terima kasih sudah berpartisipasi!</p>
<!--<button class="btn" style="background:var(--dark);" onclick="location.reload()">Tutup</button>-->
</div>
</div>
<audio id="spin-sound" src="https://assets.mixkit.co/active_storage/sfx/2004/2004-preview.mp3" preload="auto"></audio>
<audio id="win-sound" src="https://assets.mixkit.co/active_storage/sfx/1435/1435-preview.mp3" preload="auto"></audio>
<script>
// === KONFIGURASI ===
const canvas = document.getElementById('wheel');
const ctx = canvas.getContext('2d');
const spinBtn = document.getElementById('spin-btn');
const mainApp = document.getElementById('main-app');
const registerOverlay = document.getElementById('registration-overlay');
const spinSound = document.getElementById('spin-sound');
const winSound = document.getElementById('win-sound');
// Hadiah dan Peluang (Sesuai spesifikasi Anda)
// Weight adalah persentase: total harus 100
const prizes = [
{ label: '10 Hari', weight: 34, color: 'salmon' }, // Salmon
{ label: '10 Hari', weight: 34, color: '#e63946' }, // Merah
{ label: '15 Hari', weight: 14, color: 'darkcyan' }, // Hijau Tua
{ label: '20 Hari', weight: 14, color: 'dodgerblue' }, // Biru Muda
{ label: '25 Hari', weight: 2, color: 'gold' }, // Emas
//{ label: '100rb', weight: 5, color: 'darkcyan' } // hijau
];
let isSpinning = false;
let userName = "";
// Ukuran Kanvas (Internal, bukan display CSS)
const size = 300;
const center = size / 2;
const sliceAngle = 360 / prizes.length;
const sliceAngleRad = (2 * Math.PI) / prizes.length;
// === LOGIKA LOCALSTORAGE ===
window.onload = () => {
const savedUser = localStorage.getItem('gacha_user');
const savedPrize = localStorage.getItem('gacha_prize');
if (savedUser && savedPrize) {
// User sudah pernah spin
showFinalCard(savedUser, savedPrize, true);
} else {
// User baru, gambar roda
drawWheel();
}
};
// === GAMBAR RODA (CANVAS) ===
function drawWheel() {
canvas.width = size;
canvas.height = size;
prizes.forEach((prize, i) => {
// 1. Gambar Potongan
ctx.beginPath();
ctx.fillStyle = prize.color;
ctx.moveTo(center, center);
ctx.arc(center, center, center, i * sliceAngleRad, (i + 1) * sliceAngleRad);
ctx.fill();
// 2. Gambar Teks Hadiah
ctx.save();
ctx.translate(center, center);
// Rotate ke tengah-tengah potongan
ctx.rotate(i * sliceAngleRad + sliceAngleRad / 2);
// Atur warna teks agar kontras
ctx.fillStyle = (prize.color === '#f1faee' || prize.color === '#a8dadc') ? '#1d3557' : '#fff';
ctx.font = 'bold 20px Poppins, sans-serif';
ctx.textAlign = 'right';
// Geser teks agar tidak menempel tengah
ctx.fillText(prize.label, center - 20, 7);
ctx.restore();
});
}
// === MASUK & MULAI ===
function startApp() {
const inputName = document.getElementById('username').value.trim();
if (inputName.length < 3) return alert("Masukkan Nama Yang Bener!");
userName = inputName;
document.getElementById('display-name').innerText = userName;
registerOverlay.classList.add('hidden');
mainApp.style.display = 'block';
}
// === LOGIKA PELUANG (WEIGHTED RANDOM) ===
function calculateWeightedPrize() {
let totalWeight = prizes.reduce((sum, p) => sum + p.weight, 0);
let randomNum = Math.random() * totalWeight;
for (let i = 0; i < prizes.length; i++) {
if (randomNum < prizes[i].weight) {
return i; // Mengembalikan index hadiah
}
randomNum -= prizes[i].weight;
}
}
// === PROSES SPIN ===
function spin() {
if (isSpinning) return;
isSpinning = true;
spinBtn.disabled = true;
spinBtn.innerText = "SEDANG BERPUTAR...";
// 1. Tentukan hadiah (index)
const prizeIndex = calculateWeightedPrize();
// 2. Hitung Sudut Akhir (Wajib Sinkron dengan Gambar)
// Offset -90 karena jarum di atas, sedangkan kanvas mulai dari kanan.
// Kita hitung sudut tengah-tengah potongan hadiah.
const targetAngleMid = (prizeIndex * sliceAngle) + (sliceAngle / 2);
// Jarak yang harus ditempuh agar tengah hadiah berhenti di jarum (sudut 270)
const distanceToTarget = 360 - targetAngleMid;
// Berapa kali putaran penuh (min 5x agar seru) + jarak target
const extraSpins = 360 * 5;
const finalRotation = extraSpins + distanceToTarget;
// 3. Jalankan Audio dan Animasi
spinSound.play();
// Gunakan cubic-bezier untuk efek putar lambat di akhir
canvas.style.transition = "transform 8s cubic-bezier(0.15, 0, 0.15, 1)";
// Kita tambahkan rotation saat ini agar tidak restart dari nol jika di-hack
canvas.style.transform = `rotate(-90deg) rotate(${finalRotation}deg)`;
// 4. Setelah Animasi Selesai (5 Detik)
setTimeout(() => {
const wonPrize = prizes[prizeIndex].label;
// Matikan suara roda, nyalakan suara menang
spinSound.pause();
spinSound.currentTime = 0;
winSound.play();
// Simpan ke LocalStorage dan tampilkan kartu
saveAndShow(wonPrize);
}, 8100);
}
// === SIMPAN & TAMPILKAN HASIL ===
function saveAndShow(prize) {
localStorage.setItem('gacha_user', userName);
localStorage.setItem('gacha_prize', prize);
showFinalCard(userName, prize, false);
}
// === MENAMPILKAN KARTU AMPlOP ===
function showFinalCard(name, prize, alreadyPlayed = false) {
// Sembunyikan form pendaftaran
registerOverlay.classList.add('hidden');
// Pastikan aplikasi utama tampil (agar background tidak kosong)
mainApp.style.display = 'block';
spinBtn.disabled = true;
spinBtn.innerText = "SUDAH PERNAH SPIN";
const popup = document.getElementById('result-popup');
const text = document.getElementById('congrats-text');
popup.style.display = 'flex';
if (alreadyPlayed) {
text.innerHTML = `Halo ${name},<br>Kamu Depet THR Sebesar: <span class="prize-amount">Tambah ${prize}</span>`;
} else {
text.innerHTML = `Selamat ${name},<br>Kamu Dapet THR Sebesar: <span class="prize-amount">Tambah ${prize}</span>`;
}
}
</script>
</body>
</html>