Skip to content

Instantly share code, notes, and snippets.

@scottrobertson
Last active December 26, 2021 19:46
Show Gist options
  • Save scottrobertson/68c186f8d7134ed2ef991b3b7cbc99a3 to your computer and use it in GitHub Desktop.
Save scottrobertson/68c186f8d7134ed2ef991b3b7cbc99a3 to your computer and use it in GitHub Desktop.
Automatically generate an email address from the current Safari page. Useful for signing up for services.
// Make sure to run `yarn add tld-extract` / `npm install tld-extract`
const { exec } = require("child_process");
var tldParser = require("tld-extract");
exec(
"osascript -e 'tell app \"safari\" to get the url of the current tab of window 1'",
(_error, stdout) => {
try {
const parsedDomain = tldParser(stdout);
const regex = new RegExp(`.${parsedDomain.tld}`);
console.log(parsedDomain.domain.replace(regex, ""));
} catch (error) {
console.log("signup");
return;
}
}
);
matches:
- trigger: ":EM"
replace: "{{domain}}@[YOUR DOMAIN HERE]"
vars:
- name: domain
type: script
params:
args:
- node
- path to domain_from_url.js
@scottrobertson
Copy link
Author

scottrobertson commented Dec 26, 2021

This means you can type :EM while on GitHub, and it will replace that with github@yourdomain.com.

I have used this for a few years now, and it's been awesome. 1Password Masked Emails, and iCloud Hide My Email are awesome, but I find them super clunky to use compared to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment