]> git.p6c8.net - jirafeau_project.git/blob - lib/functions.js.php
14fad1da5fa98eadc2473c90cba890ad6161cba3
[jirafeau_project.git] / lib / functions.js.php
1 <?php
2 /*
3 * Jirafeau, your web file repository
4 * Copyright (C) 2015 Jerome Jutteau <jerome@jutteau.fr>
5 * Copyright (C) 2015 Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21 header('Content-Type: text/javascript');
22 define('JIRAFEAU_ROOT', dirname(__FILE__) . '/../');
23
24 require(JIRAFEAU_ROOT . 'lib/settings.php');
25 require(JIRAFEAU_ROOT . 'lib/functions.php');
26 require(JIRAFEAU_ROOT . 'lib/lang.php');
27 ?>
28 // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later
29 var web_root = "<?php echo $cfg['web_root']; ?>";
30
31 var lang_array = <?php echo json_lang_generator(null); ?>;
32 var lang_array_fallback = <?php echo json_lang_generator("en"); ?>;
33
34 function translate (expr) {
35 if (lang_array.hasOwnProperty(expr)) {
36 var e = lang_array[expr];
37 if (!isEmpty(e))
38 return e;
39 }
40 if (lang_array_fallback.hasOwnProperty(expr)) {
41 var e = lang_array_fallback[expr];
42 if (!isEmpty(e))
43 return e;
44 }
45 return "FIXME: " + expr;
46 }
47
48 function isEmpty(str) {
49 return (!str || 0 === str.length);
50 }
51
52 // Extend date object with format method
53 Date.prototype.format = function(format) {
54 format = format || 'YYYY-MM-DD hh:mm';
55
56 var zeropad = function(number, length) {
57 number = number.toString();
58 length = length || 2;
59 while(number.length < length)
60 number = '0' + number;
61 return number;
62 },
63 formats = {
64 YYYY: this.getFullYear(),
65 MM: zeropad(this.getMonth() + 1),
66 DD: zeropad(this.getDate()),
67 hh: zeropad(this.getHours()),
68 mm: zeropad(this.getMinutes()),
69 O: (function() {
70 localDate = new Date;
71 sign = (localDate.getTimezoneOffset() > 0) ? '-' : '+';
72 offset = Math.abs(localDate.getTimezoneOffset());
73 hours = zeropad(Math.floor(offset / 60));
74 minutes = zeropad(offset % 60);
75 return sign + hours + ":" + minutes;
76 })()
77 },
78 pattern = '(' + Object.keys(formats).join(')|(') + ')';
79
80 return format.replace(new RegExp(pattern, 'g'), function(match) {
81 return formats[match];
82 });
83 };
84
85 function dateFromUtcString(datestring) {
86 // matches »YYYY-MM-DD hh:mm«
87 var m = datestring.match(/(\d+)-(\d+)-(\d+)\s+(\d+):(\d+)/);
88 return new Date(Date.UTC(+m[1], +m[2] - 1, +m[3], +m[4], +m[5], 0));
89 }
90
91 function dateFromUtcTimestamp(datetimestamp) {
92 return new Date(parseInt(datetimestamp) * 1000)
93 }
94
95 function dateToUtcString(datelocal) {
96 return new Date(
97 datelocal.getUTCFullYear(),
98 datelocal.getUTCMonth(),
99 datelocal.getUTCDate(),
100 datelocal.getUTCHours(),
101 datelocal.getUTCMinutes(),
102 datelocal.getUTCSeconds()
103 ).format();
104 }
105
106 function dateToUtcTimestamp(datelocal) {
107 return (Date.UTC(
108 datelocal.getUTCFullYear(),
109 datelocal.getUTCMonth(),
110 datelocal.getUTCDate(),
111 datelocal.getUTCHours(),
112 datelocal.getUTCMinutes(),
113 datelocal.getUTCSeconds()
114 ) / 1000);
115 }
116
117 function convertAllDatetimeFields() {
118 datefields = document.getElementsByClassName('datetime')
119 for(var i=0; i<datefields.length; i++) {
120 dateUTC = datefields[i].getAttribute('data-datetime');
121 datefields[i].setAttribute('title', dateUTC + ' (GMT)');
122 datefields[i].innerHTML = dateFromUtcString(dateUTC).format('YYYY-MM-DD hh:mm (GMT O)');
123 }
124 }
125
126 function show_link (reference, delete_code, crypt_key, date)
127 {
128 // Upload finished
129 document.getElementById('uploading').style.display = 'none';
130 document.getElementById('upload').style.display = 'none';
131 document.getElementById('upload_finished').style.display = '';
132 document.title = "100% - <?php echo empty($cfg['title']) ? 'Jirafeau' : $cfg['title']; ?>";
133
134 // Download page
135 var download_link_href = 'f.php?h=' + reference;
136 if (crypt_key.length > 0)
137 {
138 download_link_href += '&k=' + crypt_key;
139 }
140 if (!!document.getElementById('upload_finished_download_page'))
141 {
142 document.getElementById('upload_link').href = download_link_href;
143 document.getElementById('upload_link_text').innerHTML = web_root + download_link_href;
144 }
145
146 // Email link
147 var filename = document.getElementById('file_select').files[0].name;
148 var b = encodeURIComponent("<?php echo t("DL"); ?> \"" + filename + "\":") + "%0D" + "%0A";
149 b += encodeURIComponent(web_root + download_link_href) + "%0D" + "%0A";
150 if (false == isEmpty(date))
151 {
152 b += "%0D" + "%0A" + encodeURIComponent("<?php echo t("VALID_UNTIL"); ?>: " + date.format('YYYY-MM-DD hh:mm (GMT O)')) + "%0D" + "%0A";
153 document.getElementById('upload_link_email').href = "mailto:?body=" + b + "&subject=" + encodeURIComponent(filename);
154 }
155
156 // Delete link
157 var delete_link_href = 'f.php?h=' + reference + '&d=' + delete_code;
158 document.getElementById('delete_link').href = delete_link_href;
159 document.getElementById('delete_link_text').innerHTML = web_root + delete_link_href;
160
161 // Validity date
162 if (isEmpty(date))
163 {
164 document.getElementById('date').style.display = 'none';
165 }
166 else {
167 document.getElementById('date').innerHTML = '<span class="datetime" title="'
168 + dateToUtcString(date) + ' (GMT)">'
169 + date.format('YYYY-MM-DD hh:mm (GMT O)')
170 + '</span>';
171 document.getElementById('date').style.display = '';
172 }
173
174 // Preview link (if allowed)
175 if (!!document.getElementById('preview_link'))
176 {
177 document.getElementById('upload_finished_preview').style.display = 'none';
178 var preview_link_href = 'f.php?h=' + reference + '&p=1';
179 if (crypt_key.length > 0)
180 {
181 preview_link_href += '&k=' + crypt_key;
182 }
183
184 // Test if content can be previewed
185 type = document.getElementById('file_select').files[0].type;
186 if ((type.startsWith('image/')
187 || type.startsWith('audio')
188 || type.startsWith('text/plain')
189 || type.startsWith('video/'))
190 && !type.includes('image/svg+xml'))
191 {
192 document.getElementById('preview_link').href = preview_link_href;
193 document.getElementById('preview_link_text').innerHTML = web_root + preview_link_href;
194 document.getElementById('upload_finished_preview').style.display = '';
195 }
196 }
197
198 // Direct download link
199 var direct_download_link_href = 'f.php?h=' + reference + '&d=1';
200 if (crypt_key.length > 0)
201 {
202 direct_download_link_href += '&k=' + crypt_key;
203 }
204 document.getElementById('direct_link').href = direct_download_link_href;
205 document.getElementById('direct_link_text').innerHTML = web_root + direct_download_link_href;
206
207 // Hide preview and direct download link if password is set
208 if (document.getElementById('input_key').value.length > 0)
209 {
210 if (!!document.getElementById('preview_link'))
211 document.getElementById('upload_finished_preview').style.display = 'none';
212 document.getElementById('upload_direct_download').style.display = 'none';
213 }
214 }
215
216 function show_upload_progression (percentage, speed, time_left)
217 {
218 document.getElementById('uploaded_percentage').innerHTML = percentage;
219 document.getElementById('uploaded_speed').innerHTML = speed;
220 document.getElementById('uploaded_time').innerHTML = time_left;
221 document.title = percentage + " - <?php echo empty($cfg['title']) ? 'Jirafeau' : $cfg['title']; ?>";
222 }
223
224 function hide_upload_progression ()
225 {
226 document.getElementById('uploaded_percentage').style.display = 'none';
227 document.getElementById('uploaded_speed').style.display = 'none';
228 document.getElementById('uploaded_time').style.display = 'none';
229 document.title = "<?php echo empty($cfg['title']) ? 'Jirafeau' : $cfg['title']; ?>";
230 }
231
232 function upload_progress (e)
233 {
234 if (e == undefined || e == null || !e.lengthComputable)
235 return;
236
237 // Init time estimation if needed
238 if (upload_time_estimation_total_size == 0)
239 upload_time_estimation_total_size = e.total;
240
241 // Compute percentage
242 var p = Math.round (e.loaded * 100 / e.total);
243 var p_str = ' ';
244 if (p != 100)
245 p_str = p.toString() + '%';
246 // Update estimation speed
247 upload_time_estimation_add(e.loaded);
248 // Get speed string
249 var speed_str = upload_time_estimation_speed_string();
250 speed_str = upload_speed_refresh_limiter(speed_str);
251 // Get time string
252 var time_str = chrono_update(upload_time_estimation_time());
253
254 show_upload_progression (p_str, speed_str, time_str);
255 }
256
257 function control_selected_file_size(max_size, error_str)
258 {
259 f_size = document.getElementById('file_select').files[0].size;
260 if (max_size > 0 && f_size > max_size * 1024 * 1024)
261 {
262 pop_failure(error_str);
263 document.getElementById('send').style.display = 'none';
264 }
265 else
266 {
267 // add class to restyle upload form in next step
268 document.getElementById('upload').setAttribute('class', 'file-selected');
269 // display options
270 document.getElementById('options').style.display = 'block';
271 document.getElementById('send').style.display = 'block';
272 document.getElementById('error_pop').style.display = 'none';
273 document.getElementById('send').focus();
274 }
275 }
276
277 function XHRErrorHandler(e)
278 {
279 var text = "${e.type}: ${e.loaded} bytes transferred"
280 console.log(text)
281 }
282
283 function pop_failure (e)
284 {
285 var text = "<p>An error occured";
286 if (typeof e !== 'undefined')
287 text += ": " + e;
288 text += "</p>";
289 document.getElementById('error_pop').innerHTML = e;
290
291 document.getElementById('uploading').style.display = 'none';
292 document.getElementById('error_pop').style.display = '';
293 document.getElementById('upload').style.display = '';
294 document.getElementById('send').style.display = '';
295 }
296
297 function add_time_string_to_date(d, time)
298 {
299 if(typeof(d) != 'object' || !(d instanceof Date))
300 {
301 return false;
302 }
303
304 if (time == 'minute')
305 {
306 d.setSeconds (d.getSeconds() + 60);
307 return true;
308 }
309 if (time == 'hour')
310 {
311 d.setSeconds (d.getSeconds() + 3600);
312 return true;
313 }
314 if (time == 'day')
315 {
316 d.setSeconds (d.getSeconds() + 86400);
317 return true;
318 }
319 if (time == 'week')
320 {
321 d.setSeconds (d.getSeconds() + 604800);
322 return true;
323 }
324 if (time == 'month')
325 {
326 d.setSeconds (d.getSeconds() + 2592000);
327 return true;
328 }
329 if (time == 'quarter')
330 {
331 d.setSeconds (d.getSeconds() + 7776000);
332 return true;
333 }
334 if (time == 'year')
335 {
336 d.setSeconds (d.getSeconds() + 31536000);
337 return true;
338 }
339 return false;
340 }
341
342 function classic_upload (file, time, password, one_time, upload_password)
343 {
344 // Delay time estimation init as we can't have file size
345 upload_time_estimation_init(0);
346
347 var req = new XMLHttpRequest ();
348 req.upload.addEventListener ("progress", upload_progress, false);
349 req.addEventListener ("error", XHRErrorHandler, false);
350 req.addEventListener ("abort", XHRErrorHandler, false);
351 req.onreadystatechange = function ()
352 {
353 if (req.readyState == 4 && req.status == 200)
354 {
355 var res = req.responseText;
356
357 // if response starts with "Error" then show a failure
358 if (/^Error/.test(res))
359 {
360 pop_failure (res);
361 return;
362 }
363
364 res = res.split ("\n");
365 var expiryDate = '';
366 if (time != 'none')
367 {
368 // convert time (local time + selected expiry date)
369 var localDatetime = new Date();
370 if(!add_time_string_to_date(localDatetime, time))
371 {
372 pop_failure ('Error: Date can not be parsed');
373 return;
374 }
375 expiryDate = localDatetime;
376 }
377
378 show_link (res[0], res[1], res[2], expiryDate);
379 }
380 else
381 {
382 pop_failure ("<?php echo t("ERR_OCC"); ?>");
383 }
384 }
385 req.open ("POST", 'script.php' , true);
386
387 var form = new FormData();
388 form.append ("file", file);
389 if (time)
390 form.append ("time", time);
391 if (password)
392 form.append ("key", password);
393 if (one_time)
394 form.append ("one_time_download", '1');
395 if (upload_password.length > 0)
396 form.append ("upload_password", upload_password);
397
398 req.send (form);
399 }
400
401 function check_html5_file_api ()
402 {
403 return window.File && window.FileReader && window.FileList && window.Blob;
404 }
405
406 var async_global_transfered = 0;
407 var async_global_file;
408 var async_global_ref = '';
409 var async_global_max_size = 0;
410 var async_global_time;
411 var async_global_transfering = 0;
412 var async_global_last_code;
413
414 function async_upload_start (max_size, file, time, password, one_time, upload_password)
415 {
416 async_global_transfered = 0;
417 async_global_file = file;
418 async_global_max_size = max_size;
419 async_global_time = time;
420
421 var req = new XMLHttpRequest ();
422 req.addEventListener ("error", XHRErrorHandler, false);
423 req.addEventListener ("abort", XHRErrorHandler, false);
424 req.onreadystatechange = function ()
425 {
426 if (req.readyState == 4 && req.status == 200)
427 {
428 var res = req.responseText;
429
430 if (/^Error/.test(res))
431 {
432 pop_failure (res);
433 return;
434 }
435
436 res = res.split ("\n");
437 async_global_ref = res[0];
438 var code = res[1];
439 async_upload_push (code);
440 }
441 }
442 req.open ("POST", 'script.php?init_async' , true);
443
444 var form = new FormData();
445 form.append ("filename", async_global_file.name);
446 form.append ("type", async_global_file.type);
447 if (time)
448 form.append ("time", time);
449 if (password)
450 form.append ("key", password);
451 if (one_time)
452 form.append ("one_time_download", '1');
453 if (upload_password.length > 0)
454 form.append ("upload_password", upload_password);
455
456 // Start time estimation
457 upload_time_estimation_init(async_global_file.size);
458
459 req.send (form);
460 }
461
462 function async_upload_progress (e)
463 {
464 if (e == undefined || e == null || !e.lengthComputable && async_global_file.size != 0)
465 return;
466
467 // Compute percentage
468 var p = Math.round ((e.loaded + async_global_transfered) * 100 / (async_global_file.size));
469 var p_str = ' ';
470 if (p != 100)
471 p_str = p.toString() + '%';
472 // Update estimation speed
473 upload_time_estimation_add(e.loaded + async_global_transfered);
474 // Get speed string
475 var speed_str = upload_time_estimation_speed_string();
476 speed_str = upload_speed_refresh_limiter(speed_str);
477 // Get time string
478 var time_str = chrono_update(upload_time_estimation_time());
479
480 show_upload_progression (p_str, speed_str, time_str);
481 }
482
483 function async_upload_push (code)
484 {
485 async_global_last_code = code;
486 if (async_global_transfered == async_global_file.size)
487 {
488 hide_upload_progression ();
489 async_upload_end (code);
490 return;
491 }
492 var req = new XMLHttpRequest ();
493 req.upload.addEventListener ("progress", async_upload_progress, false);
494 req.addEventListener ("error", XHRErrorHandler, false);
495 req.addEventListener ("abort", XHRErrorHandler, false);
496 req.onreadystatechange = function ()
497 {
498 if (req.readyState == 4)
499 {
500 if (req.status == 200)
501 {
502 var res = req.responseText;
503
504 // This error may be triggered when Jirafeau does not receive any file in POST.
505 // This may be due to bad php configuration where post_max_size is too low
506 // comparing to upload_max_filesize. Let's retry with lower file size.
507 if (res === "Error 23")
508 {
509 async_global_max_size = Math.max(1, async_global_max_size - 500);
510 async_upload_push (async_global_last_code);
511 return;
512 }
513 else if (/^Error/.test(res))
514 {
515 pop_failure (res);
516 return;
517 }
518
519 res = res.split ("\n");
520 var code = res[0]
521 async_global_transfered = async_global_transfering;
522 async_upload_push (code);
523 return;
524 }
525 else
526 {
527 if (req.status == 413) // Request Entity Too Large
528 {
529 // lower async_global_max_size and retry
530 async_global_max_size = Math.max(1, parseInt (async_global_max_size * 0.8));
531 }
532 async_upload_push (async_global_last_code);
533 return;
534 }
535 }
536 }
537 req.open ("POST", 'script.php?push_async' , true);
538
539 var start = async_global_transfered;
540 var end = start + async_global_max_size;
541 if (end >= async_global_file.size)
542 end = async_global_file.size;
543 var blob = async_global_file.slice (start, end);
544 async_global_transfering = end;
545
546 var form = new FormData();
547 form.append ("ref", async_global_ref);
548 form.append ("data", blob);
549 form.append ("code", code);
550 req.send (form);
551 }
552
553 function async_upload_end (code)
554 {
555 var req = new XMLHttpRequest ();
556 req.addEventListener ("error", XHRErrorHandler, false);
557 req.addEventListener ("abort", XHRErrorHandler, false);
558 req.onreadystatechange = function ()
559 {
560 if (req.readyState == 4 && req.status == 200)
561 {
562 var res = req.responseText;
563
564 if (/^Error/.test(res))
565 {
566 pop_failure (res);
567 return;
568 }
569
570 res = res.split ("\n");
571 var expiryDate = '';
572 if (async_global_time != 'none')
573 {
574 // convert time (local time + selected expiry date)
575 var localDatetime = new Date();
576 if(!add_time_string_to_date(localDatetime, async_global_time)) {
577 pop_failure ('Error: Date can not be parsed');
578 return;
579 }
580 expiryDate = localDatetime;
581 }
582
583 show_link (res[0], res[1], res[2], expiryDate);
584 }
585 }
586 req.open ("POST", 'script.php?end_async' , true);
587
588 var form = new FormData();
589 form.append ("ref", async_global_ref);
590 form.append ("code", code);
591 req.send (form);
592 }
593
594 function upload (max_size)
595 {
596 var one_time_checkbox = document.getElementById('one_time_download');
597 var one_time = one_time_checkbox !== null ? one_time_checkbox.checked : false;
598 if (check_html5_file_api ())
599 {
600 async_upload_start (
601 max_size,
602 document.getElementById('file_select').files[0],
603 document.getElementById('select_time').value,
604 document.getElementById('input_key').value,
605 one_time,
606 document.getElementById('upload_password').value
607 );
608 }
609 else
610 {
611 classic_upload (
612 document.getElementById('file_select').files[0],
613 document.getElementById('select_time').value,
614 document.getElementById('input_key').value,
615 one_time,
616 document.getElementById('upload_password').value
617 );
618 }
619 }
620
621 var upload_time_estimation_total_size = 42;
622 var upload_time_estimation_transfered_size = 42;
623 var upload_time_estimation_transfered_date = 42;
624 var upload_time_estimation_moving_average_speed = 42;
625
626 function upload_time_estimation_init(total_size)
627 {
628 upload_time_estimation_total_size = total_size;
629 upload_time_estimation_transfered_size = 0;
630 upload_time_estimation_moving_average_speed = 0;
631 var d = new Date();
632 upload_time_estimation_transfered_date = d.getTime();
633 }
634
635 function upload_time_estimation_add(total_transfered_size)
636 {
637 // Let's compute the current speed
638 var d = new Date();
639 var speed = upload_time_estimation_moving_average_speed;
640 if (d.getTime() - upload_time_estimation_transfered_date != 0)
641 speed = (total_transfered_size - upload_time_estimation_transfered_size)
642 / (d.getTime() - upload_time_estimation_transfered_date);
643 // Let's compute moving average speed on 30 values
644 var m = (upload_time_estimation_moving_average_speed * 29 + speed) / 30;
645 // Update global values
646 upload_time_estimation_transfered_size = total_transfered_size;
647 upload_time_estimation_transfered_date = d.getTime();
648 upload_time_estimation_moving_average_speed = m;
649 }
650
651 function upload_time_estimation_speed_string()
652 {
653 // speed ms -> s
654 var s = upload_time_estimation_moving_average_speed * 1000;
655 var res = 0;
656 var scale = '';
657 if (s <= 1000)
658 {
659 res = s.toString();
660 scale = "B/s";
661 }
662 else if (s < 1000000)
663 {
664 res = Math.floor(s/100) / 10;
665 scale = "KB/s";
666 }
667 else
668 {
669 res = Math.floor(s/100000) / 10;
670 scale = "MB/s";
671 }
672 if (res == 0)
673 return '';
674 return res.toString() + ' ' + scale;
675 }
676
677 function milliseconds_to_time_string (milliseconds)
678 {
679 function numberEnding (number) {
680 return (number > 1) ? translate ('PLURAL_ENDING') : '';
681 }
682
683 var temp = Math.floor(milliseconds / 1000);
684 var years = Math.floor(temp / 31536000);
685 if (years) {
686 return years + ' ' + translate ('YEAR') + numberEnding(years);
687 }
688 var days = Math.floor((temp %= 31536000) / 86400);
689 if (days) {
690 return days + ' ' + translate ('DAY') + numberEnding(days);
691 }
692 var hours = Math.floor((temp %= 86400) / 3600);
693 if (hours) {
694 return hours + ' ' + translate ('HOUR') + numberEnding(hours);
695 }
696 var minutes = Math.floor((temp %= 3600) / 60);
697 if (minutes) {
698 return minutes + ' ' + translate ('MINUTE') + numberEnding(minutes);
699 }
700 var seconds = temp % 60;
701 if (seconds) {
702 return seconds + ' ' + translate ('SECOND') + numberEnding(seconds);
703 }
704 return translate ('LESS_1_SEC');
705 }
706
707 function upload_time_estimation_time()
708 {
709 // Estimate remaining time
710 if (upload_time_estimation_moving_average_speed == 0)
711 return 0;
712 return (upload_time_estimation_total_size - upload_time_estimation_transfered_size)
713 / upload_time_estimation_moving_average_speed;
714 }
715
716 var chrono_last_update = 0;
717 var chrono_time_ms = 0;
718 var chrono_time_ms_last_update = 0;
719 function chrono_update(time_ms)
720 {
721 var d = new Date();
722 var chrono = 0;
723 // Don't update too often
724 if (d.getTime() - chrono_last_update < 3000 &&
725 chrono_time_ms_last_update > 0)
726 chrono = chrono_time_ms;
727 else
728 {
729 chrono_last_update = d.getTime();
730 chrono_time_ms = time_ms;
731 chrono = time_ms;
732 chrono_time_ms_last_update = d.getTime();
733 }
734
735 // Adjust chrono for smooth estimation
736 chrono = chrono - (d.getTime() - chrono_time_ms_last_update);
737
738 // Let's update chronometer
739 var time_str = '';
740 if (chrono > 0)
741 time_str = milliseconds_to_time_string (chrono);
742 return time_str;
743 }
744
745 var upload_speed_refresh_limiter_last_update = 0;
746 var upload_speed_refresh_limiter_last_value = '';
747 function upload_speed_refresh_limiter(speed_str)
748 {
749 var d = new Date();
750 if (d.getTime() - upload_speed_refresh_limiter_last_update > 1500)
751 {
752 upload_speed_refresh_limiter_last_value = speed_str;
753 upload_speed_refresh_limiter_last_update = d.getTime();
754 }
755 return upload_speed_refresh_limiter_last_value;
756 }
757
758 // document.ready()
759 document.addEventListener('DOMContentLoaded', function(event) {
760 // Search for all datetime fields and convert the time to local timezone
761 convertAllDatetimeFields();
762 });
763
764 // Add copy event listeners
765 function copyLinkToClipboard(link_id) {
766 var focus = document.activeElement;
767 var e = document.getElementById(link_id);
768
769 var tmp = document.createElement("textarea");
770 document.body.appendChild(tmp);
771 tmp.textContent = e.href;
772 tmp.focus();
773 tmp.setSelectionRange(0, tmp.value.length);
774 document.execCommand("copy");
775 document.body.removeChild(tmp);
776
777 focus.focus();
778 }
779
780 function addCopyListener(button_id, link_id) {
781 if(document.getElementById(button_id)){
782 document.getElementById(button_id)
783 .addEventListener("click", function() {
784 copyLinkToClipboard(link_id);});
785 }
786 }
787 // @license-end

patrick-canterino.de