Generate-email-list
by Nic Fontaine
HTML
<div>
Generate list of email addresses in format: <code>[email protected]</code>
</div>
<hr>
<label>Number</label>
<input id="in-max" value="100"><br>
<label>Email Base</label>
<input id="in-base" value="name"><br>
<label>Email Url</label>
<input id="in-url" value="example.com"><br>
<button id="btn-create" style="margin-top: 1rem;">Create</button>
<hr>
<pre id="pre"></pre>
CSS
html {
font-family: sans-serif;
}
html,
body {
background: #222;
color: #ccc;
}
pre {
-webkit-touch-callout: all;
-webkit-user-select: all;
-khtml-user-select: all;
-moz-user-select: all;
-ms-user-select: all;
user-select: all;
font-family: monospace;
}
JavaScript
var str = {
base: "",
url: "",
out: ""
}
var max = undefined
var i = 0
// Format incremented number to string sortable length
function format(n) {
n = n.toString()
let len = max.toString().length
let diff = len - n.length
let prefix = ""
for (var j = 0; j < diff; j++) {
prefix += "0"
}
n = prefix + n
return n
}
function create() {
// Reset
str.out = ""
i = 0
// Get input values
max = document.getElementById("in-max").value
str.base = document.getElementById("in-base").value
str.url = document.getElementById("in-url").value
// Loop, add incremented emails to variable
for (i; i < max; i++) {
str.out += str.base +
"-" +
format(i) +
"@" +
str.url +
"\n"
}
// Output
document.getElementById("pre").innerHTML = str.out
}
// Add event to Create button
document.getElementById("btn-create").addEventListener("click", create)