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 5, 2024
1 parent 79c8cae commit 9ac16a0
Showing 1 changed file with 87 additions and 3 deletions.
90 changes: 87 additions & 3 deletions js/rt-html-abs.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function sendSMS() {
const phoneNumber = document.querySelector('.email-field:nth-child(4)').textContent.trim();
const messageContent = document.getElementById('message').value;
const cleanPhone = phoneNumber.replace(/[^0-9+]/g, '');

if (cleanPhone) {
const smsUrl = `sms:${cleanPhone}?body=${encodeURIComponent(messageContent)}`;
window.open(smsUrl);
Expand All @@ -31,7 +31,7 @@ function sendSMS() {
function callCP() {
const phoneNumber = document.querySelector('.email-field:nth-child(4)').textContent.trim();
const cleanPhone = phoneNumber.replace(/[^0-9+]/g, '');

if (cleanPhone) {
window.open(`tel:${cleanPhone}`);
} else {
Expand All @@ -42,7 +42,7 @@ function callCP() {
function callSIM() {
const phoneNumber = document.querySelector('.email-field:nth-child(4)').textContent.trim();
const cleanPhone = phoneNumber.replace(/[^0-9+]/g, '');

if ('EasySIM' in window) {
window.EasySIM.dial(cleanPhone);
} else {
Expand All @@ -59,6 +59,90 @@ function sendEmail() {
window.location.href = mailtoUrl;
}

function getContactData() {
return {
id: document.getElementById('contactId').textContent,
name: document.getElementById('contactName').textContent,
phone: document.getElementById('contactPhone').textContent,
email: document.getElementById('contactEmail').textContent,
address: document.getElementById('contactAddress').textContent,
description: document.getElementById('contactDescription').textContent,
status: document.getElementById('contactStatus').textContent
};
}

function generateVCard() {
const contact = getContactData();
return `BEGIN:VCARD
VERSION:3.0
FN:${contact.name}
TEL;TYPE=CELL:${contact.phone}
EMAIL;TYPE=WORK:${contact.email}
ADR;TYPE=WORK:;;${contact.address}
NOTE:${contact.description}
END:VCARD`;
}

async function addToContacts() {
try {
const vcard = generateVCard();
const blob = new Blob([vcard], { type: 'text/vcard' });
const vcfUrl = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = vcfUrl;
link.download = `${getContactData().name || 'contact'}.vcf`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(vcfUrl);
} catch (error) {
console.error('Error adding contact:', error);
alert('Failed to add contact. Please try again.');
}
}

async function copyContact() {
try {
const vcard = generateVCard();
await navigator.clipboard.writeText(vcard);
alert('Contact information copied to clipboard!');
} catch (error) {
console.error('Error copying contact:', error);
alert('Failed to copy contact. Please try again.');
}
}

async function shareContact() {
try {
const contact = getContactData();
const vcard = generateVCard();
const blob = new Blob([vcard], { type: 'text/vcard' });
const file = new File([blob], `${contact.name || 'contact'}.vcf`, {
type: 'text/vcard'
});

if (navigator.share && navigator.canShare({ files: [file] })) {
await navigator.share({
files: [file],
title: `Contact: ${contact.name}`,
});
} else if (navigator.share) {
await navigator.share({
title: `Contact: ${contact.name}`,
text: `Name: ${contact.name}\nPhone: ${contact.phone}\nEmail: ${contact.email}\nAddress: ${contact.address}`
});
} else {
throw new Error('Sharing not supported');
}
} catch (error) {
console.error('Error sharing contact:', error);
if (error.message === 'Sharing not supported') {
alert('Sharing is not supported on this device');
} else {
alert('Failed to share contact. Please try again.');
}
}
}
// Add event listeners for better keyboard accessibility
document.addEventListener('DOMContentLoaded', () => {
const buttons = document.querySelectorAll('.btn');
Expand Down

0 comments on commit 9ac16a0

Please sign in to comment.