forked from meganz/webclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
secureboot.js
4162 lines (3634 loc) · 202 KB
/
secureboot.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
// Release version information is replaced by the build scripts
var buildVersion = { website: '', chrome: '', firefox: '', commit: '', timestamp: '', dateTime: '' };
var browserUpdate = 0;
var pageLoadTime;
var silent_loading = false;
var cookiesDisabled = false;
var storageQuotaError = false;
var lastactive = new Date().getTime();
var seqno = Math.ceil(Math.random()*1000000000);
var staticpath = null;
var defaultStaticPath = 'https://eu.static.mega.co.nz/4/';
var ua = window.navigator.userAgent.toLowerCase();
var uv = window.navigator.appVersion.toLowerCase();
var storage_version = '1'; // clear localStorage when version doesn't match
var contenterror = 0;
var nocontentcheck = false;
var l, d = false;
var loginresponse, voucher, dl_res, gmf_res;
var tmp, page, apipath, hashLogic, u_storage, u_sid;
// Cache location.search parameters early as the URL may get rewritten later
var locationSearchParams = location.search;
var is_electron = false;
var is_eplusplus = false;
if (typeof process !== 'undefined') {
var mll = process.moduleLoadList || [];
if (mll.indexOf('NativeModule ELECTRON_ASAR') !== -1) {
is_electron = module;
module = undefined; // prevent factory loaders from using the module
// localStorage.jj = 1;
}
}
var is_mobile = (function isMobile() {
'use strict';
var mobileStrings = [
'iphone', 'ipad', 'android', 'blackberry', 'nokia', 'opera mini', 'ucbrowser',
'windows mobile', 'windows phone', 'iemobile', 'mobile safari', 'bb10; touch'
];
for (var i = mobileStrings.length; i--;) {
if (ua.indexOf(mobileStrings[i]) > 0) {
return true;
}
}
})();
var is_android = is_mobile && ua.indexOf('android') > 0;
var is_uc_browser = is_mobile && ua.indexOf('ucbrowser') > 0;
var is_ios = is_mobile && (ua.indexOf('iphone') > -1 || ua.indexOf('ipad') > -1 || ua.indexOf('ipod') > -1);
var is_old_windows_phone = is_mobile && /windows phone 8|iemobile\/9|iemobile\/10|iemobile\/11/i.test(ua);
var is_windowsphone = is_old_windows_phone || is_mobile && ua.indexOf('windows phone') > 0;
var is_huawei = is_mobile && (ua.indexOf('huawei') > 0 || ua.indexOf('hmscore') > 0);
if (is_android && !is_huawei) {
// detect huawei devices by model
tmp = [
'ana-al00', 'ana-nx9', 'ang-an00', 'art-l28', 'brq-an00', 'cdy-nx9b', 'dra-lx9', 'els-n39', 'els-nx9',
'jef-nx9', 'jny-lx2', 'lio-an00m', 'lio-l29', 'lio-n29', 'med-lx9', 'noh-an00', 'noh-lg', 'noh-nx9',
'nop-an00', 'oce-an10', 'oce-an50', 'tas-l29', 'tet-an00'
];
for (var m = tmp.length; m--;) {
if (ua.indexOf(tmp[m]) > 0) {
is_huawei = tmp[m];
break;
}
}
}
var staticServerLoading = {
loadFailuresOriginal: 0, // Count of failures on the original static server (from any thread)
loadFailuresDefault: {}, // Count of failures on the EU static server per file
maxRetryAttemptsOriginal: 2, // Max retry attempts on the original static server before switching to the default
maxRetryAttemptsDefault: 3, // Max retry attempts on the default static server per file before it shows dialog
failureLoggedOriginal: false, // Flag to indicate failure of original static server was logged to the API
failureLoggedDefault: false, // Flag to indicate failure of the default static server was logged to the API
failureLoggedCorrupt: false, // Flag to indicate that file corruption (hash mismatch) was logged to the API
flippedToDefault: false // Flag to indicate if the static server was flipped
};
var load_error_types = {
/** The file is corrupt i.e. mismatch on SHA-2 hash check */
file_corrupt: 1,
/** A file loading issue, network issue or the static server is down */
file_load_error: 2
};
Object.defineProperties(self, {
'freeze': {
value: function freeze(obj) {
Object.setPrototypeOf(obj, null);
return Object.freeze(obj);
}
},
'gClearTimeout': {
value: self.clearTimeout
},
'gSetTimeout': {
value: self.setTimeout
},
'lazy': {
value: function lazy(target, property, stub) {
return Object.defineProperty(target, property, {
get: function() {
Object.defineProperty(this, property, {
value: stub.call(this),
enumerable: property[0] !== '_'
});
return this[property];
},
configurable: true
});
}
},
'megaChatIsDisabled': ((function() {
var status = tryCatch(function() {
return localStorage.testChatDisabled;
}, false)();
return {
set: function(val) {
status = val;
if (status) {
$(document.body).addClass("megaChatDisabled");
}
else {
$(document.body).removeClass("megaChatDisabled");
}
},
get: function() {
return status || window.mega.flags.mcs === 0;
}
};
})()),
'megaChatIsReady': {
get: function() {
return !self.megaChatIsDisabled && typeof megaChat !== 'undefined' && megaChat.is_initialized;
}
}
});
/**
* Check whether the provided `page` points to a public link
* @param {String} [page] optional page to check.
* @returns {String|Array|Boolean} page for v1, [public-handle, key] for v2+, or false
*/
function isPublicLink(page) {
'use strict';
var ptr = (page = getCleanSitePath(page)).split(/[^\w-]/).filter(String);
if (page[0] === '!') {
ptr.unshift('file');
}
else if (isPublicLink.upd[ptr[0]]) {
ptr[0] = isPublicLink.upd[ptr[0]];
}
else if (isPublicLink.v1[page.slice(0, 2)]) {
return page;
}
if (ptr.length > 1 && page.length > isPublicLink.v2[ptr[0]]) {
return Object.defineProperties(ptr.slice(1), {
dl: {
value: ptr[0] === 'file' || ptr[0] === 'embed'
},
pf: {
value: ptr[0] === 'folder' || ptr[0] === 'collection'
},
link: {
value: ptr[0] + '/' + ptr[1] + '#' + ptr[2] + (ptr.length > 3 ? '/' + ptr.slice(3).join('/') : '')
}
});
}
return false;
}
Object.defineProperties(isPublicLink, {
v1: {
value: {'F!': 1, 'P!': 1, 'E!': 1, 'D!': 1}
},
v2: {
value: {file: 6, folder: 8, embed: 7, chat: 6, collection: 12}
},
upd: {
value: {F: 'folder', E: 'embed', D: 'filerequest'}
}
});
try {
// auto-shield
freeze(freeze);
freeze(lazy);
freeze(isPublicLink.v1);
freeze(isPublicLink.v2);
freeze(isPublicLink.upd);
freeze(isPublicLink);
delete String.prototype.big;
delete String.prototype.sup;
delete String.prototype.sub;
delete String.prototype.bold;
delete String.prototype.link;
delete String.prototype.blink;
delete String.prototype.small;
delete String.prototype.fixed;
delete String.prototype.anchor;
delete String.prototype.strike;
delete String.prototype.italics;
delete String.prototype.fontsize;
delete String.prototype.fontcolor;
}
catch (ex) {
console.warn('unsecure browser environment...', ex);
}
tmp = document.location.href.substr(0, 16);
var is_chrome_web_ext = tmp === 'chrome-extension' || tmp === 'ms-browser-exten';
var is_firefox_web_ext = tmp === 'moz-extension://';
var is_extension = hashLogic = is_electron || is_chrome_web_ext || is_firefox_web_ext;
tmp = getCleanSitePath();
var is_embed = tmp.substr(0, 6) === 'embed/' || tmp.substr(0, 2) === 'E!';
var is_drop = tmp.substr(0, 12) === 'filerequest#' || tmp.substr(0, 4) === 'drop' || tmp.substr(0, 2) === 'D!';
var is_megadrop = (tmp.substr(0, 9) === 'megadrop/' || tmp.substr(0, 12) === 'filerequest/') && tmp.split('/')[1];
var is_chatlink = tmp.substr(0, 5) === 'chat/' && tmp.replace(/[#?].*$/, '').split('/')[1];
var is_iframed = is_embed || is_drop || is_megadrop;
var is_karma = !is_iframed && /^localhost:987[6-9]/.test(window.top.location.host);
var is_microsoft = /msie|edge|trident/i.test(ua);
var is_bot = !is_extension && /bot|crawl/i.test(ua);
var is_webcache = location.host === 'webcache.googleusercontent.com';
var is_livesite = location.host === 'mega.nz' || location.host === 'mega.io'
|| location.host === 'smoketest.mega.nz' || is_extension;
function getMobileStoreLink() {
'use strict';
if (is_ios) {
return 'https://itunes.apple.com/app/mega/id706857885';
}
if (is_windowsphone) {
return 'zune://navigate/?phoneappID=1b70a4ef-8b9c-4058-adca-3b9ac8cc194a';
}
if (is_huawei) {
return 'https://appgallery.huawei.com/#/app/C102009895';
}
return 'https://play.google.com/store/apps/details?id=mega.privacy.android.app&referrer=meganzindexandroid';
}
function goToMobileApp(aBaseLink) {
'use strict';
var testbed = tryCatch(function() {
return localStorage.testOpenInApp;
}, false)();
if (is_ios || testbed === 'ios') {
openExternalLink('mega://' + aBaseLink);
}
else if (is_windowsphone || testbed === 'winphone') {
top.location = 'mega://' + aBaseLink;
}
else if (is_android || testbed === 'android') {
var tmp = 'intent://' + aBaseLink + '/#Intent;scheme=mega;package=mega.privacy.android.app;end';
tmp = tmp.replace('id.app', 'id.app;S.browser_fallback_url=' + encodeURIComponent(getMobileStoreLink()));
if (is_huawei) {
tmp = tmp.replace('.app;', '.app.huawei;');
}
top.location = tmp;
}
else {
// eslint-disable-next-line no-alert
alert('This device is unsupported.');
}
return false;
}
function openExternalLink(aExternalLink) {
'use strict';
// Clear page events
var clearEvents = function() {
document.removeEventListener('visibilitychange', clearEvents);
clearTimeout(window.appLnkInt);
window.appLnkInt = undefined;
return 0xDEAD;
};
mBroadcaster.addListener('beforepagechange', clearEvents);
// Clear events when changing the tab visibility
clearEvents();
document.addEventListener('visibilitychange', clearEvents);
// Open App link
tryCatch(function() {
top.location = aExternalLink;
})();
// Try to open Store link If application link is not opened
window.appLnkInt = setTimeout(function() {
if (!document.hidden) {
top.location = getMobileStoreLink();
}
clearEvents();
}, 3e3);
}
function getSitePath() {
'use strict';
if (is_webcache) {
var m = String(location.href).match(/mega\.nz\/([\w-]+)/);
if (m) {
return '/' + m[1];
}
}
return self.hashLogic ? '/' + location.hash.replace('#', '') : location.pathname + location.hash;
}
// remove dangling characters from the pathname/hash
function getCleanSitePath(path) {
'use strict';
if (path === undefined) {
path = getSitePath();
if (location.search && path.indexOf('#') < 0) {
location.search.replace(/\w+=[^&]+/g, function(m) {
path += '/' + m;
});
}
}
if (path.indexOf('lang_') > -1) {
path = path.replace('lang_', 'lang=');
}
// cleanup and handle affiliate tags.
path = mURIDecode(path).replace(/^[#/]+|\/+$/g, '').split(/(\/\w+=)/);
if (/^\w+=/.test(path[0])) {
path = [''].concat(path[0].split('=')).concat(path.slice(1));
}
// Allow search the folder with '=' symbol
if (path[0] === 'fm/search' && path.length > 1) {
path = [path.join('')];
}
if (path.length > 1) {
for (var s = 1; s < path.length; s += 2) {
var v = mURIDecode(path[s + 1]);
var k = String(path[s]).replace(/\W/g, '');
path[k] = v;
v = k.substr(0, 3);
if (v === 'utm' || v === 'mtm') {
/** @property window.uTagUTM */
/** @property window.uTagMTM */
v = 'uTag' + v.toUpperCase();
window[v] = window[v] || {};
window[v][k] = path[k];
}
}
if (path.uao) {
var target = window.mega || window;
target.uaoref = path.uao;
}
if (path.aff) {
tryCatch(function() {
if (!path.aff_time) {
sessionStorage.affid = path.aff;
sessionStorage.affts = Date.now();
sessionStorage.afftype = 1;
}
else if (!(sessionStorage.affts > (path.aff_time *= 1000))) {
sessionStorage.affid = path.aff;
sessionStorage.affts = path.aff_time;
// Future proof, currently only public link affiliate data is coming from other agent.
// Later, url from other agents will contains type for it to support other type.
sessionStorage.afftype = path.aff_type || 2;
}
}, false)();
}
tryCatch(function() {
if (path.csp) {
localStorage.csp = path.csp >>> 0 & 0xff;
}
if (path.sra) {
localStorage.utm = b64decode(path.sra);
}
if (path.lang && path.lang.length < 6) {
localStorage.lang = path.lang;
}
if (path.cjevent) {
sessionStorage.cjevent = path.cjevent;
}
if (path[0] === 'pro' && path.tab) {
window.mProTab = path.tab;
}
}, false)();
if (path.mt) {
window.uTagMT = path.mt;
}
if (path.mct) {
window.uTagMCT = path.mct;
}
if (path.next) {
window.nextPage = b64decode(path.next);
if (path.plan) {
window.pickedPlan = path.plan;
}
else if (path.articleUrl) {
window.helpOrigin = b64decode(path.articleUrl);
}
}
}
return path[0];
}
// Safer wrapper around decodeURIComponent
function mURIDecode(path) {
path = String(path);
if (path.indexOf('%25') >= 0) {
do {
path = path.replace(/%25/g, '%');
} while (path.indexOf('%25') >= 0);
}
if (path.indexOf('%21') >= 0) {
path = path.replace(/%21/g, '!');
}
try {
path = decodeURIComponent(path);
}
catch (e) {}
return path;
}
/**
* Based on the user's geographic location, set the closest static path.
* This is detected by the mega.nz server and set as a cookie e.g. "geoip=SG".
* @returns {String} Returns the nearest static server to be used or the EU one as default
*/
// eslint-disable-next-line complexity
function geoStaticPath(cms) {
'use strict';
var finalPath = cms ? 'cms/' : '4/';
try {
// If flag is not set to force the default EU static server
if (!sessionStorage.skipGeoStaticPath) {
// Set which countries will use which static server
var northAmericaStaticCountries = 'AG AI AR BB BL BO BR BS BZ CA CL CO CO CR CU DO EC FK GD GF GL GT GY HN HT IS JM KN LC MX NI PA PE PR PY SR SR TT US UY VC VE VE VG VI';
var newZealandStaticCountries = 'AU FJ NC NZ';
var japanStaticCountries = 'JP TW PH HK MO KR SG KP BN BT MM MY TH VN';
// Match on cookie e.g. "geoip=SG" returns array ['geoip=SG', 'SG']
var cookieMatch = String(document.cookie).match(/geoip\s*\=\s*([A-Z]{2})/);
// Check the country code to return a closer static server
if (cookieMatch && cookieMatch[1] && japanStaticCountries.indexOf(cookieMatch[1]) > -1) {
return 'https://jp.static.mega.co.nz/' + finalPath;
}
else if (cookieMatch && cookieMatch[1] && northAmericaStaticCountries.indexOf(cookieMatch[1]) > -1) {
return 'https://na.static.mega.co.nz/' + finalPath;
}
else if (cookieMatch && cookieMatch[1] && newZealandStaticCountries.indexOf(cookieMatch[1]) > -1) {
return 'https://nz.static.mega.co.nz/' + finalPath;
}
}
}
catch (ex) {}
return defaultStaticPath;
}
var myURL = window.URL;
// Check whether we should redirect the user to the browser update.html page (triggered for Edge 18 and worse browsers)
browserUpdate = browserUpdate ||
(is_embed
? (typeof ReadableStream === 'undefined' || typeof IntersectionObserver === 'undefined')
: typeof BigInt === 'undefined'
);
// ReadableStream: C43 E14 F65 O30 S10.1
// IntersectionObserver: C51 E15 F55 O38 S12.1
if (!String.prototype.trim) {
String.prototype.trim = function() {
return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
};
}
if (!String.trim) {
String.trim = function(s) {
return String(s).trim();
};
}
if (!browserUpdate) try
{
try {
if (typeof localStorage === 'undefined' || localStorage === null) {
throw new Error('SecurityError: DOM Exception 18');
}
d = localStorage.d | 0;
jj = localStorage.jj;
dd = localStorage.dd;
// Write test
localStorage['$!--foo'] = Array(100).join(",");
delete localStorage['$!--foo'];
}
catch (ex) {
storageQuotaError = (ex.code === 22);
cookiesDisabled = ex.code && ex.code === DOMException.SECURITY_ERR
|| ex.message === 'SecurityError: DOM Exception 18'
|| storageQuotaError;
if (!cookiesDisabled) {
throw ex;
}
// Cookies are disabled, therefore we can't use localStorage.
// We could either show the user a message about the issue and let him
// enable cookies, or rather setup a tiny polyfill so that they can use
// the site even in such case, even though this solution has side effects.
tmp = Object.create({}, {
length: { get: function() { return Object.keys(this).length; }},
key: { value: function(pos) { return Object.keys(this)[pos]; }},
removeItem: { value: function(key) { delete this[key]; }},
setItem: { value: function(key, value) { this[key] = String(value); }},
getItem: { value: function(key) {
if (this.hasOwnProperty(key)) {
return this[key];
}
return null;
}},
clear: {
value: function() {
var obj = this;
Object.keys(obj).forEach(function(memb) {
if (obj.hasOwnProperty(memb)) {
delete obj[memb];
}
});
}
}
});
try {
delete window.localStorage;
Object.defineProperty(window, 'localStorage', { value: tmp });
Object.defineProperty(window, 'sessionStorage', { value: tmp });
}
catch (e) {
if (!is_mobile) {
throw ex;
}
}
tmp = undefined;
setTimeout(function() {
console.warn('Apparently you have Cookies disabled, ' +
'please note this session is temporal, ' +
'it will die once you close/reload the browser/tab.');
}, 4000);
}
if (!is_livesite && !is_karma && !is_webcache) {
d = d > 0 ? d : !localStorage.nfd;
jj = d > 0 && !sessionStorage.dbgContentCheck;
dd = 1;
}
if (!is_livesite && window.dd) {
nocontentcheck = sessionStorage.dbgContentCheck ? 0 : true;
staticpath = location.origin + '/';
defaultStaticPath = staticpath;
if (window.d) {
console.debug('StaticPath set to "' + staticpath + '"');
}
}
if (location.host === 'smoketest.mega.nz') {
staticpath = 'https://smoketest.static.mega.nz/4/';
defaultStaticPath = staticpath;
d = 1;
sessionStorage.rad = 1;
}
if (d > 0) {
localStorage.minLogLevel |= 0;
}
// Override the default static path to test recovery after standard static server failure
if (localStorage.getItem('defaultstaticpath') !== null) {
defaultStaticPath = localStorage.defaultstaticpath;
}
staticpath = localStorage.staticpath || staticpath || geoStaticPath(false);
apipath = localStorage.apipath || 'https://g.api.mega.co.nz/';
// If dark mode flag is enabled, change styling
if (localStorage.getItem('darkMode') === '1') {
document.documentElement.classList.add('dark-mode');
}
}
catch(e) {
if (!is_mobile || !cookiesDisabled) {
var extraInfo = '';
if (storageQuotaError) {
extraInfo = "\n\nTip: We've detected this issue is likely caused by " +
"browsing in private mode, please try turning it off.";
}
else if (cookiesDisabled) {
extraInfo = "\n\nTip: We've detected this issue is likely related to " +
"having Cookies disabled, please check your browser settings.";
}
alert(
"Sorry, we were unable to initialize the browser's local storage, " +
"either you're using an outdated/misconfigured browser or " +
"it's something from our side.\n" +
"\n"+
"If you think it's our fault, please report the issue back to us.\n" +
"\n" +
"Reason: " + (e.message || e) +
"\nBrowser: " + (typeof mozBrowserID !== 'undefined' ? mozBrowserID : ua)
+ extraInfo
);
browserUpdate = 1;
}
}
if (location.host === 'mega.io') {
tmp = document.head.querySelector('meta[property="og:url"]');
if (tmp) {
tmp.content = 'https://mega.io/';
}
tmp = document.head.querySelector('meta[property="twitter:url"]');
if (tmp) {
tmp.content = 'https://mega.io/';
}
tmp = document.head.querySelector('link[rel="icon"]');
if (tmp) {
tmp.href = 'https://mega.io/favicon.ico?v=3';
}
tmp = undefined;
}
tmp = is_mobile && Object(window.clientInformation).vendor === 'Google Inc.';
var mega = {
ui: {},
state: 0,
utils: {},
slideshow: {settings: {}},
uaoref: window.uaoref,
updateURL: defaultStaticPath + 'current_ver.txt',
chrome: (
typeof window.chrome === 'object'
&& (window.chrome.runtime !== undefined || tmp)
&& String(window.webkitRTCPeerConnection).indexOf('native') > 0
),
browserBrand: [
0, 'Torch', 'Epic', 'Edgium'
],
whoami: 'We make secure cloud storage simple. Create an account and get up to 50 GB ' +
'free on MEGA\'s end-to-end encrypted cloud collaboration platform today!',
maxWorkers: Math.min(navigator.hardwareConcurrency || 4, 16),
/** An object with flags detailing which features are enabled on the API
* XXX: This is now meant to be a legacy private property, use `mega.flags` instead.
*/
apiMiscFlags: null,
/** Get browser brand internal ID */
getBrowserBrandID: function() {
if (Object(window.chrome).torch) {
return 1;
}
else {
var plugins = Object(navigator.plugins);
var len = plugins.length | 0;
while (len--) {
var plugin = Object(plugins[len]);
// XXX: This plugin might be shown in other browsers than Epic,
// hence we check for chrome.webstore since it won't appear
// in Google Chrome, although it might does in other forks?
if (plugin.name === 'Epic Privacy Browser Installer') {
return Object(window.chrome).webstore ? 2 : 0;
}
}
if (this.chrome && !String(this.userAgentBrands).indexOf('MicrosoftEdge:')) {
return 3;
}
}
return 0;
},
/** get cryptographically strong random values. */
getRandomValues: function(len) {
'use strict';
var seed = new Uint8Array(len || 128);
return asmCrypto.getRandomValues(seed);
},
/** Load performance report */
initLoadReport: function() {
var r = {startTime: Date.now(), stepTimeStamp: Date.now(), EAGAINs: 0, e500s: 0, errs: 0, mode: 1};
r.aliveTimer = setInterval(function() {
var now = Date.now();
if ((now - r.aliveTimeStamp) > 20000) {
// Either the browser froze for too long or the computer
// was resumed from sleep/hibernation... let's hope it's
// the later and do not send this report.
r.sent = true;
clearInterval(r.aliveTimer);
}
else if (r.scSent && now - r.scSent > 6e4 && (scqhead > scqtail * 2)) {
// Do not tell API to rebuild the treecache if we were loading from indexedDB
if (r.mode === 1 && !sessionStorage.lightTreeReload) {
sessionStorage.lightTreeReload = true;
fm_fullreload(true);
}
else {
onIdle(function() {
eventlog(99679, true); // sc processing took too long
});
$.closeMsgDialog = 1;
msgDialog('warninga:!^' + l[17704] + '!' + l[17705], l[882], l[17706], 0, function(yes) {
if (yes) {
fm_fullreload();
}
$.closeMsgDialog = 0;
});
r.scSent = now;
delete sessionStorage.lightTreeReload;
}
}
r.aliveTimeStamp = now;
}, 2000);
this.loadReport = r;
this.state |= window.MEGAFLAG_LOADINGCLOUD;
},
redirect: function(to, page, kv, urlQs, st) {
'use strict';
var storage = localStorage;
var toMegaIo = to === 'mega.io';
var getCount = 0;
st = typeof st === 'undefined' || st;
to = (String(to).indexOf('//') < 0 ? 'https://' : '') + to;
var uLang = sessionStorage.lang || storage.lang;
if (uLang) {
// Map webclient language codes to those that are supported on mega.io
to += '/' + mega.getMegaIoMappedLang(uLang);
}
if (page) {
to += '/' + page;
}
var affid = sessionStorage.affid || storage.affid;
var affts = sessionStorage.affts || storage.affts;
if (affid && affts && !(Date.now() - affts > 864e5)) {
to += '?aff=' + affid;
getCount++;
}
var _getSeperator = function() {
if (toMegaIo) {
return getCount++ ? '&' : '?';
}
else {
return '/';
}
}
if (!toMegaIo && storage.csp) {
to += _getSeperator() + 'csp=' + storage.csp;
}
if (!toMegaIo && storage.utm) {
to += _getSeperator() + 'sra=' + b64encode(storage.utm);
}
if (Array.isArray(kv)) {
for (var i = kv.length; i--;) {
var k = kv[i][0];
var v = kv[i][1];
v = !kv[i][2] && typeof v === 'string' ? b64encode(v) : v;
if (v || v === 0) {
to += '/' + k + '=' + v;
}
}
}
if (st) {
window.onload = window.onerror = null;
return location.replace(to + (urlQs || ''));
}
window.open(to + (urlQs || ''), '_blank', toMegaIo ? 'noopener' : 'noopener,noreferrer');
},
/**
* Map webclient language codes to those that are supported on mega.io
* @param {String} userLang The current webclient user language code e.g. EN, NL etc
* @returns {String} Returns the mapped language for mega.io (could be empty string for English or not supported)
*/
getMegaIoMappedLang: function(userLang) {
'use strict';
// Webclient (mega.nz) to mega.io mappings
var mappings = {
'en': '',
'ar': 'ar',
'br': 'pt-br',
'cn': 'zh-hans',
'ct': 'zh-hant',
'de': 'de',
'es': 'es',
'fr': 'fr',
'he': '', // Hebrew not supported
'hu': '', // Hungarian not supported
'id': 'id',
'it': 'it',
'jp': 'ja',
'ka': '', // Georgian not supported
'kr': 'ko',
'nl': 'nl',
'pl': 'pl',
'pt': 'pt',
'ro': 'ro',
'ru': 'ru',
'th': 'th',
'tl': '', // Filipino not supported
'tr': '', // Turkish not supported
'uk': '', // Ukrainian not supported
'vi': 'vi'
};
var mappedLang = mappings[userLang];
return typeof mappedLang === 'undefined' ? '' : mappedLang;
}
};
Object.defineProperty(mega, 'flags', {
get: function() {
'use strict';
return typeof u_attr === 'object' && u_attr.flags || this.apiMiscFlags || false;
}
});
Object.defineProperty(mega, 'user', {
get: function() {
'use strict';
return typeof u_attr === 'object' && u_attr.u === window.u_handle && u_attr.u || false;
}
});
Object.defineProperty(mega, 'ipcc', {
get: function() {
'use strict';
return typeof u_attr === 'object' && u_attr.ipcc || window.ipcc || false;
}
});
Object.defineProperty(mega, 'BID', {
get: function() {
'use strict';
if (!mega.flags.bid) {
return 'gTxFhlOd_LQ';
}
else if (mega.flags.bid === 3) {
return '-aw4PbDRAKo';
}
console.error("Invalid/unknown bid.");
return 'gTxFhlOd_LQ';
}
});
Object.defineProperty(mega, 'paywall', {
get: function() {
'use strict';
return typeof u_attr === 'object' &&
(u_attr.uspw || u_attr.b && u_attr.b.s === -1 || u_attr.pf && u_attr.pf.s === -1) || false;
}
});
Object.defineProperty(mega, 'active', {
get: (function() {
'use strict';
// Number of milliseconds past the user will be considered inactive.
var THRESHOLD = 3e4;
return function() {
return Date.now() - lastactive < THRESHOLD;
};
})()
});
/** @property mega.infinity */
lazy(mega, 'infinity', function() {
return mega.flags.inf > 0 || !!localStorage.mInfinity || !!localStorage.megaLiteMode;
});
/** @property mega.rewindEnabled */
lazy(mega, 'rewindEnabled', function() {
'use strict';
return (mega.flags.rw || localStorage.rewindEnable) && !is_mobile;
});
/** @property mega.viewID */
lazy(mega, 'viewID', function() {
'use strict';
return (Date.now() / 1e3 >>> 0).toString(16).slice(-8) + makeUUID().slice(-8);
});
(function(chrome) {
'use strict';
delete mega.chrome;
/** @property mega.chrome */
lazy(mega, 'chrome', function() {
return chrome || String(this.userAgentBrands).split(':').includes('Chromium');
});
})(mega.chrome);
/** @property mega.userAgentBrands */
lazy(mega, 'userAgentBrands', function() {
'use strict';
var res = [];
var userAgentData = (window.navigator || !1).userAgentData;
if (userAgentData) {
var brands = userAgentData.brands;
if (Array.isArray(brands)) {
for (var i = brands.length; i--;) {
var brand = (brands[i] || !1).brand;
res.push(String(brand).replace(/[\s:]/g, ''));
}
}
}
return res.join(':');
});
if (window.crypto && typeof crypto.getRandomValues === 'function') {
(function(crypto, rand) {
'use strict';
mega.getRandomValues = function(len) {
var seed = new Uint8Array(len || 128);
return rand.call(crypto, seed);
};
mega.getRandomValues.strong = true;
if (window.isSecureContext && typeof crypto.randomUUID === 'function') {