-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
74 lines (57 loc) · 1.83 KB
/
index.js
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
addEventListener('fetch', event => {
event.passThroughOnException() // Optional; you know best
event.respondWith(handleRequest(event.request))
})
/**
* Fetch and log a given request object
* @param {Request} request
*/
async function handleRequest(request) {
const url = request.url
// Function to parse query strings
function getParameterByName(name) {
name = name.replace(/[\[\]]/g, '\\$&')
name = name.replace(/\//g, '')
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url)
if (!results) return null
else if (!results[2]) return ''
else if (results[2]) {
results[2] = results[2].replace(/\//g, '')
}
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
function clamp( value, min, max ) {
return min < max
? (value < min ? min : value > max ? max : value)
: (value < max ? max : value > min ? min : value)
}
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
// Get Email from Parameter.
var email = getParameterByName('email');
if( email ) {
// Debug Log Email to Console.
//console.log(email);
let antispambot_email = '';
for ( let letter of email ) {
switch ( getRandomInt( 0 + 1 + clamp( 0, 0, 1 ) ) ) {
case 0:
antispambot_email += `&#${letter.charCodeAt(0)};`;
break;
case 1:
antispambot_email += letter;
break;
case 2:
antispambot_email += `%${padStart(letter.charCodeAt(0).toString(16), 2, '0')}`;
break;
}
}
// Lot To Console.
// console.log(antispambot_email.replace('@', '@') );
return new Response(antispambot_email.replace('@', '@'));
} else {
return new Response( 'Please provide a email address with ?email=.' );
}
}