Skip to content

Commit

Permalink
Update rt-html-abs.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ledangtrung committed Dec 9, 2024
1 parent 756e86f commit 977832e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions js/rt-html-abs.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,37 @@ function openChat(element) {
App.callActionButton(json);
}

function downloadVCard() {
const vCardContent = document.getElementById('vcardTemplate').textContent;

const fnMatch = vCardContent.match(/FN;CHARSET=utf-8:(.*)/);
const filename = fnMatch ? fnMatch[1].trim() : 'contact';

const blob = new Blob([vCardContent], {
type: 'text/vcard;charset=utf-8'
});

const downloadUrl = URL.createObjectURL(blob);
const downloadLink = document.createElement('a');
downloadLink.href = downloadUrl;
downloadLink.download = `${filename}.vcf`;

document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);

URL.revokeObjectURL(downloadUrl);
}

window.onload = function() {
const button = document.getElementById('downloadButton');
if (button) {
button.addEventListener('click', downloadVCard);
}
};



document.addEventListener('DOMContentLoaded', () => {
const buttons = document.querySelectorAll('.btn');
buttons.forEach(button => {
Expand Down

0 comments on commit 977832e

Please sign in to comment.