From c74017c987c43cfab7a4529bab11ab6d6b9bebbf Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Thu, 26 Feb 2026 13:35:29 +0800 Subject: [PATCH] fix: auto detect mailto prefix --- assets/js/email.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/assets/js/email.js b/assets/js/email.js index 16017543..4d45f4cf 100644 --- a/assets/js/email.js +++ b/assets/js/email.js @@ -1,11 +1,12 @@ (function () { const links = document.querySelectorAll(".email-link"); links.forEach((link) => { - const email = atob(link.getAttribute("data-email")); + let email = atob(link.getAttribute("data-email")); const subject = link.getAttribute("data-subject"); - let mailto = "mailto:" + email; + let mailto = email.startsWith("mailto:") ? email : "mailto:" + email; + if (subject) { - mailto += "?subject=" + encodeURIComponent(subject); + mailto += (mailto.includes("?") ? "&" : "?") + "subject=" + encodeURIComponent(subject); } link.href = mailto; });