-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
239 lines (211 loc) · 8.53 KB
/
index.html
File metadata and controls
239 lines (211 loc) · 8.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mettre à jour les contacts</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
text-align: center;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 10px;
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
}
input[type="file"] {
margin: 20px 0;
}
button {
padding: 10px 20px;
background-color: #007BFF;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
margin-top: 10px;
}
button:hover {
background-color: #0056b3;
}
#downloadLink {
display: none;
margin-top: 20px;
text-decoration: none;
color: #28a745;
}
#downloadLink:hover {
text-decoration: underline;
}
#preview {
margin-top: 20px;
text-align: left;
font-size: 14px;
max-height: 300px;
overflow-y: auto;
border: 1px solid #ccc;
padding: 10px;
border-radius: 5px;
}
.contact {
margin-bottom: 10px;
}
.hidden {
display: none;
}
</style>
</head>
<body>
<div class="container">
<h1>Mettre à jour les contacts</h1>
<a id="" href="dublicate.html">Vérifier mes doublons</a>
<p>Importez votre fichier .vcf, examinez les modifications proposées, et choisissez l'action à effectuer.</p>
<input type="file" id="fileInput" accept=".vcf" />
<button id="checkButton">Afficher les modifications proposées</button>
<button id="secondaryButton">Créer un numéro secondaire</button>
<div id="preview"></div>
<div id="modificationCount" class="hidden">
<h3>Total de contacts à modifier : <span id="count"></span></h3>
</div>
<a id="downloadLink" href="#" download="updated_contacts.vcf">Télécharger</a>
</div>
<script>
let originalContent = '';
let updatedContent = '';
let updatedSecondaryContent = '';
let changesPending = false;
function enableDownload(content, fileName, linkText) {
const downloadLink = document.getElementById('downloadLink');
const blob = new Blob([content], { type: 'text/vcard' });
const url = URL.createObjectURL(blob);
downloadLink.href = url;
downloadLink.download = fileName;
downloadLink.textContent = linkText;
downloadLink.style.display = 'inline';
}
document.getElementById('checkButton').addEventListener('click', () => {
const fileInput = document.getElementById('fileInput');
const previewDiv = document.getElementById('preview');
const modificationCountDiv = document.getElementById('modificationCount');
const countSpan = document.getElementById('count');
if (!fileInput.files.length) {
alert('Veuillez importer un fichier .vcf');
return;
}
const file = fileInput.files[0];
const reader = new FileReader();
reader.onload = function (event) {
originalContent = event.target.result;
const updatedNumbers = [];
updatedContent = originalContent.replace(/BEGIN:VCARD([\s\S]*?)END:VCARD/g, (vcard) => {
const nameMatch = vcard.match(/FN:(.+)/); // Récupérer le nom complet
const phoneMatch = vcard.match(/TEL;.*:(.+)/); // Récupérer le numéro de téléphone
if (phoneMatch) {
let originalPhone = phoneMatch[1].replace(/\s+/g, ''); // Supprimer les espaces
const name = nameMatch ? nameMatch[1] : 'Sans nom';
if (originalPhone.length === 8 && !originalPhone.startsWith('01') && !originalPhone.startsWith('02')) {
// Ajouter '01' aux numéros locaux à 8 chiffres
const updatedPhone = `01${originalPhone}`;
const formattedUpdatedPhone = updatedPhone.replace(/(\d{2})(\d{2})(\d{4})/, '$1 $2 $3');
updatedNumbers.push({ name, original: phoneMatch[1], updated: formattedUpdatedPhone });
return vcard.replace(phoneMatch[1], formattedUpdatedPhone);
} else if (
originalPhone.startsWith('+229') ||
originalPhone.startsWith('00229')
) {
// Gestion des numéros commençant par +229 ou 00229
const localPart = originalPhone.replace(/^\+229|^00229/, ''); // Extraire la partie locale
if (!localPart.startsWith('01')) {
const updatedPhone = `+22901${localPart}`;
updatedNumbers.push({ name, original: phoneMatch[1], updated: updatedPhone });
return vcard.replace(phoneMatch[1], updatedPhone);
}
}
}
return vcard; // Pas de modification
});
// Afficher les modifications proposées
previewDiv.innerHTML = '<h3>Modifications proposées :</h3>';
if (updatedNumbers.length > 0) {
updatedNumbers.forEach((entry) => {
const div = document.createElement('div');
div.className = 'contact';
div.innerHTML = `
<strong>Nom :</strong> ${entry.name} <br>
<strong>Ancien numéro :</strong> ${entry.original} <br>
<strong>Nouveau numéro :</strong> ${entry.updated}
`;
previewDiv.appendChild(div);
});
// Afficher le nombre total de modifications
countSpan.textContent = updatedNumbers.length;
modificationCountDiv.classList.remove('hidden');
changesPending = true;
enableDownload(updatedContent, 'updated_contacts.vcf', 'Télécharger avec les contacts modifiés');
} else {
previewDiv.innerHTML += '<p>Aucune modification nécessaire.</p>';
modificationCountDiv.classList.add('hidden');
changesPending = false;
document.getElementById('downloadLink').style.display = 'none';
}
};
reader.readAsText(file);
});
document.getElementById('secondaryButton').addEventListener('click', () => {
const fileInput = document.getElementById('fileInput');
const previewDiv = document.getElementById('preview');
if (!fileInput.files.length) {
alert('Veuillez importer un fichier .vcf');
return;
}
const file = fileInput.files[0];
const reader = new FileReader();
reader.onload = function (event) {
originalContent = event.target.result;
const updatedNumbers = [];
updatedSecondaryContent = originalContent.replace(/BEGIN:VCARD([\s\S]*?)END:VCARD/g, (vcard) => {
const nameMatch = vcard.match(/FN:(.+)/); // Récupérer le nom complet
const phoneMatch = vcard.match(/TEL;.*:(.+)/); // Récupérer le numéro de téléphone
if (phoneMatch) {
let originalPhone = phoneMatch[1].replace(/\s+/g, ''); // Supprimer les espaces
const name = nameMatch ? nameMatch[1] : 'Sans nom';
if (!originalPhone.startsWith('+229')) {
originalPhone = '+229' + originalPhone; // Ajouter le préfixe international si nécessaire
}
if (!originalPhone.slice(4).startsWith('01')) {
const secondaryPhone = `+22901${originalPhone.slice(4)}`; // Générer le numéro secondaire
updatedNumbers.push({ name, existing: phoneMatch[1], secondary: secondaryPhone });
return vcard + `\nTEL;TYPE=SECONDARY:${secondaryPhone}`; // Ajouter le numéro secondaire
}
}
return vcard; // Pas de modification
});
// Afficher les numéros secondaires ajoutés
previewDiv.innerHTML = '<h3>Numéros secondaires ajoutés :</h3>';
if (updatedNumbers.length > 0) {
updatedNumbers.forEach((entry) => {
const div = document.createElement('div');
div.className = 'contact';
div.innerHTML = `
<strong>Nom :</strong> ${entry.name} <br>
<strong>Numéro existant :</strong> ${entry.existing} <br>
<strong>Numéro secondaire :</strong> ${entry.secondary}
`;
previewDiv.appendChild(div);
});
enableDownload(updatedSecondaryContent, 'contacts_with_secondary_numbers.vcf', 'Télécharger avec les contacts secondaires');
} else {
previewDiv.innerHTML += '<p>Aucun numéro secondaire ajouté.</p>';
document.getElementById('downloadLink').style.display = 'none';
}
};
reader.readAsText(file);
});
</script>
</body>
</html>