mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 23:16:49 +00:00
- refactor email handling logic in handleEmailClick - add new encryptEmail and decryptEmail utility functions - improve error handling for decryption process - simplify the email click handler implementation
22 lines
592 B
JavaScript
22 lines
592 B
JavaScript
export const handleEmailClick = (e, emailIcon, CONTACT_EMAIL) => {
|
|
if (CONTACT_EMAIL && emailIcon && !emailIcon.current.href) {
|
|
e.preventDefault()
|
|
const email = decryptEmail(CONTACT_EMAIL)
|
|
emailIcon.current.href = `mailto:${email}`
|
|
emailIcon.current.click()
|
|
}
|
|
}
|
|
|
|
export const encryptEmail = email => {
|
|
return btoa(unescape(encodeURIComponent(email)))
|
|
}
|
|
|
|
export const decryptEmail = encryptedEmail => {
|
|
try {
|
|
return decodeURIComponent(escape(atob(encryptedEmail)))
|
|
} catch (error) {
|
|
console.error('解密邮箱失败:', error)
|
|
return encryptedEmail
|
|
}
|
|
}
|