]> git.p6c8.net - jirafeau_mojo42.git/blob - lib/functions.js.php
73e901f2b28607760b812bde4fafc0b47a334574
[jirafeau_mojo42.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.indexOf("image") > -1 ||
187 type.indexOf("audio") > -1 ||
188 type.indexOf("text") > -1 ||
189 type.indexOf("video") > -1)
190 {
191 document.getElementById('preview_link').href = preview_link_href;
192 document.getElementById('preview_link_text').innerHTML = web_root + preview_link_href;
193 document.getElementById('upload_finished_preview').style.display = '';
194 }
195 }
196
197 // Direct download link
198 var direct_download_link_href = 'f.php?h=' + reference + '&d=1';
199 if (crypt_key.length > 0)
200 {
201 direct_download_link_href += '&k=' + crypt_key;
202 }
203 document.getElementById('direct_link').href = direct_download_link_href;
204 document.getElementById('direct_link_text').innerHTML = web_root + direct_download_link_href;
205
206 // Hide preview and direct download link if password is set
207 if (document.getElementById('input_key').value.length > 0)
208 {
209 if (!!document.getElementById('preview_link'))
210 document.getElementById('upload_finished_preview').style.display = 'none';
211 document.getElementById('upload_direct_download').style.display = 'none';
212 }
213 }
214
215 function show_upload_progression (percentage, speed, time_left)
216 {
217 document.getElementById('uploaded_percentage').innerHTML = percentage;
218 document.getElementById('uploaded_speed').innerHTML = speed;
219 document.getElementById('uploaded_time').innerHTML = time_left;
220 document.title = percentage + " - <?php echo empty($cfg['title']) ? 'Jirafeau' : $cfg['title']; ?>";
221 }
222
223 function hide_upload_progression ()
224 {
225 document.getElementById('uploaded_percentage').style.display = 'none';
226 document.getElementById('uploaded_speed').style.display = 'none';
227 document.getElementById('uploaded_time').style.display = 'none';
228 document.title = "<?php echo empty($cfg['title']) ? 'Jirafeau' : $cfg['title']; ?>";
229 }
230
231 function upload_progress (e)
232 {
233 if (e == undefined || e == null || !e.lengthComputable)
234 return;
235
236 // Init time estimation if needed
237 if (upload_time_estimation_total_size == 0)
238 upload_time_estimation_total_size = e.total;
239
240 // Compute percentage
241 var p = Math.round (e.loaded * 100 / e.total);
242 var p_str = ' ';
243 if (p != 100)
244 p_str = p.toString() + '%';
245 // Update estimation speed
246 upload_time_estimation_add(e.loaded);
247 // Get speed string
248 var speed_str = upload_time_estimation_speed_string();
249 speed_str = upload_speed_refresh_limiter(speed_str);
250 // Get time string
251 var time_str = chrono_update(upload_time_estimation_time());
252
253 show_upload_progression (p_str, speed_str, time_str);
254 }
255
256 function control_selected_file_size(max_size, error_str)
257 {
258 f_size = document.getElementById('file_select').files[0].size;
259 if (max_size > 0 && f_size > max_size * 1024 * 1024)
260 {
261 pop_failure(error_str);
262 document.getElementById('send').style.display = 'none';
263 }
264 else
265 {
266 // add class to restyle upload form in next step
267 document.getElementById('upload').setAttribute('class', 'file-selected');
268 // display options
269 document.getElementById('options').style.display = 'block';
270 document.getElementById('send').style.display = 'block';
271 document.getElementById('error_pop').style.display = 'none';
272 document.getElementById('send').focus();
273 }
274 }
275
276 function pop_failure (e)
277 {
278 var text = "An error occured";
279 if (typeof e !== 'undefined')
280 text = e;
281 text = "<p>" + text + "</p>";
282 document.getElementById('error_pop').innerHTML = e;
283
284 document.getElementById('uploading').style.display = 'none';
285 document.getElementById('error_pop').style.display = '';
286 document.getElementById('upload').style.display = '';
287 document.getElementById('send').style.display = '';
288 }
289
290 function add_time_string_to_date(d, time)
291 {
292 if(typeof(d) != 'object' || !(d instanceof Date))
293 {
294 return false;
295 }
296
297 if (time == 'minute')
298 {
299 d.setSeconds (d.getSeconds() + 60);
300 return true;
301 }
302 if (time == 'hour')
303 {
304 d.setSeconds (d.getSeconds() + 3600);
305 return true;
306 }
307 if (time == 'day')
308 {
309 d.setSeconds (d.getSeconds() + 86400);
310 return true;
311 }
312 if (time == 'week')
313 {
314 d.setSeconds (d.getSeconds() + 604800);
315 return true;
316 }
317 if (time == 'month')
318 {
319 d.setSeconds (d.getSeconds() + 2592000);
320 return true;
321 }
322 if (time == 'quarter')
323 {
324 d.setSeconds (d.getSeconds() + 7776000);
325 return true;
326 }
327 if (time == 'year')
328 {
329 d.setSeconds (d.getSeconds() + 31536000);
330 return true;
331 }
332 return false;
333 }
334
335 function classic_upload (file, time, password, one_time, upload_password)
336 {
337 // Delay time estimation init as we can't have file size
338 upload_time_estimation_init(0);
339
340 var req = new XMLHttpRequest ();
341 req.upload.addEventListener ("progress", upload_progress, false);
342 req.addEventListener ("error", pop_failure, false);
343 req.addEventListener ("abort", pop_failure, false);
344 req.onreadystatechange = function ()
345 {
346 if (req.readyState == 4 && req.status == 200)
347 {
348 var res = req.responseText;
349
350 // if response starts with "Error" then show a failure
351 if (/^Error/.test(res))
352 {
353 pop_failure (res);
354 return;
355 }
356
357 res = res.split ("\n");
358 var expiryDate = '';
359 if (time != 'none')
360 {
361 // convert time (local time + selected expiry date)
362 var localDatetime = new Date();
363 if(!add_time_string_to_date(localDatetime, time))
364 {
365 pop_failure ('Error: Date can not be parsed');
366 return;
367 }
368 expiryDate = localDatetime;
369 }
370
371 show_link (res[0], res[1], res[2], expiryDate);
372 }
373 }
374 req.open ("POST", 'script.php' , true);
375
376 var form = new FormData();
377 form.append ("file", file);
378 if (time)
379 form.append ("time", time);
380 if (password)
381 form.append ("key", password);
382 if (one_time)
383 form.append ("one_time_download", '1');
384 if (upload_password.length > 0)
385 form.append ("upload_password", upload_password);
386
387 req.send (form);
388 }
389
390 function check_html5_file_api ()
391 {
392 return window.File && window.FileReader && window.FileList && window.Blob;
393 }
394
395 var async_global_transfered = 0;
396 var async_global_file;
397 var async_global_ref = '';
398 var async_global_max_size = 0;
399 var async_global_time;
400 var async_global_transfering = 0;
401 var async_global_last_code;
402
403 function async_upload_start (max_size, file, time, password, one_time, upload_password)
404 {
405 async_global_transfered = 0;
406 async_global_file = file;
407 async_global_max_size = max_size;
408 async_global_time = time;
409
410 var req = new XMLHttpRequest ();
411 req.addEventListener ("error", pop_failure, false);
412 req.addEventListener ("abort", pop_failure, false);
413 req.onreadystatechange = function ()
414 {
415 if (req.readyState == 4 && req.status == 200)
416 {
417 var res = req.responseText;
418
419 if (/^Error/.test(res))
420 {
421 pop_failure (res);
422 return;
423 }
424
425 res = res.split ("\n");
426 async_global_ref = res[0];
427 var code = res[1];
428 async_upload_push (code);
429 }
430 }
431 req.open ("POST", 'script.php?init_async' , true);
432
433 var form = new FormData();
434 form.append ("filename", async_global_file.name);
435 form.append ("type", async_global_file.type);
436 if (time)
437 form.append ("time", time);
438 if (password)
439 form.append ("key", password);
440 if (one_time)
441 form.append ("one_time_download", '1');
442 if (upload_password.length > 0)
443 form.append ("upload_password", upload_password);
444
445 // Start time estimation
446 upload_time_estimation_init(async_global_file.size);
447
448 req.send (form);
449 }
450
451 function async_upload_progress (e)
452 {
453 if (e == undefined || e == null || !e.lengthComputable && async_global_file.size != 0)
454 return;
455
456 // Compute percentage
457 var p = Math.round ((e.loaded + async_global_transfered) * 100 / (async_global_file.size));
458 var p_str = ' ';
459 if (p != 100)
460 p_str = p.toString() + '%';
461 // Update estimation speed
462 upload_time_estimation_add(e.loaded + async_global_transfered);
463 // Get speed string
464 var speed_str = upload_time_estimation_speed_string();
465 speed_str = upload_speed_refresh_limiter(speed_str);
466 // Get time string
467 var time_str = chrono_update(upload_time_estimation_time());
468
469 show_upload_progression (p_str, speed_str, time_str);
470 }
471
472 function async_upload_push (code)
473 {
474 async_global_last_code = code;
475 if (async_global_transfered == async_global_file.size)
476 {
477 hide_upload_progression ();
478 async_upload_end (code);
479 return;
480 }
481 var req = new XMLHttpRequest ();
482 req.upload.addEventListener ("progress", async_upload_progress, false);
483 req.addEventListener ("error", pop_failure, false);
484 req.addEventListener ("abort", pop_failure, false);
485 req.onreadystatechange = function ()
486 {
487 if (req.readyState == 4)
488 {
489 if (req.status == 200)
490 {
491 var res = req.responseText;
492
493 if (/^Error/.test(res))
494 {
495 pop_failure (res);
496 return;
497 }
498
499 res = res.split ("\n");
500 var code = res[0]
501 async_global_transfered = async_global_transfering;
502 async_upload_push (code);
503 }
504 else if (req.status == 413) // Request Entity Too Large
505 {
506 // lower async_global_max_size and retry
507 async_global_max_size = parseInt (async_global_max_size * 0.8);
508 async_upload_push (async_global_last_code);
509 }
510 }
511 }
512 req.open ("POST", 'script.php?push_async' , true);
513
514 var start = async_global_transfered;
515 var end = start + async_global_max_size;
516 if (end >= async_global_file.size)
517 end = async_global_file.size;
518 var blob = async_global_file.slice (start, end);
519 async_global_transfering = end;
520
521 var form = new FormData();
522 form.append ("ref", async_global_ref);
523 form.append ("data", blob);
524 form.append ("code", code);
525 req.send (form);
526 }
527
528 function async_upload_end (code)
529 {
530 var req = new XMLHttpRequest ();
531 req.addEventListener ("error", pop_failure, false);
532 req.addEventListener ("abort", pop_failure, false);
533 req.onreadystatechange = function ()
534 {
535 if (req.readyState == 4 && req.status == 200)
536 {
537 var res = req.responseText;
538
539 if (/^Error/.test(res))
540 {
541 pop_failure (res);
542 return;
543 }
544
545 res = res.split ("\n");
546 var expiryDate = '';
547 if (async_global_time != 'none')
548 {
549 // convert time (local time + selected expiry date)
550 var localDatetime = new Date();
551 if(!add_time_string_to_date(localDatetime, async_global_time)) {
552 pop_failure ('Error: Date can not be parsed');
553 return;
554 }
555 expiryDate = localDatetime;
556 }
557
558 show_link (res[0], res[1], res[2], expiryDate);
559 }
560 }
561 req.open ("POST", 'script.php?end_async' , true);
562
563 var form = new FormData();
564 form.append ("ref", async_global_ref);
565 form.append ("code", code);
566 req.send (form);
567 }
568
569 function upload (max_size)
570 {
571 var one_time_checkbox = document.getElementById('one_time_download');
572 var one_time = one_time_checkbox !== null ? one_time_checkbox.checked : false;
573 if (check_html5_file_api ()
574 && document.getElementById('file_select').files[0].size >= max_size)
575 {
576 async_upload_start (
577 max_size,
578 document.getElementById('file_select').files[0],
579 document.getElementById('select_time').value,
580 document.getElementById('input_key').value,
581 one_time,
582 document.getElementById('upload_password').value
583 );
584 }
585 else
586 {
587 classic_upload (
588 document.getElementById('file_select').files[0],
589 document.getElementById('select_time').value,
590 document.getElementById('input_key').value,
591 one_time,
592 document.getElementById('upload_password').value
593 );
594 }
595 }
596
597 var upload_time_estimation_total_size = 42;
598 var upload_time_estimation_transfered_size = 42;
599 var upload_time_estimation_transfered_date = 42;
600 var upload_time_estimation_moving_average_speed = 42;
601
602 function upload_time_estimation_init(total_size)
603 {
604 upload_time_estimation_total_size = total_size;
605 upload_time_estimation_transfered_size = 0;
606 upload_time_estimation_moving_average_speed = 0;
607 var d = new Date();
608 upload_time_estimation_transfered_date = d.getTime();
609 }
610
611 function upload_time_estimation_add(total_transfered_size)
612 {
613 // Let's compute the current speed
614 var d = new Date();
615 var speed = upload_time_estimation_moving_average_speed;
616 if (d.getTime() - upload_time_estimation_transfered_date != 0)
617 speed = (total_transfered_size - upload_time_estimation_transfered_size)
618 / (d.getTime() - upload_time_estimation_transfered_date);
619 // Let's compute moving average speed on 30 values
620 var m = (upload_time_estimation_moving_average_speed * 29 + speed) / 30;
621 // Update global values
622 upload_time_estimation_transfered_size = total_transfered_size;
623 upload_time_estimation_transfered_date = d.getTime();
624 upload_time_estimation_moving_average_speed = m;
625 }
626
627 function upload_time_estimation_speed_string()
628 {
629 // speed ms -> s
630 var s = upload_time_estimation_moving_average_speed * 1000;
631 var res = 0;
632 var scale = '';
633 if (s <= 1000)
634 {
635 res = s.toString();
636 scale = "B/s";
637 }
638 else if (s < 1000000)
639 {
640 res = Math.floor(s/100) / 10;
641 scale = "KB/s";
642 }
643 else
644 {
645 res = Math.floor(s/100000) / 10;
646 scale = "MB/s";
647 }
648 if (res == 0)
649 return '';
650 return res.toString() + ' ' + scale;
651 }
652
653 function milliseconds_to_time_string (milliseconds)
654 {
655 function numberEnding (number) {
656 return (number > 1) ? translate ('PLURAL_ENDING') : '';
657 }
658
659 var temp = Math.floor(milliseconds / 1000);
660 var years = Math.floor(temp / 31536000);
661 if (years) {
662 return years + ' ' + translate ('YEAR') + numberEnding(years);
663 }
664 var days = Math.floor((temp %= 31536000) / 86400);
665 if (days) {
666 return days + ' ' + translate ('DAY') + numberEnding(days);
667 }
668 var hours = Math.floor((temp %= 86400) / 3600);
669 if (hours) {
670 return hours + ' ' + translate ('HOUR') + numberEnding(hours);
671 }
672 var minutes = Math.floor((temp %= 3600) / 60);
673 if (minutes) {
674 return minutes + ' ' + translate ('MINUTE') + numberEnding(minutes);
675 }
676 var seconds = temp % 60;
677 if (seconds) {
678 return seconds + ' ' + translate ('SECOND') + numberEnding(seconds);
679 }
680 return translate ('LESS_1_SEC');
681 }
682
683 function upload_time_estimation_time()
684 {
685 // Estimate remaining time
686 if (upload_time_estimation_moving_average_speed == 0)
687 return 0;
688 return (upload_time_estimation_total_size - upload_time_estimation_transfered_size)
689 / upload_time_estimation_moving_average_speed;
690 }
691
692 var chrono_last_update = 0;
693 var chrono_time_ms = 0;
694 var chrono_time_ms_last_update = 0;
695 function chrono_update(time_ms)
696 {
697 var d = new Date();
698 var chrono = 0;
699 // Don't update too often
700 if (d.getTime() - chrono_last_update < 3000 &&
701 chrono_time_ms_last_update > 0)
702 chrono = chrono_time_ms;
703 else
704 {
705 chrono_last_update = d.getTime();
706 chrono_time_ms = time_ms;
707 chrono = time_ms;
708 chrono_time_ms_last_update = d.getTime();
709 }
710
711 // Adjust chrono for smooth estimation
712 chrono = chrono - (d.getTime() - chrono_time_ms_last_update);
713
714 // Let's update chronometer
715 var time_str = '';
716 if (chrono > 0)
717 time_str = milliseconds_to_time_string (chrono);
718 return time_str;
719 }
720
721 var upload_speed_refresh_limiter_last_update = 0;
722 var upload_speed_refresh_limiter_last_value = '';
723 function upload_speed_refresh_limiter(speed_str)
724 {
725 var d = new Date();
726 if (d.getTime() - upload_speed_refresh_limiter_last_update > 1500)
727 {
728 upload_speed_refresh_limiter_last_value = speed_str;
729 upload_speed_refresh_limiter_last_update = d.getTime();
730 }
731 return upload_speed_refresh_limiter_last_value;
732 }
733
734 // document.ready()
735 document.addEventListener('DOMContentLoaded', function(event) {
736 // Search for all datetime fields and convert the time to local timezone
737 convertAllDatetimeFields();
738 });
739
740 // Add copy event listeners
741 function copyLinkToClipboard(link_id) {
742 var focus = document.activeElement;
743 var e = document.getElementById(link_id);
744
745 var tmp = document.createElement("textarea");
746 document.body.appendChild(tmp);
747 tmp.textContent = e.href;
748 tmp.focus();
749 tmp.setSelectionRange(0, tmp.value.length);
750 document.execCommand("copy");
751 document.body.removeChild(tmp);
752
753 focus.focus();
754 }
755
756 function addCopyListener(button_id, link_id) {
757 if(document.getElementById(button_id)){
758 document.getElementById(button_id)
759 .addEventListener("click", function() {
760 copyLinkToClipboard(link_id);});
761 }
762 }
763 // @license-end

patrick-canterino.de