-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
560 lines (484 loc) · 18.7 KB
/
index.html
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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>DDG API Key Grabber</title>
<link rel="icon" href="favicon.ico" type="image/x-icon">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
color: #333;
}
h1 {
text-align: center;
font-size: 2.5em;
color: #333;
margin-bottom: 50px;
}
.page {
text-align: center;
margin: 0 auto;
width: 80%;
max-width: 500px;
background-color: #fff;
padding: 20px;
border-radius: 4px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.page h1 {
font-size: 2em;
margin-bottom: 20px;
}
.page input[type="text"],
.page input[type="password"] {
width: 90%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
font-size: 1.2em;
}
.page button {
width: 90%;
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 1.2em;
}
.page button:hover {
background-color: #45a049;
}
#tokenOutput {
overflow-wrap: break-word;
word-wrap: break-word;
}
#emailDisplay {
font-size: 1.2em;
color: #333;
margin-bottom: 10px;
padding: 5px;
border: 1px solid #ddd;
border-radius: 4px;
background-color: #f9f9f9;
}
#errorPopup {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 999;
}
#errorPopup>div {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: #fff;
padding: 20px;
border-radius: 5px;
text-align: center;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5);
animation: fade-in 0.5s ease-out;
}
#errorPopup h2 {
color: #ff0000;
}
#errorPopup #error-message {
color: #ff0000;
}
#errorPopup button {
background-color: #ff0000;
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
}
#permissionPopup {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 999;
}
#permissionPopup>div {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: #fff;
padding: 20px;
border-radius: 5px;
text-align: center;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5);
animation: fade-in 0.5s ease-out;
width: 80%;
max-width: 500px;
max-height: 90%;
overflow: auto;
}
#permissionPopup .button-container {
display: flex;
justify-content: space-between;
width: 100%;
}
#permissionPopup button {
background-color: #4CAF50;
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
margin: 10px 0;
flex: 1;
margin: 0 5px;
}
#permissionPopup button:nth-child(1) {
background-color: #ff0000;
}
#permissionPopup button:nth-child(2) {
background-color: #28a745;
}
#permissionPopup h2 {
color: #333;
}
#permissionPopup ul {
text-align: left;
}
#permissionPopup ul li {
margin-bottom: 10px;
}
#permissionPopup ul li strong {
color: #333;
}
.instruction {
background-color: #f9f9f9;
border: 1px solid #ddd;
padding: 15px;
border-radius: 5px;
margin-bottom: 20px;
}
.instruction p {
margin: 0 0 10px;
}
.instruction a {
color: #007BFF;
text-decoration: none;
}
.instruction a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<h1>DDG Email API Key Grabber</h1>
<div id="usernamePage" class="page">
<h1>Enter Username</h1>
<div class="instruction">
<p>Enter your DDG email username here.</p>
<p>If you don't know your username, please visit <a href="https://duckduckgo.com/email" target="_blank"
rel="noopener">duckduckgo.com/email</a>. It will will be listed under: <i>"Autofill enabled in this
browser for"</i>.</p>
</div>
<input type="text" id="username" placeholder="Username">
<div class="h-captcha" data-sitekey="92f19740-3042-4fa0-b878-c38b0301b0c3"></div>
<button onclick="auth()">Next --></button>
</div>
<div id="otpPage" class="page" style="display: none;">
<h1>Enter OTP</h1>
<div class="instruction">
<p>An email was just sent to you from DuckDuckGo.</p>
<p>Enter the OTP (the four random words) OR copy and paste the link here.</p>
</div>
<p id="emailDisplay"></p>
<input type="text" id="otp" placeholder="OTP">
<button id="getKey" onclick="getToken()">Get Key --></button>
<button onclick="backToUsername()"><-- Back</button>
</div>
<div id="tokenPage" class="page" style="display: none;">
<h1>Your API Key</h1>
<div class="instruction">
<p>This is your API key.</p>
<p>Copy it and save it in a password manager for easy access.</p>
</div>
<p id="tokenOutput"></p>
<button id="copyButton" onclick="copyToken()">Copy Key</button>
<button onclick="resetPage()"><-- Start Over</button>
</div>
<div id="errorPopup">
<div>
<h2>Error</h2>
<p id="error-message">An error occurred</p>
<button onclick="closeErrorPopup()">Dismiss</button>
</div>
</div>
<div id="permissionPopup">
<div>
<h2>Third Party App Access</h2>
<h3 id="popup-title"></h3>
<ul>
<li><strong>This app WILL be able to:</strong> Access your API key which will allow it to generate
private duck addresses.</li>
<li><strong>This app WILL NOT be able to:</strong> Access the email associated with your account OR your
personal duck address.</li>
</ul>
<p>NOTE: Your API key cannot be reset, so you cannot revoke access from any apps.</address>
</p>
<div class="button-container">
<button style="background-color: #ff0000;" onclick="authCancel()">Go Back</button>
<button style="background-color: #28a745;"
onclick="document.getElementById('permissionPopup').style.display = 'none'">Continue</button>
</div>
</div>
</div>
<footer
style="position: relative; left: 0; bottom: 0; width: 100%; text-align: center; padding: 10px 0; font-family: Arial, sans-serif; margin-top: 20px;">
<a href="https://github.com/Hamster45105/ddgemail-token">
<img alt="GitHub Repo stars"
src="https://img.shields.io/github/stars/Hamster45105/ddgemail-token?style=social&logo=github&label=Stars">
</a>
<div id="google_translate_element"></div>
<p style="color: #333; font-family: Arial, sans-serif; font-size: 18px; text-align: center;">
Made with ❤️ by
<a href="https://github.com/Hamster45105" target="_blank" rel="noopener"
style="color: #333; text-decoration: none; font-weight: bold;">
Hamster45105
</a>
</p>
</footer>
<script src="https://js.hcaptcha.com/1/api.js" async defer></script>
<script>
// Main functions
async function auth() {
// Set variables
let username = document.getElementById('username').value;
const hcaptchaResponse = hcaptcha.getResponse();
const button = document.querySelector('button[onclick="auth()"]');
// Change button to loading
setButtonLoading(button, 'Authenticating...');
// Remove @duck.com if found
if (username.endsWith('@duck.com')) {
username = username.slice(0, -9);
document.getElementById('username').value = username;
}
// Send request
try {
const response = await fetch('/api/auth', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ username, hcaptchaResponse })
});
// Throw error if response is not OK
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.error);
}
// Display username
document.getElementById('emailDisplay').textContent = document.getElementById('username').value + '@duck.com';
// Change pages
document.getElementById('otpPage').style.display = 'block';
document.getElementById('usernamePage').style.display = 'none';
} catch (error) {
// Throw error if occured
hcaptcha.reset();
showErrorPopup(error.message)
}
// Remove button loading status
unSetButtonLoading(button, 'Next -->');
}
async function getToken() {
// Set variables
let otp = document.getElementById('otp').value.replace(/ /g, '+');
const username = document.getElementById('username').value;
const button = document.querySelector('button[onclick="getToken()"]');
const urlParams = new URLSearchParams(window.location.search);
const callbackUrl = urlParams.get('callback');
const webName = urlParams.get('app_name');
// Change button to loading
setButtonLoading(button, 'Getting Key...');
// Extract words from link if link was pasted
const otpPattern = /https:\/\/duckduckgo\.com\/email\/login\?otp=(\w+-\w+-\w+-\w+)&user=\w+/;
const match = otp.match(otpPattern);
if (match) {
otp = match[1].replace(/-/g, ' ');
document.getElementById('otp').value = otp;
}
// Send request
try {
const response = await fetch('/api/getToken', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ username, otp })
});
// Throw error if response is not OK
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.error);
}
// Display key
const data = await response.json();
document.getElementById('tokenOutput').innerText = data.token;
// Get the callback URL from the URL parameters
// If the callback URL is present, replace [API_KEY] with the token and redirect the user
if (callbackUrl) {
const redirectUrl = callbackUrl.replace('__API_KEY__', data.token);
window.location.href = redirectUrl;
} else {
// Change page
document.getElementById('otpPage').style.display = 'none';
document.getElementById('tokenPage').style.display = 'block';
}
} catch (error) {
// Show error if occured
showErrorPopup(error.message)
}
if (callbackUrl) {
button.innerHTML = 'Continue to: <strong>' + webName + '</strong>';
button.disabled = false;
button.style.backgroundColor = "#4CAF50";
} else {
unSetButtonLoading(button, 'Get Key -->');
}
}
// Page changing
function backToUsername() {
// Reset captcha
hcaptcha.reset();
// Clear OTP textbox
document.getElementById('otp').value = '';
// Change page
document.getElementById('otpPage').style.display = 'none';
document.getElementById('usernamePage').style.display = 'block';
}
function resetPage() {
// Reset captcha
hcaptcha.reset();
// Reset copy button
document.getElementById('copyButton').textContent = 'Copy Key';
document.getElementById('copyButton').style.backgroundColor = '#4CAF50';
// Clear OTP textbox
document.getElementById('otp').value = '';
// Clear result
document.getElementById('tokenOutput').innerText = '';
// Change page
document.getElementById('tokenPage').style.display = 'none';
document.getElementById('usernamePage').style.display = 'block';
}
function authCancel() {
const urlParams = new URLSearchParams(window.location.search);
const callbackUrl = urlParams.get('callback');
const redirectUrl = callbackUrl.replace('__API_KEY__', 'USER_CANCELLED');
window.location.href = redirectUrl;
}
// Button functions
function copyToken() {
var token = document.getElementById('tokenOutput').innerText;
navigator.clipboard.writeText(token);
const button = document.querySelector('button[onclick="copyToken()"]');
button.textContent = "Copied!";
button.style.backgroundColor = "#21ceb7";
}
// Loading button handling
function setButtonLoading(button, loadingText) {
button.textContent = loadingText;
button.disabled = true;
button.style.backgroundColor = "#808080";
}
function unSetButtonLoading(button, originalText) {
button.textContent = originalText;
button.disabled = false;
button.style.backgroundColor = "#4CAF50";
}
window.onload = function () {
const urlParams = new URLSearchParams(window.location.search);
const username = urlParams.get('username');
if (username) {
document.getElementById('username').value = username;
}
// Get the callback URL and web name from the URL parameters
const callbackUrl = urlParams.get('callback');
if (callbackUrl) {
const webName = urlParams.get('app_name');
// Check if the callback URL contains __API_KEY__
if (!callbackUrl.includes('__API_KEY__')) {
showErrorPopup("Invalid callback URL - No API key detected!")
removeCallbackParams();
return;
}
// Check if the callback URL is a valid URL
let url;
try {
url = new URL(callbackUrl.replace('__API_KEY__', "examplekey"));
} catch (_) {
showErrorPopup("Invalid callback URL - Not a valid URL!");
removeCallbackParams();
return;
}
// If app name is present, modify the button
if (webName) {
// Get the button element
const btn = document.getElementById('getKey');
// Set the button text
btn.innerHTML = 'Continue to: <strong>' + webName + '</strong>';
}
// Show the popup
const popup = document.getElementById('permissionPopup');
const title = document.getElementById('popup-title');
title.textContent = 'Authorize "' + (webName || 'an unnamed app') + '" to access your DuckDuckGo email account';
popup.style.display = 'block';
}
}
// Remove params
function removeCallbackParams() {
const url = new URL(window.location.href);
url.searchParams.delete('callback');
url.searchParams.delete('app_name');
window.history.replaceState({}, '', url);
}
// Error popup handling
function showErrorPopup(errorMessage) {
document.getElementById("error-message").innerHTML = errorMessage;
document.getElementById("errorPopup").style.display = "block";
}
function closeErrorPopup() {
document.getElementById("errorPopup").style.display = "none";
}
// Keyboard enter shortcuts
document.getElementById('username').addEventListener('keydown', function (event) {
if (event.key === 'Enter') {
auth();
}
});
document.getElementById('otp').addEventListener('keydown', function (event) {
if (event.key === 'Enter') {
getToken();
}
});
</script>
<script type="text/javascript"
src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({ pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.HORIZONTAL }, 'google_translate_element');
}
</script>
</body>
</html>