malaknihed commited on
Commit
107f4cb
·
verified ·
1 Parent(s): dc06196

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +66 -1
static/script.js CHANGED
@@ -44,7 +44,7 @@ function loadResumerPage() {
44
  </div>
45
  <div class="results-container">
46
  <div class="results-placeholder">
47
- <div id="documentResult" class="placeholder-text">Le résultat apparaîtra ici...</div>
48
  <div id="downloadSection" style="display: none; margin-top: 20px;">
49
  <h3 style="color: white; margin-bottom: 10px;">Télécharger la traduction</h3>
50
  <div style="display: flex; gap: 10px;">
@@ -156,6 +156,71 @@ fileInput.addEventListener('change', function(event) {
156
  }
157
  });
158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
 
160
  }
161
 
 
44
  </div>
45
  <div class="results-container">
46
  <div class="results-placeholder">
47
+ <p id="documentResult" class="placeholder-text">Le résultat apparaîtra ici...</p>
48
  <div id="downloadSection" style="display: none; margin-top: 20px;">
49
  <h3 style="color: white; margin-bottom: 10px;">Télécharger la traduction</h3>
50
  <div style="display: flex; gap: 10px;">
 
156
  }
157
  });
158
 
159
+ // Téléchargements
160
+ document.getElementById('downloadPdf').addEventListener('click', downloadAsPdf);
161
+ document.getElementById('downloadWord').addEventListener('click', downloadAsWord);
162
+ document.getElementById('downloadPpt').addEventListener('click', downloadAsPowerPoint);
163
+ document.getElementById('downloadTxt').addEventListener('click', downloadAsText);
164
+ function downloadAsPdf() {
165
+ const text = document.getElementById("documentResult").dataset.translatedText;
166
+ if (!text) return;
167
+
168
+ const { jsPDF } = window.jspdf;
169
+ const doc = new jsPDF();
170
+ doc.text(text, 10, 10);
171
+ doc.save('traduction.pdf');
172
+ }
173
+
174
+ async function downloadAsWord() {
175
+ const text = document.getElementById("documentResult").dataset.translatedText;
176
+ if (!text) return;
177
+
178
+ const { Document, Paragraph, TextRun, Packer } = window.docx;
179
+ const doc = new Document({
180
+ sections: [{
181
+ properties: {},
182
+ children: [
183
+ new Paragraph({
184
+ children: [
185
+ new TextRun(text)
186
+ ]
187
+ })
188
+ ]
189
+ }]
190
+ });
191
+
192
+ Packer.toBlob(doc).then(blob => {
193
+ const url = URL.createObjectURL(blob);
194
+ const a = document.createElement('a');
195
+ a.href = url;
196
+ a.download = 'traduction.docx';
197
+ a.click();
198
+ URL.revokeObjectURL(url);
199
+ });
200
+ }
201
+
202
+ function downloadAsPowerPoint() {
203
+ const text = document.getElementById("documentResult").dataset.translatedText;
204
+ if (!text) return;
205
+
206
+ const pptx = new window.PptxGenJS();
207
+ const slide = pptx.addSlide();
208
+ slide.addText(text, { x: 1, y: 1, w: 8, h: 4 });
209
+ pptx.writeFile({ fileName: 'traduction.pptx' });
210
+ }
211
+
212
+ function downloadAsText() {
213
+ const text = document.getElementById("documentResult").dataset.translatedText;
214
+ if (!text) return;
215
+
216
+ const blob = new Blob([text], { type: 'text/plain' });
217
+ const url = URL.createObjectURL(blob);
218
+ const a = document.createElement('a');
219
+ a.href = url;
220
+ a.download = 'traduction.txt';
221
+ a.click();
222
+ URL.revokeObjectURL(url);
223
+ }
224
 
225
  }
226