FarelDeveloper commited on
Commit
39bb0e7
·
verified ·
1 Parent(s): da7a97d

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +25 -5
index.html CHANGED
@@ -8,6 +8,7 @@ body{background:#020617;color:#fff;font-family:sans-serif}
8
  .box{max-width:500px;margin:40px auto;background:#0f172a;padding:20px;border-radius:10px}
9
  input,select,button{width:100%;padding:10px;margin:6px 0}
10
  button{background:#38bdf8;border:0;cursor:pointer}
 
11
  .msg{background:#020617;padding:8px;border-radius:5px;margin:5px 0}
12
  </style>
13
  </head>
@@ -18,7 +19,7 @@ button{background:#38bdf8;border:0;cursor:pointer}
18
 
19
  <input id="name" placeholder="username">
20
  <select id="domain"></select>
21
- <button onclick="createEmail()">Buat Email</button>
22
 
23
  <b id="email"></b>
24
  <div id="inbox"></div>
@@ -27,29 +28,46 @@ button{background:#38bdf8;border:0;cursor:pointer}
27
  <script>
28
  let currentEmail = null;
29
  let timer = null;
 
30
 
31
- // 🔧 FIX DI SINI
32
  async function loadDomains(){
33
  const r = await fetch('/api/domains');
34
  const j = await r.json();
35
 
36
  domain.innerHTML = '';
 
 
37
  j.domains.forEach(d=>{
38
  const dom = typeof d === 'string' ? d : d.name;
 
39
  domain.innerHTML += `<option value="${dom}">${dom}</option>`;
40
  });
 
 
 
 
 
 
41
  }
42
 
43
- // TIDAK DIUBAH
44
  async function createEmail(){
 
 
 
 
 
 
45
  const r = await fetch('/api/email/new',{
46
  method:'POST',
47
  headers:{'Content-Type':'application/json'},
48
  body:JSON.stringify({
49
- name: name.value,
50
  domain: domain.value
51
  })
52
  });
 
53
  const j = await r.json();
54
  if(!j.success) return alert(j.error);
55
 
@@ -60,11 +78,13 @@ async function createEmail(){
60
  timer = setInterval(loadInbox, 5000);
61
  }
62
 
63
- // TIDAK DIUBAH
64
  async function loadInbox(){
65
  if(!currentEmail) return;
 
66
  const r = await fetch('/api/email/' + currentEmail + '/messages');
67
  const j = await r.json();
 
68
  inbox.innerHTML = '';
69
  j.messages?.forEach(m=>{
70
  inbox.innerHTML += `
 
8
  .box{max-width:500px;margin:40px auto;background:#0f172a;padding:20px;border-radius:10px}
9
  input,select,button{width:100%;padding:10px;margin:6px 0}
10
  button{background:#38bdf8;border:0;cursor:pointer}
11
+ button:disabled{opacity:.6;cursor:not-allowed}
12
  .msg{background:#020617;padding:8px;border-radius:5px;margin:5px 0}
13
  </style>
14
  </head>
 
19
 
20
  <input id="name" placeholder="username">
21
  <select id="domain"></select>
22
+ <button id="btn" onclick="createEmail()" disabled>Buat Email</button>
23
 
24
  <b id="email"></b>
25
  <div id="inbox"></div>
 
28
  <script>
29
  let currentEmail = null;
30
  let timer = null;
31
+ let domainList = [];
32
 
33
+ // 🔥 LOAD DOMAIN + AUTO RANDOM
34
  async function loadDomains(){
35
  const r = await fetch('/api/domains');
36
  const j = await r.json();
37
 
38
  domain.innerHTML = '';
39
+ domainList = [];
40
+
41
  j.domains.forEach(d=>{
42
  const dom = typeof d === 'string' ? d : d.name;
43
+ domainList.push(dom);
44
  domain.innerHTML += `<option value="${dom}">${dom}</option>`;
45
  });
46
+
47
+ // auto pilih random
48
+ const random = domainList[Math.floor(Math.random() * domainList.length)];
49
+ domain.value = random;
50
+
51
+ btn.disabled = false;
52
  }
53
 
54
+ // 🔥 CREATE EMAIL (AMAN)
55
  async function createEmail(){
56
+ if (!name.value.trim())
57
+ return alert('Username wajib diisi');
58
+
59
+ if (!domain.value)
60
+ return alert('Domain belum siap');
61
+
62
  const r = await fetch('/api/email/new',{
63
  method:'POST',
64
  headers:{'Content-Type':'application/json'},
65
  body:JSON.stringify({
66
+ name: name.value.trim(),
67
  domain: domain.value
68
  })
69
  });
70
+
71
  const j = await r.json();
72
  if(!j.success) return alert(j.error);
73
 
 
78
  timer = setInterval(loadInbox, 5000);
79
  }
80
 
81
+ // 🔥 LOAD INBOX
82
  async function loadInbox(){
83
  if(!currentEmail) return;
84
+
85
  const r = await fetch('/api/email/' + currentEmail + '/messages');
86
  const j = await r.json();
87
+
88
  inbox.innerHTML = '';
89
  j.messages?.forEach(m=>{
90
  inbox.innerHTML += `