fix: auto detect mailto prefix

This commit is contained in:
ZhenShuo Leo
2026-02-26 13:35:29 +08:00
parent be7f6b6f8f
commit c74017c987
+4 -3
View File
@@ -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;
});