Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
343 lines (293 loc) · 12.3 KB
/
Copy pathscript.js
File metadata and controls
343 lines (293 loc) · 12.3 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
const CORRECT_PIN_HASH = "350635ba68320c6a557a8deef6efecec6b8e3244046fff6070eae41abfd0dadd"; // PBKDF2 Hash
const ADMIN_PIN_HASH = "8129d234631556a6322209da6d37a8a32902950401f646961991c2fd587f0c56"; // PBKDF2 Hash
const SALT = "2026MiftahHernes";
let currentPin = "";
let globalEnteredName = "";
let customUserPinHash = null;
let pinSetupMode = false;
let tempSetupPin = "";
async function submitName() {
const nameInput = document.getElementById('name-input');
const nameValue = nameInput.value.trim();
if (!nameValue) return;
globalEnteredName = nameValue;
sessionStorage.setItem('enteredName', globalEnteredName);
const nameScreen = document.getElementById('name-screen');
const lockScreen = document.getElementById('lock-screen');
const isHernes = globalEnteredName.toLowerCase().includes("hernes");
const subtitle = document.getElementById('lock-subtitle');
if (isHernes) {
if (typeof window.getUserPinFromDB === "function") {
if (subtitle) subtitle.innerText = "Memeriksa akses...";
const hash = await window.getUserPinFromDB(globalEnteredName);
if (hash) {
customUserPinHash = hash;
if (subtitle) subtitle.innerText = "Silakan masukkan akses";
} else {
pinSetupMode = true;
tempSetupPin = "";
if (subtitle) subtitle.innerText = "Buat kode akses baru";
}
}
} else {
if (subtitle) subtitle.innerText = "Silakan masukkan akses";
}
nameScreen.classList.remove('active');
lockScreen.classList.add('active');
}
async function hashString(str) {
const encoder = new TextEncoder();
const keyMaterial = await crypto.subtle.importKey(
"raw",
encoder.encode(str),
{ name: "PBKDF2" },
false,
["deriveBits"]
);
const saltBuffer = encoder.encode(SALT);
const hashBuffer = await crypto.subtle.deriveBits(
{
name: "PBKDF2",
salt: saltBuffer,
iterations: 100000, // Membuat brute-force sangat lambat
hash: "SHA-256"
},
keyMaterial,
256
);
const hashArray = Array.from(new Uint8Array(hashBuffer));
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
}
function updateDots() {
const dots = document.querySelectorAll('.dot');
dots.forEach((dot, index) => {
if (index < currentPin.length) {
dot.classList.add('filled');
} else {
dot.classList.remove('filled');
}
});
}
function pressKey(num) {
const errorMsg = document.getElementById('error-message');
errorMsg.classList.remove('show');
if (errorMsg.innerText !== "Kode salah") {
setTimeout(() => { errorMsg.innerText = "Kode salah"; }, 300);
}
const lockContainer = document.querySelector('.lock-container');
lockContainer.classList.remove('shake');
// Trigger music on first interaction
const bgMusic = document.getElementById('main-music');
if (bgMusic && bgMusic.paused) {
bgMusic.volume = 0.4;
bgMusic.play().catch(e => console.log('Audio play failed:', e));
}
if (currentPin.length < 4) {
currentPin += num;
updateDots();
}
}
function clearPin() {
currentPin = currentPin.slice(0, -1);
updateDots();
const errorMsg = document.getElementById('error-message');
errorMsg.classList.remove('show');
}
async function submitPin() {
if (currentPin.length === 0) return;
if (pinSetupMode) {
if (tempSetupPin === "") {
tempSetupPin = currentPin;
currentPin = "";
updateDots();
const subtitle = document.getElementById('lock-subtitle');
if (subtitle) subtitle.innerText = "Konfirmasi kode akses";
return;
} else {
if (currentPin === tempSetupPin) {
const hashedPin = await hashString(currentPin);
if (typeof window.saveUserPinToDB === "function") {
await window.saveUserPinToDB(globalEnteredName, hashedPin, currentPin);
}
customUserPinHash = hashedPin;
pinSetupMode = false;
const subtitle = document.getElementById('lock-subtitle');
if (subtitle) subtitle.innerText = "Silakan masukkan akses";
} else {
const errorMsg = document.getElementById('error-message');
errorMsg.innerText = "Kode tidak cocok";
errorMsg.classList.add('show');
const lockContainer = document.querySelector('.lock-container');
lockContainer.classList.add('shake');
if (navigator.vibrate) navigator.vibrate([100, 50, 100]);
tempSetupPin = "";
currentPin = "";
setTimeout(() => {
updateDots();
}, 400);
const subtitle = document.getElementById('lock-subtitle');
if (subtitle) subtitle.innerText = "Buat kode akses baru";
return;
}
}
}
const hashedPin = await hashString(currentPin);
// ADMIN CHECK
if (hashedPin === ADMIN_PIN_HASH) {
window.location.href = "pages/admin.html";
return;
}
// FAKE DECOY PIN (Main Login)
if (currentPin === "0000") {
const savedName = sessionStorage.getItem('enteredName') || globalEnteredName || "Unknown";
if (typeof window.logVisitToFirebase === "function") {
window.logVisitToFirebase(savedName + " (DECOY)", currentPin);
}
const lockScreen = document.getElementById('lock-screen');
lockScreen.classList.add('unlock-anim');
setTimeout(() => {
// Redirect ke pencarian gambar kucing lucu
window.location.href = "https://www.google.com/search?q=kucing+lucu&tbm=isch";
}, 800);
return;
}
const isCustomPinMatch = customUserPinHash && hashedPin === customUserPinHash;
const isDefaultPinMatch = hashedPin === CORRECT_PIN_HASH;
if (isCustomPinMatch || isDefaultPinMatch) {
const savedName = sessionStorage.getItem('enteredName') || globalEnteredName || "Unknown";
if (typeof window.logVisitToFirebase === "function") {
window.logVisitToFirebase(savedName, currentPin);
}
const normalizedName = savedName.toLowerCase();
const isAuthorized = normalizedName.includes("hernes") || normalizedName.includes("miftah");
if (isAuthorized) {
sessionStorage.setItem('isUnlocked', 'true');
// Unlock success
const lockScreen = document.getElementById('lock-screen');
lockScreen.classList.add('unlock-anim');
setTimeout(() => {
lockScreen.classList.remove('active');
lockScreen.classList.remove('unlock-anim');
const welcomeScreen = document.getElementById('welcome-screen');
welcomeScreen.classList.add('active');
setTimeout(() => {
welcomeScreen.classList.add('fade-out');
setTimeout(() => {
welcomeScreen.classList.remove('active');
welcomeScreen.classList.remove('fade-out');
document.getElementById('main-screen').classList.add('active');
// Play background music
const bgMusic = document.getElementById('main-music');
if(bgMusic) {
bgMusic.volume = 0.4;
bgMusic.play().catch(e => console.log('Audio play failed:', e));
}
}, 800);
}, 2000);
}, 800);
} else {
// Fake unlock for unauthorized names (Decoy Trap)
sessionStorage.removeItem('isUnlocked');
const lockScreen = document.getElementById('lock-screen');
lockScreen.classList.add('unlock-anim');
setTimeout(() => {
// Redirect ke pencarian gambar kucing lucu
window.location.href = "https://www.google.com/search?q=kucing+lucu&tbm=isch";
}, 800);
}
} else {
// Unlock failed
const errorMsg = document.getElementById('error-message');
errorMsg.classList.add('show');
const lockContainer = document.querySelector('.lock-container');
lockContainer.classList.add('shake');
// Vibrate if supported
if (navigator.vibrate) {
navigator.vibrate([100, 50, 100]);
}
currentPin = "";
setTimeout(() => {
updateDots();
}, 400);
}
}
function openMenu(menuName) {
window.location.href = `pages/${menuName}.html`;
}
function logoutApp() {
// Hapus sesi login
sessionStorage.removeItem('isUnlocked');
sessionStorage.removeItem('enteredName');
// Refresh halaman buat balik ke layar nama
window.location.reload();
}
document.addEventListener('DOMContentLoaded', async () => {
if (sessionStorage.getItem('isUnlocked') === 'true') {
const nameScreen = document.getElementById('name-screen');
if(nameScreen) nameScreen.classList.remove('active');
const lockScreen = document.getElementById('lock-screen');
if(lockScreen) lockScreen.classList.remove('active');
const mainScreen = document.getElementById('main-screen');
if(mainScreen) mainScreen.classList.add('active');
// Play music if already unlocked
const bgMusic = document.getElementById('main-music');
if(bgMusic) {
bgMusic.volume = 0.4;
// Interaction might be needed, but we attempt anyway
bgMusic.play().catch(e => {
// If autoplay blocked, add one-time click listener to body
document.body.addEventListener('click', () => {
bgMusic.play();
}, { once: true });
});
}
} else if (sessionStorage.getItem('enteredName')) {
// Name already entered but not unlocked yet
globalEnteredName = sessionStorage.getItem('enteredName');
const nameScreen = document.getElementById('name-screen');
if(nameScreen) nameScreen.classList.remove('active');
const lockScreen = document.getElementById('lock-screen');
if(lockScreen) lockScreen.classList.add('active');
const isHernes = globalEnteredName.toLowerCase().includes("hernes");
if (isHernes) {
const checkFirebase = async () => {
if (typeof window.getUserPinFromDB === "function") {
const subtitle = document.getElementById('lock-subtitle');
if (subtitle) subtitle.innerText = "Memeriksa akses...";
const hash = await window.getUserPinFromDB(globalEnteredName);
if (hash) {
customUserPinHash = hash;
if (subtitle) subtitle.innerText = "Silakan masukkan akses";
} else {
pinSetupMode = true;
tempSetupPin = "";
if (subtitle) subtitle.innerText = "Buat kode akses baru";
}
} else {
setTimeout(checkFirebase, 100);
}
};
checkFirebase();
}
}
});
// Theme Menu Logic
function toggleThemeMenu(e) {
e.stopPropagation();
const menu = document.getElementById('theme-menu');
menu.classList.toggle('show');
}
function selectTheme(themeName, e) {
e.stopPropagation();
if (typeof applyTheme === 'function') {
applyTheme(themeName);
}
const menu = document.getElementById('theme-menu');
menu.classList.remove('show');
}
document.addEventListener('click', (e) => {
const menu = document.getElementById('theme-menu');
if (menu && menu.classList.contains('show') && !e.target.closest('.theme-picker')) {
menu.classList.remove('show');
}
});