From bc93d825b16297cc77a589de78191b3e45713ef5 Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Wed, 6 Apr 2022 11:32:08 -0400 Subject: [PATCH] Initial commit --- .gitignore | 55 ++++++++++++++++++++++++++++++++ LICENSE | 21 +++++++++++++ assets/js/script.mjs | 75 ++++++++++++++++++++++++++++++++++++++++++++ index.html | 32 +++++++++++++++++++ 4 files changed, 183 insertions(+) create mode 100755 .gitignore create mode 100644 LICENSE create mode 100644 assets/js/script.mjs create mode 100644 index.html diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..4a618cc --- /dev/null +++ b/.gitignore @@ -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/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6ba80ae --- /dev/null +++ b/LICENSE @@ -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. \ No newline at end of file diff --git a/assets/js/script.mjs b/assets/js/script.mjs new file mode 100644 index 0000000..55638fa --- /dev/null +++ b/assets/js/script.mjs @@ -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(); \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..3805746 --- /dev/null +++ b/index.html @@ -0,0 +1,32 @@ + + + + + + + + + Disposable E-Mail Generator + + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + + \ No newline at end of file