Initial commit

This commit is contained in:
Victor Westerlund 2022-04-06 11:32:08 -04:00
commit bc93d825b1
4 changed files with 183 additions and 0 deletions

55
.gitignore vendored Executable file
View file

@ -0,0 +1,55 @@
# victorwesterlund.com #
########################
.well-known/
/content
# Bootstrapping #
#################
/node_modules
/public/hot
/public/storage
/storage/*.key
/vendor
.env
.env.backup
.phpunit.result.cache
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
public/robots.txt
# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
Icon?
ehthumbs.db
Thumbs.db
.directory
# Tool specific files #
#######################
# vim
*~
*.swp
*.swo
# sublime text & textmate
*.sublime-*
*.stTheme.cache
*.tmlanguage.cache
*.tmPreferences.cache
# Eclipse
.settings/*
# JetBrains, aka PHPStorm, IntelliJ IDEA
.idea/*
# NetBeans
nbproject/*
# Visual Studio Code
.vscode
# Sass preprocessor
.sass-cache/

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 Victor Westerlund
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

75
assets/js/script.mjs Normal file
View file

@ -0,0 +1,75 @@
// Convert decimal Unix epoch to base64
function epochToBase64() {
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
let time = Math.floor((Date.now() / 1000)).toString();
let output = '';
// Encode as base64
let i = 0;
do {
let chr1 = time.charCodeAt(i++);
let chr2 = time.charCodeAt(i++);
let chr3 = time.charCodeAt(i++);
let enc1 = chr1 >> 2;
let enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
let enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
let enc4 = chr3 & 63;
if (isNaN(chr2))
enc3 = enc4 = 64;
else if (isNaN(chr3))
enc4 = 64;
// Add chars to result
output += alphabet.charAt(enc1)
+ alphabet.charAt(enc2)
+ alphabet.charAt(enc3)
+ alphabet.charAt(enc4);
} while (i < time.length);
return output;
}
// Set output element value with base64 encoded Unix epoch
function generateTempMail() {
const target = document.getElementById("email");
let domain = document.getElementById("domain");
// Default to victorwesterlund.com
domain = domain.value ? domain.value : "victorwesterlund.com";
target.value = `${epochToBase64()}@${domain}`;
}
// Bind new temp mail button
document.getElementById("tempmail").addEventListener("submit", event => {
event.preventDefault();
generateTempMail();
});
// Select all text on focus of output element
document.getElementById("email").addEventListener("focus", event => event.target.select());
// Bind copy button
document.getElementById("copy").addEventListener("click", event => {
const target = document.getElementById("email");
// Focus output element if Clipboard API is unavailable
if (navigator.hasOwnProperty("clipboard")) {
return target.focus();
}
// Attempt to copy to clipboard or focus output elemet if failed
navigator.clipboard.writeText(target.value)
.then(() => {
const cache = event.target.innerText;
event.target.innerText = "Copied!";
setTimeout(() => event.target.innerText = cache, 1500);
})
.catch(() => target.focus());
});
generateTempMail();

32
index.html Normal file
View file

@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<style>body,html{height:100%;}</style>
<title>Disposable E-Mail Generator</title>
</head>
<body>
<div class="container h-100">
<div class="row h-100 justify-content-center align-items-center">
<form class="col-12" id="tempmail">
<div class="form-group mb-3">
<label for="domain" class="form-label">Domain</label>
<input type="text" class="form-control form-control-lg" id="domain" placeholder="victorwesterlund.com">
</div>
<div class="form-group mb-3">
<label for="email" class="form-label">E-Mail</label>
<input readonly type="text" class="form-control form-control-lg" id="email" placeholder="Generating..">
</div>
<div class="form-group mb-3 d-grid gap-3">
<button type="button" class="btn btn-primary btn-lg" id="copy">Copy to Clipboard</button>
<button type="submit" class="btn btn-outline-secondary btn-lg" id="generate">Generate New</button>
</div>
</form>
</div>
</div>
<script type="module" src="assets/js/script.mjs"></script>
</body>
</html>