-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathassets_js_bitrequest_settings.js
3715 lines (3584 loc) · 146 KB
/
assets_js_bitrequest_settings.js
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
$(document).ready(function() {
// ** Settings **
// Account name
editaccount();
submitaccount();
// Contact form
edit_contactform_trigger();
//edit_contactform;
type_contactform();
submit_contactform();
// Standard fiat currency
editcurrency();
toggle_defaultcurrency();
autocompletecurrency();
submitcurrency();
// Language
editlanguage();
submitlang();
// CSV Export
csvexport_trigger();
submit_csvexport();
//complile_csv
//render_csv
share_csv();
//check_csvexport
submit_csvdownload();
// Bip32 passphrase
trigger_bip32();
hide_seed_panel_trigger();
//hide_seed_panel
// Pincode
editpin();
locktime();
submit_locktime();
// Back up
backupdatabasetrigger();
//backupdatabase
sbu_switch();
sharebu();
//check_systembu
//stripb64
//systembu_expired
restore_systembu();
backupcd();
//complilebackup
//complilefilename
submitbackup();
// Restore backup
restorefrombackup();
//trigger_restore
restorebackup();
submitrestore();
//restore
//check_backup
submit_GD_restore();
//scan_restore
//restore_algo
//restore_callback
//s_decode
//pin_dialog
submit_pin_dialog();
//restore_cb_init_addresses
//restore_callback_file
//restore_callback_gd
//dphrase_dialog
submit_dphrase();
//keep_current_seed
//restore_bu_seed
//bu_oldseed
compare_seeds();
//cs_callback
//compare_seeds_callback
//restorestorage
// Url shortener
urlshortener();
togglebl();
pick_urlshortener_select();
submit_urlshortener_select();
// Cryptocurrency price api
editccapi();
pickcmcapiselect();
submitccapi();
// Fiat price api
editfiatxrapi();
pickfiatxrapiselect();
submitfiatxrapi();
// API keys
apikeys();
api_input_change();
submitapi();
//checkapikey
//json_check_apikey
//api_fail
//update_api_attr
//complement_apisettings
// API Proxy
trigger_proxy_dialog();
pick_api_proxy();
//test_append_proxy
//proxy_option_li
submit_proxy();
hide_custom_proxy_field();
//test_custom_proxy
remove_proxy();
//complete_url
//c_proxy
// PERMISSIONS
permissions();
submit_permissions();
// TEAM INVITE
team_invite_trigger()
//team_invite
//complile_teaminvite
//adjust_object
share_teaminvite()
//check_teaminvite
install_teaminvite_trigger()
//install_teaminvite
//isteaminvite
check_useragent();
});
// ** Settings **
// Account name
// Handles the click event for editing account settings
function editaccount() {
$(document).on("click", "#accountsettings", function() {
const ddat = [{
"div": {
"class": "popform",
"content": [{
"input": {
"attr": {
"type": "text",
"value": $(this).data("selected")
}
}
},
{
"input": {
"class": "submit",
"attr": {
"type": "submit",
"value": translate("okbttn")
}
}
}
]
}
}],
content = template_dialog({
"id": "accountformbox",
"icon": "icon-user",
"title": translate("accountsettings"),
"elements": ddat
});
popdialog(content, "triggersubmit");
})
}
// Handles the submission of account settings
function submitaccount() {
$(document).on("click", "#accountformbox input.submit", function(e) {
e.preventDefault();
const thisinput = $(this).prev("input"),
thisvalue = thisinput.val();
if (thisvalue.length < 1) {
popnotify("error", translate("nameisrequired"));
thisinput.focus();
return false;
}
set_setting("accountsettings", {
"selected": thisvalue
}, thisvalue);
canceldialog();
notify(translate("datasaved"));
savesettings();
})
}
// Standard fiat currency
// Handles the click event for editing currency settings
function editcurrency() {
$(document).on("click", "#currencysettings", function() {
const currencysettings = $("#currencysettings"),
switchmode = currencysettings.data("default"),
currency = currencysettings.data("selected"),
symbolstringarray = br_get_local("symbols", true);
let symbollist = "";
$.each(symbolstringarray, function(key, value) {
if (key !== "BTC") { // remove from list
symbollist += "<span data-id='1' data-pe='none'>" + key + " | " + value + "</span>";
}
});
const ddat = [{
"div": {
"class": "popform validated",
"content": [{
"div": {
"class": "selectbox",
"content": [{
"input": {
"attr": {
"type": "text",
"value": currency,
"placeholder": "Pick currency"
},
"close": true
},
"div": {
"class": "selectarrows icon-menu2",
"attr": {
"data-pe": "none"
}
}
},
{
"div": {
"class": "options",
"content": symbollist
}
}
]
}
},
{
"div": {
"id": "toggle_defaultcurrency",
"class": "clearfix",
"content": "<h3>" + translate("setasdefault") + switchpanel(switchmode, " global") + "</h3>"
}
},
{
"input": {
"class": "submit",
"attr": {
"type": "submit",
"value": translate("okbttn")
}
}
}
]
}
}],
content = template_dialog({
"id": "currencyformbox",
"icon": "icon-dollar",
"title": translate("entercurrency"),
"elements": ddat
});
popdialog(content, "triggersubmit");
})
}
// Handles the toggle event for setting default currency
function toggle_defaultcurrency() {
$(document).on("mouseup", "#toggle_defaultcurrency .switchpanel", function(e) {
$(this).addClass("dc_changed");
})
}
// Handles autocomplete functionality for currency input
function autocompletecurrency() {
$(document).on("input", "#currencyformbox input:first", function() {
const thisinput = $(this),
thisform = thisinput.closest(".popform"),
thisvalue = thisinput.val().toUpperCase(),
options = thisform.find(".options");
thisform.removeClass("validated");
$("#currencyformbox .options > span").each(function() {
const thisoption = $(this),
thistext = thisoption.text(),
currencysymbol = thistext.split(" | ")[0];
thisoption.removeClass("show");
if (currencysymbol === thisvalue) {
thisform.addClass("validated");
thisinput.val(thistext)[0].setSelectionRange(0, 999);
} else if (currencysymbol.match("^" + thisvalue)) {
thisoption.addClass("show");
}
});
})
}
// Handles the submission of currency settings
function submitcurrency() {
$(document).on("click", "#currencyformbox input.submit", function(e) {
e.preventDefault();
const localcurrency = get_setting("currencysettings", "currencysymbol"),
thisform = $(this).closest(".popform"),
thisinput = thisform.find("input:first"),
thisinputvalue = thisinput.val();
thisform.removeClass("validated");
$("#currencyformbox .options > span").each(function() {
if (thisinputvalue == $(this).text()) {
thisform.addClass("validated");
}
});
if (thisform.hasClass("validated")) {
const defaultcurrency_switch = $("#toggle_defaultcurrency .switchpanel"),
switchchange = defaultcurrency_switch.hasClass("dc_changed"),
values = thisinputvalue.split(" | "),
currencysymbol = values[0],
currency = values[1],
currencysymbollc = currencysymbol.toLowerCase();
if (currencysymbollc === localcurrency && !switchchange) {
canceldialog();
return false;
}
const dc_output = defaultcurrency_switch.hasClass("true");
set_setting("currencysettings", {
"currencysymbol": currencysymbollc,
"selected": thisinputvalue,
"default": dc_output
}, thisinputvalue);
canceldialog();
notify(translate("currencysaved"));
savesettings();
return false;
}
popnotify("error", translate("currencynotsupported", {
"currency": thisinputvalue.toUpperCase()
}));
thisinput.focus();
return false;
});
}
// Language
// Handles the click event for editing language settings
function editlanguage() {
$(document).on("click", "#langsettings", function() {
const translation = translate("obj"),
current_lang = q_obj(translation, langcode + ".lang"),
current_flag = q_obj(translation, langcode + ".flag"),
cf_string = current_flag ? current_flag + " " : "",
current_val = cf_string + current_lang + " (" + langcode + ")";
let langlist = "";
$.each(translation, function(key, value) {
const cflag = value.flag ? value.flag + " " : ""
langlist += "<span>" + cflag + value.lang + " (" + key + ")</span>";
});
const ddat = [{
"div": {
"class": "popform validated",
"attr": {
"data-currentlang": langcode
},
"content": [{
"div": {
"class": "selectbox",
"content": [{
"input": {
"attr": {
"type": "text",
"value": current_val,
"placeholder": "Pick language"
},
"close": true
},
"div": {
"class": "selectarrows icon-menu2",
"attr": {
"data-pe": "none"
}
}
},
{
"div": {
"class": "options",
"content": langlist
}
}
]
}
},
{
"input": {
"class": "submit",
"attr": {
"type": "submit",
"value": translate("okbttn")
}
}
}
]
}
}],
content = template_dialog({
"id": "langformbox",
"icon": "icon-dollar",
"title": translate("chooselanguage"),
"elements": ddat
});
popdialog(content, "triggersubmit");
})
}
// Handles the submission of language settings
function submitlang() {
$(document).on("click", "#langformbox input.submit", function(e) {
e.preventDefault();
const thisform = $(this).closest(".popform"),
currentlang = thisform.attr("data-currentlang"),
thisinput = thisform.find("input"),
thisvalue = thisinput.val(),
lc2 = thisvalue.match(/\(([^)]+)\)/)[1];
if (lc2 === currentlang) {
canceldialog();
return
}
set_setting("langsettings", {
"selected": lc2
}, thisvalue);
savesettings();
glob_const.w_loc.href = glob_const.w_loc.pathname + "?p=settings";
return false;
})
}
// SECURITY //
// Pincode
// Handles the click event for editing PIN settings
function editpin() {
$(document).on("click", "#pinsettings", function() {
if (haspin(true) === true) {
const content = pinpanel(" pinwall reset", null, true);
showoptions(content, "pin");
return
}
const content = pinpanel();
showoptions(content, "pin");
})
}
// Handles the click event for setting lock time
function locktime() {
$(document).on("click", "#locktime, #lock_time", function() {
const locktime = get_setting("pinsettings", "locktime"),
locktimeOptions = [{
"value": "0",
"text": "0 " + translate("minutes")
},
{
"value": "60000",
"text": "1 " + translate("minute")
},
{
"value": "300000",
"text": "5 " + translate("minutes")
},
{
"value": "600000",
"text": "10 " + translate("minutes")
},
{
"value": "900000",
"text": "15 " + translate("minutes")
},
{
"value": "1800000",
"text": "30 " + translate("minutes")
},
{
"value": "never",
"text": translate("never")
}
],
options = locktimeOptions.map(option =>
"<li><div class='pick_conf'><div class='radio icon-radio-unchecked'></div><span>" + option.value + "</span> " + option.text + "</div></li>"
).join("");
ddat = [{
"div": {
"class": "popform",
"content": [{
"ul": {
"class": "conf_options noselect",
"content": options
},
"input": {
"attr": {
"value": locktime,
"type": "hidden"
}
}
},
{
"input": {
"class": "submit",
"attr": {
"type": "submit",
"value": translate("okbttn")
}
}
}
]
}
}],
content = template_dialog({
"id": "locktime_formbox",
"icon": "icon-clock",
"title": translate("locktime"),
"elements": ddat
});
popdialog(content, "triggersubmit");
$("#locktime_formbox ul.conf_options li").filter(function() {
return $(this).find("span").text() === locktime;
}).find(".radio").removeClass("icon-radio-unchecked").addClass("icon-radio-checked2");
})
}
// Handles the submission of lock time settings
function submit_locktime() {
$(document).on("click", "#locktime_formbox input.submit", function(e) {
e.preventDefault();
const thisvalue = $(this).prev("input").val(),
titlepin = thisvalue === "never" ? "pincodedisabled" : "pincodeactivated";
set_setting("pinsettings", {
"locktime": thisvalue,
"selected": titlepin
}, translate(titlepin));
canceldialog();
canceloptions();
savesettings();
})
}
// Bip32 passphrase
// Handles the click event for BIP32 passphrase settings
function trigger_bip32() {
$(document).on("click", "#bip39_passphrase", function() {
if (glob_let.hasbip === true) {
all_pinpanel({
"func": manage_bip32
}, null, true);
return
}
manage_bip32();
})
}
// Handles the click event for hiding the seed panel
function hide_seed_panel_trigger() {
$(document).on("click", "#seed_steps .seed_step .ss_header .icon-cross", function() {
hide_seed_panel();
})
}
// Hides the seed panel
function hide_seed_panel() {
glob_const.body.removeClass("seed_dialog");
$("#seed_panel").attr("class", "");
sleep();
}
// Back up
// Handles the click event for triggering database backup
function backupdatabasetrigger() {
$(document).on("click", "#backup, #alert", function() {
backupdatabase();
})
}
// Performs the database backup
function backupdatabase() {
if ($("#popup").hasClass("showpu")) {
return
}
if (is_openrequest() === true) {
return
}
const jsonencode = complilebackup(),
filename = complilefilename(),
changespush = [];
$.each(glob_let.changes, function(key, value) {
if (value > 0) {
const nrchanges = (value == 1) ? translate("changein") : translate("changesin");
changespush.push("<li>" + value + " " + nrchanges + " '" + translate(key) + "'</li>");
}
});
const gd_active = (GD_pass().pass) ? true : false,
alert_icon = $("#alert > span"),
nr_changes = alert_icon.text(),
alert_title = alert_icon.attr("title"),
alert_txt = (nr_changes === "!") ? "<span class='warning'>! " + alert_title + " </span>" : "<p>" + translate("nrchanges", {
"nr_changes": nr_changes
}) + "</p>",
showhidechangelog = gd_active ? "display:none" : "display:block",
changenotification = ((!gd_active && glob_const.body.hasClass("haschanges")) || glob_const.html.hasClass("proxyupdate")) ? alert_txt : "",
ddat = [{
"div": {
"id": "dialogcontent",
"content": [{
"div": {
"id": "ad_info_wrap",
"content": [{
"ul": {
"content": [{
"li": {
"class": "clearfix pad",
"content": [{
"strong": {
"content": "<span class='icon-googledrive'></span> " + translate("backupwithgd")
},
"div": {
"id": "gdtrigger",
"class": "ait",
"content": switchpanel(gd_active, " custom")
}
}]
}
}]
}
}]
}
},
{
"div": {
"id": "changelog",
"attr": {
"style": showhidechangelog
},
"content": changenotification + "<ul>" + changespush.join("") + "</ul>"
}
},
{
"div": {
"id": "custom_actions",
"content": [{
"br": {
"close": true
},
"a": {
"id": "triggerdownload",
"class": "button icon-download",
"attr": {
"href": "data:text/json;charset=utf-16le;base64," + jsonencode + "' download='" + filename,
"title": filename,
"data-date": new Date(now()).toLocaleString(langcode).replace(/\s+/g, '_').replace(/\:/g, '_'),
"data-lastbackup": filename,
"download": "download"
},
"content": translate("downloadbu")
}
}]
}
}
]
}
},
{
"div": {
"id": "backupactions",
"content": [{
"div": {
"id": "share_bu",
"class": "util_icon icon-share2",
"attr": {
"data-url": jsonencode
}
}
},
{
"div": {
"id": "backupcd",
"content": "OK"
}
},
{
"div": {
"id": "backupcd",
"content": cancelbttn
}
}
]
}
}
],
content = template_dialog({
"id": "backupformbox",
"icon": "icon-download",
"title": translate("backup"),
"elements": ddat
});
popdialog(content, "triggersubmit", null, true);
}
// Handles the switch for including secret phrase in backup
function sbu_switch() {
$(document).on("mouseup", "#toggle_sbu_span .switchpanel", function() {
const thistrigger = $(this),
thisvalue = thistrigger.hasClass("true");
if (thisvalue === true) {
const result = confirm(translate("includesecretphrase"));
if (result === false) {
thistrigger.removeClass("true").addClass("false");
return false;
}
}
set_setting("backup", {
"sbu": thisvalue
});
savesettings();
})
}
// Handles sharing of backup
function sharebu() {
$(document).on("click", "#share_bu", function() {
const result = confirm(translate("sharebu"));
if (result === true) {
loader(true);
loadertext(translate("generatebu"));
const accountname = $("#accountsettings").data("selected");
api_proxy({
"custom": "system_bu",
"api_url": true,
"proxy": true,
"params": {
"url": $(this).attr("data-url"),
"account": btoa(accountname)
}
}).done(function(e) {
const br_cache = e.ping.br_cache,
filetime = br_cache.created_utc,
filetimesec = filetime ? filetime * 1000 : now(),
filetime_format = new Date(filetimesec).toLocaleString(langcode),
sharedtitle = translate("systembackup") + " " + accountname + " (" + filetime_format + ")",
set_proxy = c_proxy(),
r_dat = btoa(JSON.stringify({
"ro": br_cache.filename,
"proxy": set_proxy
}));
shorten_url(sharedtitle, glob_const.approot + "?p=settings&sbu=" + r_dat, fetch_aws("img_system_backup.png"), true);
}).fail(function(xhr, stat, err) {
console.error("API proxy error:", xhr, stat, err);
closeloader();
});
}
})
}
// Checks and processes system backup
function check_systembu(sbu) {
const ro_dat = stripb64(sbu),
ro_id = ro_dat.ro,
ro_proxy = ro_dat.proxy;
api_proxy({
"custom": "get_system_bu",
"api_url": true,
"proxy": true,
"params": ro_id
}, ro_proxy).done(function(e) {
const ping = e.ping;
if (ping) {
const br_cache = ping.br_cache,
server_time = br_cache.utc_timestamp,
filetime = br_cache.created_utc,
filetimesec = filetime ? filetime * 1000 : now(),
filetime_format = new Date(filetimesec).toLocaleString(langcode),
br_result = ping.br_result,
base64 = br_result.base64,
account = atob(br_result.account),
sharedtitle = translate("systembackup") + " " + account + " (" + filetime_format + ")",
bu_date = filetime_format.replace(/\s+/g, "_").replace(/\:/g, "_"),
cache_time = br_cache.cache_time,
expires_in = (filetime + cache_time) - server_time,
filename = "bitrequest_system_backup_" + langcode + "_" + encodeURIComponent(account) + "_" + bu_date + ".json",
cd = countdown(expires_in * 1000),
cd_format = countdown_format(cd),
cf_string = cd_format ? translate("expiresin") + cd_format : translate("fileexpired"),
ddat = [{
"div": {
"id": "dialogcontent",
"content": [{
"h1": {
"content": sharedtitle
},
"div": {
"class": "error",
"attr": {
"style": "margin-top:1em;padding:0.3em 1em"
},
"content": cf_string
}
},
{
"div": {
"id": "changelog",
"content": [{
"div": {
"id": "custom_actions",
"content": [{
"br": {
"close": true
},
"a": {
"id": "triggerdownload",
"class": "button icon-download",
"attr": {
"href": "data:text/json;charset=utf-16le;base64," + base64,
"download": filename,
"title": filename,
"data-date": bu_date,
"data-lastbackup": filename
},
"content": translate("downloadbu")
},
"div": {
"id": "restore_bu",
"class": "button icon-share2",
"attr": {
"data-base64": base64,
"data-filename": filename
},
"content": translate("installlbu")
}
}]
}
}]
}
}
]
}
}],
content = template_dialog({
"id": "system_backupformbox",
"icon": "icon-download",
"title": translate("systembackup"),
"elements": ddat
}) + "<div id='backupactions'><div id='backupcd'>" + cancelbttn + "</div></div>";
popdialog(content, "triggersubmit", null, true);
} else {
systembu_expired();
}
}).fail(function(xhr, stat, err) {
console.error("API proxy error:", xhr, stat, err);
systembu_expired();
});
}
// Decodes base64 string and returns JSON object
function stripb64(ab) {
const b64 = ab.indexOf("%") > -1 ? ab.substr(0, ab.indexOf("%")) : ab;
return JSON.parse(atob(b64));
}
// Displays message for expired system backup
function systembu_expired() {
const content = render_html([{
"div": {
"id": "system_backupformbox",
"class": "formbox",
"content": "<h2 class='icon-download'>" + translate("fileexpired") + "</h2>"
}
},
{
"div": {
"id": "backupactions",
"content": "<div id='backupcd'>" + cancelbttn + "</div>"
}
}
]);
popdialog(content, "triggersubmit", null, true);
}
// Handles the restoration of system backup
function restore_systembu() {
$(document).on("click", "#system_backupformbox #restore_bu", function() {
const result = confirm(translate("installsb"));
if (result === true) {
const this_bttn = $(this),
bu_dat = this_bttn.attr("data-base64"),
j_filename = this_bttn.attr("data-filename"),
j_object = JSON.parse(atob(bu_dat));
restore(j_object, j_filename)
}
})
}
// Handles cancellation of backup dialog
function backupcd() {
$(document).on("click", "#backupcd", function() {
canceldialog();
})
}
// Compiles backup data from localStorage
function complilebackup() {
const jsonfile = [],
excludedKeys = [
"bitrequest_symbols", "bitrequest_changes", "bitrequest_erc20tokens_init", "bitrequest_erc20tokens",
"bitrequest_editurl", "bitrequest_recent_requests", "bitrequest_backupfile_id",
"bitrequest_appstore_dialog", "bitrequest_init", "bitrequest_k",
"bitrequest_awl", "bitrequest_dat", "bitrequest_tp"
];
for (let key in localStorage) {
const value = localStorage.getItem(key);
if (value === null || excludedKeys.includes(key)) {
continue;
} else if (key === "bitrequest_bpdat") {
const not_verified = (glob_let.io.bipv !== "yes");
if (not_verified || (glob_let.test_derive && get_setting("backup", "sbu") === true)) {
const val_obj = JSON.parse(value);
val_obj.dat = null;
jsonfile.push('"' + key + '":' + JSON.stringify(val_obj));
}
} else {
jsonfile.push('"' + key + '":' + value);
}
}
return btoa("{" + jsonfile.join(",") + "}");
}
// Generates a filename for the backup file
function complilefilename() {
return "bitrequest_backup_" + langcode + "_" + new Date(now()).toLocaleString(langcode).replace(/\s+/g, "_").replace(/\:/g, "_") + ".json";
}
// Handles the submission of backup download
function submitbackup() {
$(document).on("click", "#triggerdownload", function(e) {
if (glob_const.body.hasClass("ios")) {
e.preventDefault();
notify(translate("noiosbu"));
return
}
const thisnode = $(this),
href = thisnode.attr("href"),
title = thisnode.attr("title"),
result = confirm(translate("downloadfile", {
"file": title
}));
if (result === false) {
e.preventDefault();
return
}
const lastsaved = "last backup: " + thisnode.attr("data-date"),
lastbackup = thisnode.attr("data-lastbackup");
set_setting("backup", {
"titlebackup": lastsaved,
"lastbackup": lastbackup,
"device": "folder-open"
}, lastsaved);
savesettings("noalert");
resetchanges();
canceldialog();
notify(translate("downloaded", {
"file": lastbackup
}));
})
}
// Restore backup
// Initiates the restore process from backup
function restorefrombackup() {
$(document).on("click", "#restore, #rshome", function() {
trigger_restore();
})
}
// Triggers the restore process and displays the restore dialog
function trigger_restore() {
glob_let.backup_active = false;
const restorenode = $("#restore"),
backupnode = $("#backup"),
lastfileused = restorenode.data("fileused"),
lastdevice = restorenode.data("device"),
deviceused = lastdevice === "folder-open" ? "" : "google-drive",
lastfileusedstring = lastfileused ? "<p class='icon-" + deviceused + "'>" + translate("lastrestore") + "<br/><span class='icon-" + lastdevice + "'>" + lastfileused + "</span></p>" : "",
lastbackup = backupnode.data("lastbackup"),
lastbudevice = backupnode.data("device"),
lastbackupdevice = lastbudevice === "folder-open" ? "" : "google-drive",
lastbackupstring = lastbackup ? "<p class='icon-" + lastbackupdevice + "'>" + translate("lastbackup") + "<br/><span class='icon-" + lastbudevice + "'>" + lastbackup + "</span></p>" : "",
gd_active = GD_pass().pass,
showhidegd = gd_active ? "display:none" : "display:block",
ddat = [{
"div": {
"id": "gd_meta",
"content": lastfileusedstring + lastbackupstring