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>
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.
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.
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/>.
21 function template_js_preview_link() {
23 if (!!document
.getElementById('preview_link'))
25 document
.getElementById('upload_finished_preview').style
.display
= 'none';
26 var preview_link_href
= 'f.php?h=' + reference +
'&p=1';
27 if (crypt_key
.length
> 0)
29 preview_link_href +
= '&k=' + crypt_key
;
32 // Test if content can be previewed
33 type
= document
.getElementById('file_select').files
[0].type
;
34 if ((type
.startsWith('image/')
35 || type
.startsWith('audio')
36 || type
.startsWith('text/plain')
37 || type
.startsWith('video/'))
38 && !type
.includes('image/svg+xml'))
40 document
.getElementById('preview_link').href
= preview_link_href
;
41 document
.getElementById('preview_link_text').innerHTML
= web_root + preview_link_href
;
42 document
.getElementById('upload_finished_preview').style
.display
= '';
47 function template_js_download_page() {
50 var download_link_href
= 'f.php?h=' + reference
;
51 if (crypt_key
.length
> 0)
53 download_link_href +
= '&k=' + crypt_key
;
55 if (!!document
.getElementById('upload_finished_download_page'))
57 document
.getElementById('upload_link').href
= download_link_href
;
58 document
.getElementById('upload_link_text').innerHTML
= web_root + download_link_href
;
62 function template_js_email_link() {
65 var b
= encodeURIComponent("<?php echo t("DL
"); ?> \"" + filename +
"\":") +
"%0D" +
"%0A";
66 b +
= encodeURIComponent(web_root + download_link_href
) +
"%0D" +
"%0A";
67 if (false == isEmpty(date
))
69 b +
= "%0D" +
"%0A" +
encodeURIComponent("<?php echo t("VALID_UNTIL
"); ?>: " + date
.format('YYYY-MM-DD hh:mm (GMT O)')) +
"%0D" +
"%0A";
70 document
.getElementById('upload_link_email').href
= "mailto:?body=" + b +
"&subject=" +
encodeURIComponent(filename
);
74 function template_js_delete_link() {
77 var delete_link_href
= 'f.php?h=' + reference +
'&d=' + delete_code
;
78 document
.getElementById('delete_link').href
= delete_link_href
;
79 document
.getElementById('delete_link_text').innerHTML
= web_root + delete_link_href
;
82 function template_js_direct_download() {
84 // Direct download link
85 var direct_download_link_href
= 'f.php?h=' + reference +
'&d=1';
86 if (crypt_key
.length
> 0)
88 direct_download_link_href +
= '&k=' + crypt_key
;
90 document
.getElementById('direct_link').href
= direct_download_link_href
;
91 document
.getElementById('direct_link_text').innerHTML
= web_root + direct_download_link_href
;
94 function template_js_date_function() {
99 document
.getElementById('date').style
.display
= 'none';
102 document
.getElementById('date').innerHTML
=
103 '<span class="datetime"'
105 +
dateToUtcString(date
) +
' (GMT"'
107 +
dateToUtcString(date
) +
' (GMT)">'
108 + date
.format('YYYY-MM-DD hh:mm (GMT O)')
110 document
.getElementById('date').style
.display
= '';
118 header('Content-Type: text/javascript');
119 define('JIRAFEAU_ROOT', dirname(__FILE__
) . '/../');
121 require(JIRAFEAU_ROOT
. 'lib/settings.php');
122 require(JIRAFEAU_ROOT
. 'lib/functions.php');
123 require(JIRAFEAU_ROOT
. 'lib/lang.php');
126 // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later
127 var web_root
= "<?php echo $cfg['web_root']; ?>";
129 var lang_array
= <?php
echo json_lang_generator(null); ?
>;
130 var lang_array_fallback
= <?php
echo json_lang_generator("en"); ?
>;
132 function translate (expr
) {
133 if (lang_array
.hasOwnProperty(expr
)) {
134 var e
= lang_array
[expr
];
138 if (lang_array_fallback
.hasOwnProperty(expr
)) {
139 var e
= lang_array_fallback
[expr
];
143 return "FIXME: " + expr
;
146 function isEmpty(str
) {
147 return (!str ||
0 === str
.length
);
150 // Extend date object with format method
151 Date
.prototype
.format
= function(format
) {
152 format
= format ||
'YYYY-MM-DD hh:mm';
154 var zeropad
= function(number
, length
) {
155 number
= number
.toString();
156 length
= length ||
2;
157 while(number
.length
< length
)
158 number
= '0' + number
;
162 YYYY
: this
.getFullYear(),
163 MM
: zeropad(this
.getMonth() +
1),
164 DD
: zeropad(this
.getDate()),
165 hh
: zeropad(this
.getHours()),
166 mm
: zeropad(this
.getMinutes()),
168 localDate
= new Date
;
169 sign
= (localDate
.getTimezoneOffset() > 0) ?
'-' : '+';
170 offset
= Math
.abs(localDate
.getTimezoneOffset());
171 hours
= zeropad(Math
.floor(offset
/ 60));
172 minutes
= zeropad(offset %
60);
173 return sign + hours +
":" + minutes
;
176 pattern
= '(' +
Object.keys(formats
).join(')|(') +
')';
178 return format
.replace(new RegExp(pattern
, 'g'), function(match
) {
179 return formats
[match
];
183 function dateFromUtcString(datestring
) {
184 // matches »YYYY-MM-DD hh:mm«
185 var m
= datestring
.match(/(\d+
)-(\d+
)-(\d+
)\s+
(\d+
):(\d+
)/);
186 return new Date(Date
.UTC(+m
[1], +m
[2] - 1, +m
[3], +m
[4], +m
[5], 0));
189 function dateFromUtcTimestamp(datetimestamp
) {
190 return new Date(parseInt(datetimestamp
) * 1000)
193 function dateToUtcString(datelocal
) {
195 datelocal
.getUTCFullYear(),
196 datelocal
.getUTCMonth(),
197 datelocal
.getUTCDate(),
198 datelocal
.getUTCHours(),
199 datelocal
.getUTCMinutes(),
200 datelocal
.getUTCSeconds()
204 function dateToUtcTimestamp(datelocal
) {
206 datelocal
.getUTCFullYear(),
207 datelocal
.getUTCMonth(),
208 datelocal
.getUTCDate(),
209 datelocal
.getUTCHours(),
210 datelocal
.getUTCMinutes(),
211 datelocal
.getUTCSeconds()
215 function convertAllDatetimeFields() {
216 datefields
= document
.getElementsByClassName('datetime')
217 for(var i
=0; i
<datefields
.length
; i++
) {
218 dateUTC
= datefields
[i
].getAttribute('data-datetime');
219 datefields
[i
].setAttribute('title', dateUTC +
' (GMT)');
220 datefields
[i
].innerHTML
= dateFromUtcString(dateUTC
).format('YYYY-MM-DD hh:mm (GMT O)');
224 // evil copy and paste from show_link - TODO refactor show link
225 function show_link_from_php (file_name
,file_type
, reference
, delete_code
, crypt_key
, date
)
227 <?php
template_js_download_page(); ?
>
230 var filename
= file_name
;
231 <?php
template_js_email_link(); ?
>
232 <?php
template_js_delete_link(); ?
>
233 <?php
template_js_date_function(); ?
>
234 var type
= file_type
;
235 <?php
template_js_direct_download();?
>
240 function show_link (reference
, delete_code
, crypt_key
, date
)
243 document
.getElementById('uploading').style
.display
= 'none';
244 document
.getElementById('upload').style
.display
= 'none';
245 document
.getElementById('upload_finished').style
.display
= '';
246 document
.title
= "100% - <?php echo empty($cfg['title']) ? 'Jirafeau' : $cfg['title']; ?>";
248 <?php
template_js_download_page(); ?
>
250 var filename
= document
.getElementById('file_select').files
[0].name
;
252 <?php
template_js_email_link(); ?
>
254 <?php
template_js_delete_link(); ?
>
255 <?php
template_js_date_function(); ?
>
258 // Preview link (if allowed)
260 var type
= document
.getElementById('file_select').files
[0].type
;
261 <?php
template_js_preview_link(); ?
>
263 <?php
template_js_direct_download();?
>
266 // Hide preview and direct download link if password is set
267 if (document
.getElementById('input_key').value
.length
> 0)
269 if (!!document
.getElementById('preview_link'))
270 document
.getElementById('upload_finished_preview').style
.display
= 'none';
271 document
.getElementById('upload_direct_download').style
.display
= 'none';
275 function show_upload_progression (percentage
, speed
, time_left
)
277 document
.getElementById('uploaded_percentage').innerHTML
= percentage
;
278 document
.getElementById('uploaded_speed').innerHTML
= speed
;
279 document
.getElementById('uploaded_time').innerHTML
= time_left
;
280 document
.title
= percentage +
" - <?php echo empty($cfg['title']) ? 'Jirafeau' : $cfg['title']; ?>";
283 function hide_upload_progression ()
285 document
.getElementById('uploaded_percentage').style
.display
= 'none';
286 document
.getElementById('uploaded_speed').style
.display
= 'none';
287 document
.getElementById('uploaded_time').style
.display
= 'none';
288 document
.title
= "<?php echo empty($cfg['title']) ? 'Jirafeau' : $cfg['title']; ?>";
291 function upload_progress (e
)
293 if (e
== undefined || e
== null ||
!e
.lengthComputable
)
296 // Init time estimation if needed
297 if (upload_time_estimation_total_size
== 0)
298 upload_time_estimation_total_size
= e
.total
;
300 // Compute percentage
301 var p
= Math
.round (e
.loaded
* 100 / e
.total
);
304 p_str
= p
.toString() +
'%';
305 // Update estimation speed
306 upload_time_estimation_add(e
.loaded
);
308 var speed_str
= upload_time_estimation_speed_string();
309 speed_str
= upload_speed_refresh_limiter(speed_str
);
311 var time_str
= chrono_update(upload_time_estimation_time());
313 show_upload_progression (p_str
, speed_str
, time_str
);
316 function control_selected_file_size(max_size
, error_str
)
318 f_size
= document
.getElementById('file_select').files
[0].size
;
319 if (max_size
> 0 && f_size
> max_size
* 1024 * 1024)
321 pop_failure(error_str
);
322 document
.getElementById('send').style
.display
= 'none';
326 // add class to restyle upload form in next step
327 document
.getElementById('upload').setAttribute('class', 'file-selected');
329 document
.getElementById('options').style
.display
= 'block';
330 document
.getElementById('send').style
.display
= 'block';
331 document
.getElementById('error_pop').style
.display
= 'none';
332 document
.getElementById('send').focus();
336 function XHRErrorHandler(e
)
338 var text
= "${e.type}: ${e.loaded} bytes transferred"
342 function pop_failure (e
)
344 var text
= "<p>An error occured";
345 if (typeof e
!== 'undefined')
348 document
.getElementById('error_pop').innerHTML
= e
;
350 document
.getElementById('uploading').style
.display
= 'none';
351 document
.getElementById('error_pop').style
.display
= '';
352 document
.getElementById('upload').style
.display
= '';
353 document
.getElementById('send').style
.display
= '';
356 function add_time_string_to_date(d
, time
)
358 if(typeof(d
) != 'object' ||
!(d
instanceof Date
))
363 if (time
== 'minute')
365 d
.setSeconds (d
.getSeconds() +
60);
370 d
.setSeconds (d
.getSeconds() +
3600);
375 d
.setSeconds (d
.getSeconds() +
86400);
380 d
.setSeconds (d
.getSeconds() +
604800);
383 if (time
== 'fortnight')
385 d
.setSeconds (d
.getSeconds() +
1209600);
390 d
.setSeconds (d
.getSeconds() +
2592000);
393 if (time
== 'quarter')
395 d
.setSeconds (d
.getSeconds() +
7776000);
400 d
.setSeconds (d
.getSeconds() +
31536000);
406 function classic_upload (file
, time
, password
, one_time
)
408 // Delay time estimation init as we can't have file size
409 upload_time_estimation_init(0);
411 var req
= new XMLHttpRequest ();
412 req
.upload
.addEventListener ("progress", upload_progress
, false);
413 req
.addEventListener ("error", XHRErrorHandler
, false);
414 req
.addEventListener ("abort", XHRErrorHandler
, false);
415 req
.onreadystatechange
= function ()
417 if (req
.readyState
== 4 && req
.status
== 200)
419 var res
= req
.responseText
;
421 // if response starts with "Error" then show a failure
422 if (/^Error
/.test(res
))
428 res
= res
.split ("\n");
432 // convert time (local time + selected expiry date)
433 var localDatetime
= new Date();
434 if(!add_time_string_to_date(localDatetime
, time
))
436 pop_failure ('Error: Date can not be parsed');
439 expiryDate
= localDatetime
;
442 show_link (res
[0], res
[1], res
[2], expiryDate
);
446 pop_failure ("<?php echo t("ERR_OCC
"); ?>");
449 req
.open ("POST", 'script.php' , true);
451 var form
= new FormData();
452 form
.append ("file", file
);
454 form
.append ("time", time
);
456 form
.append ("key", password
);
458 form
.append ("one_time_download", '1');
462 function check_html5_file_api ()
464 return window
.File
&& window
.FileReader
&& window
.FileList
&& window
.Blob
;
467 var async_global_transfered
= 0;
468 var async_global_file
;
469 var async_global_ref
= '';
470 var async_global_max_size
= 0;
471 var async_global_time
;
472 var async_global_transfering
= 0;
473 var async_global_last_code
;
475 function async_upload_start (max_size
, file
, time
, password
, one_time
)
477 async_global_transfered
= 0;
478 async_global_file
= file
;
479 async_global_max_size
= max_size
;
480 async_global_time
= time
;
482 var req
= new XMLHttpRequest ();
483 req
.addEventListener ("error", XHRErrorHandler
, false);
484 req
.addEventListener ("abort", XHRErrorHandler
, false);
485 req
.onreadystatechange
= function ()
487 if (req
.readyState
== 4 && req
.status
== 200)
489 var res
= req
.responseText
;
491 if (/^Error
/.test(res
))
497 res
= res
.split ("\n");
498 async_global_ref
= res
[0];
500 async_upload_push (code
);
503 req
.open ("POST", 'script.php?init_async' , true);
505 var form
= new FormData();
506 form
.append ("filename", async_global_file
.name
);
507 form
.append ("type", async_global_file
.type
);
509 form
.append ("time", time
);
511 form
.append ("key", password
);
513 form
.append ("one_time_download", '1');
515 // Start time estimation
516 upload_time_estimation_init(async_global_file
.size
);
521 function async_upload_progress (e
)
523 if (e
== undefined || e
== null ||
!e
.lengthComputable
&& async_global_file
.size
!= 0)
526 // Compute percentage
527 var p
= Math
.round ((e
.loaded + async_global_transfered
) * 100 / (async_global_file
.size
));
530 p_str
= p
.toString() +
'%';
531 // Update estimation speed
532 upload_time_estimation_add(e
.loaded + async_global_transfered
);
534 var speed_str
= upload_time_estimation_speed_string();
535 speed_str
= upload_speed_refresh_limiter(speed_str
);
537 var time_str
= chrono_update(upload_time_estimation_time());
539 show_upload_progression (p_str
, speed_str
, time_str
);
542 function async_upload_push (code
)
544 async_global_last_code
= code
;
545 if (async_global_transfered
== async_global_file
.size
)
547 hide_upload_progression ();
548 async_upload_end (code
);
551 var req
= new XMLHttpRequest ();
552 req
.upload
.addEventListener ("progress", async_upload_progress
, false);
553 req
.addEventListener ("error", XHRErrorHandler
, false);
554 req
.addEventListener ("abort", XHRErrorHandler
, false);
555 req
.onreadystatechange
= function ()
557 if (req
.readyState
== 4)
559 if (req
.status
== 200)
561 var res
= req
.responseText
;
563 // This error may be triggered when Jirafeau does not receive any file in POST.
564 // This may be due to bad php configuration where post_max_size is too low
565 // comparing to upload_max_filesize. Let's retry with lower file size.
566 if (res
=== "Error 23")
568 async_global_max_size
= Math
.max(1, async_global_max_size
- 500);
569 async_upload_push (async_global_last_code
);
572 else if (/^Error
/.test(res
))
578 res
= res
.split ("\n");
580 async_global_transfered
= async_global_transfering
;
581 async_upload_push (code
);
586 // lower async_global_max_size and retry
587 // This can occurs in several cases:
588 // - Request Entity Too Large (413) due to server bad configuration relative to PHP configuration
589 // - Server Error (500) which can happen when PHP's `max_execution_time` is too low comparared to sent size
590 async_global_max_size
= Math
.max(1, parseInt (async_global_max_size
* 0.5));
591 async_upload_push (async_global_last_code
);
596 req
.open ("POST", 'script.php?push_async' , true);
598 var start
= async_global_transfered
;
599 var end
= start + async_global_max_size
;
600 if (end
>= async_global_file
.size
)
601 end
= async_global_file
.size
;
602 var blob
= async_global_file
.slice (start
, end
);
603 async_global_transfering
= end
;
605 var form
= new FormData();
606 form
.append ("ref", async_global_ref
);
607 form
.append ("data", blob
);
608 form
.append ("code", code
);
612 function async_upload_end (code
)
614 var req
= new XMLHttpRequest ();
615 req
.addEventListener ("error", XHRErrorHandler
, false);
616 req
.addEventListener ("abort", XHRErrorHandler
, false);
617 req
.onreadystatechange
= function ()
619 if (req
.readyState
== 4 && req
.status
== 200)
621 var res
= req
.responseText
;
623 if (/^Error
/.test(res
))
629 res
= res
.split ("\n");
631 if (async_global_time
!= 'none')
633 // convert time (local time + selected expiry date)
634 var localDatetime
= new Date();
635 if(!add_time_string_to_date(localDatetime
, async_global_time
)) {
636 pop_failure ('Error: Date can not be parsed');
639 expiryDate
= localDatetime
;
642 show_link (res
[0], res
[1], res
[2], expiryDate
);
645 req
.open ("POST", 'script.php?end_async' , true);
647 var form
= new FormData();
648 form
.append ("ref", async_global_ref
);
649 form
.append ("code", code
);
653 function upload (max_chunk_size
)
655 var one_time_checkbox
= document
.getElementById('one_time_download');
656 var one_time
= one_time_checkbox
!== null ? one_time_checkbox
.checked
: false;
657 if (check_html5_file_api ())
661 document
.getElementById('file_select').files
[0],
662 document
.getElementById('select_time').value
,
663 document
.getElementById('input_key').value
,
670 document
.getElementById('file_select').files
[0],
671 document
.getElementById('select_time').value
,
672 document
.getElementById('input_key').value
,
678 var upload_time_estimation_total_size
= 42;
679 var upload_time_estimation_transfered_size
= 42;
680 var upload_time_estimation_transfered_date
= 42;
681 var upload_time_estimation_moving_average_speed
= 42;
683 function upload_time_estimation_init(total_size
)
685 upload_time_estimation_total_size
= total_size
;
686 upload_time_estimation_transfered_size
= 0;
687 upload_time_estimation_moving_average_speed
= 0;
689 upload_time_estimation_transfered_date
= d
.getTime();
692 function upload_time_estimation_add(total_transfered_size
)
694 // Let's compute the current speed
696 var speed
= upload_time_estimation_moving_average_speed
;
697 if (d
.getTime() - upload_time_estimation_transfered_date
!= 0) {
698 speed
= (total_transfered_size
- upload_time_estimation_transfered_size
)
699 / (d
.getTime() - upload_time_estimation_transfered_date
);
700 speed
= Math
.max(0, speed
);
702 // Let's compute moving average speed on 30 values
703 var m
= (upload_time_estimation_moving_average_speed
* 29 + speed
) / 30;
704 // Update global values
705 upload_time_estimation_transfered_size
= total_transfered_size
;
706 upload_time_estimation_transfered_date
= d
.getTime();
707 upload_time_estimation_moving_average_speed
= m
;
710 function upload_time_estimation_speed_string()
713 var s
= upload_time_estimation_moving_average_speed
* 1000;
721 else if (s
< 1000000)
723 res
= Math
.floor(s
/100) / 10;
728 res
= Math
.floor(s
/100000) / 10;
733 return res
.toString() +
' ' + scale
;
736 function milliseconds_to_time_string (milliseconds
)
738 function numberEnding (number
) {
739 return (number
> 1) ?
translate ('PLURAL_ENDING') : '';
742 var temp
= Math
.floor(milliseconds
/ 1000);
743 var years
= Math
.floor(temp
/ 31536000);
745 return years +
' ' +
translate ('YEAR') +
numberEnding(years
);
747 var days
= Math
.floor((temp %
= 31536000) / 86400);
749 return days +
' ' +
translate ('DAY') +
numberEnding(days
);
751 var hours
= Math
.floor((temp %
= 86400) / 3600);
753 return hours +
' ' +
translate ('HOUR') +
numberEnding(hours
);
755 var minutes
= Math
.floor((temp %
= 3600) / 60);
757 return minutes +
' ' +
translate ('MINUTE') +
numberEnding(minutes
);
759 var seconds
= temp %
60;
761 return seconds +
' ' +
translate ('SECOND') +
numberEnding(seconds
);
763 return translate ('LESS_1_SEC');
766 function upload_time_estimation_time()
768 // Estimate remaining time
769 if (upload_time_estimation_moving_average_speed
<= 0)
771 return (upload_time_estimation_total_size
- upload_time_estimation_transfered_size
)
772 / upload_time_estimation_moving_average_speed
;
775 var chrono_last_update
= 0;
776 var chrono_time_ms
= 0;
777 var chrono_time_ms_last_update
= 0;
778 function chrono_update(time_ms
)
782 // Don't update too often
783 if (d
.getTime() - chrono_last_update
< 3000 &&
784 chrono_time_ms_last_update
> 0)
785 chrono
= chrono_time_ms
;
788 chrono_last_update
= d
.getTime();
789 chrono_time_ms
= time_ms
;
791 chrono_time_ms_last_update
= d
.getTime();
794 // Adjust chrono for smooth estimation
795 chrono
= chrono
- (d
.getTime() - chrono_time_ms_last_update
);
797 // Let's update chronometer
800 time_str
= milliseconds_to_time_string (chrono
);
804 var upload_speed_refresh_limiter_last_update
= 0;
805 var upload_speed_refresh_limiter_last_value
= '';
806 function upload_speed_refresh_limiter(speed_str
)
809 if (d
.getTime() - upload_speed_refresh_limiter_last_update
> 1500)
811 upload_speed_refresh_limiter_last_value
= speed_str
;
812 upload_speed_refresh_limiter_last_update
= d
.getTime();
814 return upload_speed_refresh_limiter_last_value
;
818 document
.addEventListener('DOMContentLoaded', function(event
) {
819 // Search for all datetime fields and convert the time to local timezone
820 convertAllDatetimeFields();
823 // Add copy event listeners
824 function copyLinkToClipboard(link_id
) {
825 var focus
= document
.activeElement
;
826 var e
= document
.getElementById(link_id
);
828 var tmp
= document
.createElement("textarea");
829 document
.body
.appendChild(tmp
);
830 tmp
.textContent
= e
.href
;
832 tmp
.setSelectionRange(0, tmp
.value
.length
);
833 document
.execCommand("copy");
834 document
.body
.removeChild(tmp
);
839 function addCopyListener(button_id
, link_id
) {
840 if(document
.getElementById(button_id
)){
841 document
.getElementById(button_id
)
842 .addEventListener("click", function() {
843 copyLinkToClipboard(link_id
);});
847 function copyTextToClipboard(text_id
){
848 var copyText
= document
.getElementById(text_id
);
850 copyText
.setSelectionRange(0, 99999);
851 navigator
.clipboard
.writeText(copyText
.value
);
854 function addTextCopyListener(button_id
, text_id
) {
855 if(document
.getElementById(button_id
)){
856 document
.getElementById(button_id
)
857 .addEventListener("click", function() {
858 copyTextToClipboard(text_id
);});
862 function set_dark_mode() {
863 let steel_sheet
= "<?php echo 'media/' . $cfg['dark_style'] . '/style.css.php'; ?>";
864 let shortcut_icon
= "<?php echo 'media/' . $cfg['dark_style'] . '/favicon.ico'; ?>";
865 document
.getElementById('stylesheet').href
= steel_sheet
;
866 document
.getElementById('shortcut_icon').href
= shortcut_icon
;
869 function set_light_mode() {
870 let steel_sheet
= "<?php echo 'media/' . $cfg['style'] . '/style.css.php'; ?>";
871 let shortcut_icon
= "<?php echo 'media/' . $cfg['style'] . '/favicon.ico'; ?>";
872 document
.getElementById('stylesheet').href
= steel_sheet
;
873 document
.getElementById('shortcut_icon').href
= shortcut_icon
;
876 function color_scheme_preferences() {
878 let dark_mode_steel_sheet
= "<?php echo 'media/' . $cfg['dark_style'] . '/style.css.php'; ?>"
879 if (window
.matchMedia
&& window
.matchMedia('(prefers-color-scheme: dark)').matches
) {
885 // When user change its preference
886 window
.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', lightMode
=> {
887 lightMode
.matches ?
set_dark_mode() : set_light_mode();