Skip to content

Instantly share code, notes, and snippets.

@jbranchaud
Created November 20, 2024 17:59
Show Gist options
  • Save jbranchaud/6f19c839b420ac42b1f988a58c5681be to your computer and use it in GitHub Desktop.
Save jbranchaud/6f19c839b420ac42b1f988a58c5681be to your computer and use it in GitHub Desktop.
Get email (w/ current site interpolated) for newsletter signup
/** @type {import("@johnlindquist/kit")} */
// Name: Get Email for Newsletter
// Description: Create email address with current domain interpolated
const createEmailWithDomain = (baseEmail, { url }) => {
const [emailUser, emailDomain] = baseEmail.split("@");
const urlObj = new URL(url);
let domain = urlObj.host.split(".");
// Only remove www if it's exactly the first subdomain
if (domain[0] === "www") {
domain = domain.slice(1);
}
return `${emailUser}+${domain.join("-")}@${emailDomain}`;
};
let jxa = await npm("@jxa/run");
let result = await jxa.run(() => {
let windows = Application("com.google.Chrome").windows();
let tab = windows[0].activeTab();
return {
url: tab.url(),
};
});
const baseEmail = await env("PERSONAL_EMAIL");
await copy(createEmailWithDomain(baseEmail, result));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment