-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
4851 lines (4194 loc) · 148 KB
/
app.js
File metadata and controls
4851 lines (4194 loc) · 148 KB
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
/**
* ============================================
* WHO ARE YOU? - Browser Fingerprint Demo
* ============================================
* Educational demonstration of browser fingerprinting
*
* app.js - Part 1: Core Detection Functions
* - Navigator API
* - Screen & Display
* - Connection (WiFi vs Cellular)
* - Device Brand Parsing
* - Timezone & Locale
* ============================================
*/
'use strict';
// ============================================
// GLOBAL STATE
// ============================================
const AppState = {
fingerprint: {},
categorized: {},
privacyScore: 0,
dataPointsCount: 0,
language: 'id',
startTime: null,
};
// ============================================
// UTILITY FUNCTIONS
// ============================================
const Utils = {
/**
* Safely get nested property
*/
safeGet: (obj, path, fallback = null) => {
try {
return path.split('.').reduce((o, k) => (o || {})[k], obj) ?? fallback;
} catch {
return fallback;
}
},
/**
* Hash string using simple djb2 algorithm
*/
hashString: (str) => {
let hash = 5381;
for (let i = 0; i < str.length; i++) {
hash = ((hash << 5) + hash) ^ str.charCodeAt(i);
}
return (hash >>> 0).toString(16).padStart(8, '0');
},
/**
* Detect user's preferred language
*/
detectLanguage: () => {
const lang = navigator.language || navigator.userLanguage || 'en';
return lang.startsWith('id') ? 'id' : 'en';
},
/**
* Format bytes to human readable
*/
formatBytes: (bytes, decimals = 2) => {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(decimals)) + ' ' + sizes[i];
},
/**
* Delay helper
*/
delay: (ms) => new Promise(resolve => setTimeout(resolve, ms)),
/**
* Count non-null properties in object (recursive)
*/
countDataPoints: (obj) => {
let count = 0;
for (const key in obj) {
if (obj[key] !== null && obj[key] !== undefined) {
if (typeof obj[key] === 'object' && !Array.isArray(obj[key])) {
count += Utils.countDataPoints(obj[key]);
} else {
count++;
}
}
}
return count;
}
};
// ============================================
// 1. NAVIGATOR INFO
// ============================================
const NavigatorDetector = {
/**
* Get all navigator-based information
*/
getInfo: () => {
const nav = navigator;
return {
// Raw User Agent
userAgent: nav.userAgent || null,
// Platform info
platform: nav.platform || null,
vendor: nav.vendor || null,
product: nav.product || null,
appName: nav.appName || null,
appVersion: nav.appVersion || null,
appCodeName: nav.appCodeName || null,
// Language settings
language: nav.language || null,
languages: nav.languages ? Array.from(nav.languages) : null,
// Hardware hints
hardwareConcurrency: nav.hardwareConcurrency || null, // CPU cores
deviceMemory: nav.deviceMemory || null, // RAM in GB
maxTouchPoints: nav.maxTouchPoints || 0,
// Features & Permissions
cookieEnabled: nav.cookieEnabled,
doNotTrack: nav.doNotTrack || window.doNotTrack || null,
pdfViewerEnabled: nav.pdfViewerEnabled ?? null,
webdriver: nav.webdriver || false, // Automation detection
// Online status
onLine: nav.onLine,
// Plugins (mostly empty in modern browsers)
pluginsCount: nav.plugins ? nav.plugins.length : 0,
// Java & ActiveX (legacy)
javaEnabled: typeof nav.javaEnabled === 'function' ? nav.javaEnabled() : false,
};
},
/**
* Parse OS from User Agent
*/
parseOS: (ua) => {
if (!ua) return { name: 'Unknown', version: null };
const patterns = [
// Windows
{ regex: /Windows NT 10.0.*Build\/(\d+)/i, name: 'Windows', versionFn: (m) => {
const build = parseInt(m[1]);
return build >= 22000 ? '11' : '10';
}},
{ regex: /Windows NT 10.0/i, name: 'Windows', version: '10/11' },
{ regex: /Windows NT 6.3/i, name: 'Windows', version: '8.1' },
{ regex: /Windows NT 6.2/i, name: 'Windows', version: '8' },
{ regex: /Windows NT 6.1/i, name: 'Windows', version: '7' },
// macOS
{ regex: /Mac OS X (\d+[._]\d+[._]?\d*)/i, name: 'macOS', versionFn: (m) => m[1].replace(/_/g, '.') },
{ regex: /Macintosh/i, name: 'macOS', version: null },
// iOS
{ regex: /iPhone OS (\d+[._]\d+)/i, name: 'iOS', versionFn: (m) => m[1].replace(/_/g, '.') },
{ regex: /iPad.*OS (\d+[._]\d+)/i, name: 'iPadOS', versionFn: (m) => m[1].replace(/_/g, '.') },
// Android
{ regex: /Android (\d+\.?\d*)/i, name: 'Android', versionFn: (m) => m[1] },
// Linux distros
{ regex: /Ubuntu/i, name: 'Ubuntu', version: null },
{ regex: /Fedora/i, name: 'Fedora', version: null },
{ regex: /Linux/i, name: 'Linux', version: null },
// Chrome OS
{ regex: /CrOS/i, name: 'Chrome OS', version: null },
];
for (const pattern of patterns) {
const match = ua.match(pattern.regex);
if (match) {
return {
name: pattern.name,
version: pattern.versionFn ? pattern.versionFn(match) : pattern.version
};
}
}
return { name: 'Unknown', version: null };
},
/**
* Parse Browser from User Agent
*/
parseBrowser: (ua) => {
if (!ua) return { name: 'Unknown', version: null };
const patterns = [
// Order matters! More specific first
{ regex: /Edg\/(\d+\.?\d*)/i, name: 'Microsoft Edge' },
{ regex: /OPR\/(\d+\.?\d*)/i, name: 'Opera' },
{ regex: /Opera\/(\d+\.?\d*)/i, name: 'Opera' },
{ regex: /Brave\/(\d+\.?\d*)/i, name: 'Brave' },
{ regex: /Vivaldi\/(\d+\.?\d*)/i, name: 'Vivaldi' },
{ regex: /YaBrowser\/(\d+\.?\d*)/i, name: 'Yandex Browser' },
{ regex: /SamsungBrowser\/(\d+\.?\d*)/i, name: 'Samsung Internet' },
{ regex: /UCBrowser\/(\d+\.?\d*)/i, name: 'UC Browser' },
{ regex: /Firefox\/(\d+\.?\d*)/i, name: 'Firefox' },
{ regex: /FxiOS\/(\d+\.?\d*)/i, name: 'Firefox iOS' },
{ regex: /CriOS\/(\d+\.?\d*)/i, name: 'Chrome iOS' },
{ regex: /Chrome\/(\d+\.?\d*)/i, name: 'Chrome' },
{ regex: /Safari\/(\d+\.?\d*)/i, name: 'Safari', versionRegex: /Version\/(\d+\.?\d*)/ },
];
for (const pattern of patterns) {
const match = ua.match(pattern.regex);
if (match) {
let version = match[1];
// Safari uses Version/ for actual version
if (pattern.versionRegex) {
const versionMatch = ua.match(pattern.versionRegex);
if (versionMatch) version = versionMatch[1];
}
return { name: pattern.name, version };
}
}
return { name: 'Unknown', version: null };
},
/**
* Detect device type
*/
getDeviceType: (ua, touchPoints) => {
if (!ua) return 'unknown';
// Tablets
if (/iPad|tablet|playbook/i.test(ua) ||
(/Android/i.test(ua) && !/Mobile/i.test(ua))) {
return 'tablet';
}
// Mobile
if (/Mobile|iPhone|iPod|Android.*Mobile|webOS|BlackBerry|IEMobile|Opera Mini/i.test(ua)) {
return 'mobile';
}
// Touch-enabled desktop (Surface, etc)
if (touchPoints > 0 && /Windows/i.test(ua)) {
return 'desktop-touch';
}
return 'desktop';
}
};
// ============================================
// 2. DEVICE BRAND DETECTION
// ============================================
const DeviceDetector = {
/**
* Parse device brand and model from User Agent
*/
parse: (ua) => {
if (!ua) return { brand: 'Unknown', model: null, series: null };
// ========== APPLE ==========
if (/iPhone/.test(ua)) {
return {
brand: 'Apple',
series: 'iPhone',
model: DeviceDetector.parseAppleDevice(ua, 'iPhone')
};
}
if (/iPad/.test(ua)) {
return {
brand: 'Apple',
series: 'iPad',
model: DeviceDetector.parseAppleDevice(ua, 'iPad')
};
}
if (/Macintosh/.test(ua)) {
return {
brand: 'Apple',
series: 'Mac',
model: DeviceDetector.parseMac(ua)
};
}
// ========== SAMSUNG ==========
const samsungMatch = ua.match(/SM-([A-Z])(\d{3,4})([A-Z]*)/i);
if (samsungMatch) {
return DeviceDetector.parseSamsung(samsungMatch);
}
if (/Samsung|SAMSUNG|Galaxy/i.test(ua)) {
return { brand: 'Samsung', series: 'Galaxy', model: null };
}
// ========== XIAOMI ECOSYSTEM ==========
if (/Xiaomi|Redmi|POCO|Mi \d|MIX|Black ?Shark/i.test(ua)) {
return DeviceDetector.parseXiaomi(ua);
}
// ========== BBK ELECTRONICS ==========
if (/OPPO|CPH\d{4}/i.test(ua)) {
return DeviceDetector.parseOPPO(ua);
}
if (/vivo|V\d{4}/i.test(ua)) {
return { brand: 'Vivo', series: null, model: DeviceDetector.extractModel(ua, /vivo\s*([^\s;)]+)/i) };
}
if (/Realme|RMX\d{4}/i.test(ua)) {
return { brand: 'Realme', series: null, model: DeviceDetector.extractModel(ua, /RMX(\d{4})/i) };
}
if (/OnePlus|ONEPLUS|IN\d{4}/i.test(ua)) {
return DeviceDetector.parseOnePlus(ua);
}
// ========== HUAWEI / HONOR ==========
if (/HUAWEI|HarmonyOS/i.test(ua)) {
return { brand: 'Huawei', series: null, model: DeviceDetector.extractModel(ua, /HUAWEI\s*([^\s;)]+)/i) };
}
if (/HONOR/i.test(ua)) {
return { brand: 'Honor', series: null, model: DeviceDetector.extractModel(ua, /HONOR\s*([^\s;)]+)/i) };
}
// ========== GOOGLE ==========
if (/Pixel/i.test(ua)) {
const pixelMatch = ua.match(/Pixel\s*(\d+\s*(?:Pro|a|XL)?)/i);
return {
brand: 'Google',
series: 'Pixel',
model: pixelMatch ? `Pixel ${pixelMatch[1]}` : 'Pixel'
};
}
// ========== OTHERS ==========
if (/ASUS|ROG/i.test(ua)) {
return { brand: 'ASUS', series: /ROG/i.test(ua) ? 'ROG Phone' : null, model: null };
}
if (/Sony|Xperia/i.test(ua)) {
return { brand: 'Sony', series: 'Xperia', model: null };
}
if (/LG/i.test(ua)) {
return { brand: 'LG', series: null, model: null };
}
if (/Nokia/i.test(ua)) {
return { brand: 'Nokia', series: null, model: null };
}
if (/Motorola|moto/i.test(ua)) {
return { brand: 'Motorola', series: null, model: null };
}
if (/HTC/i.test(ua)) {
return { brand: 'HTC', series: null, model: null };
}
if (/Lenovo|Tab/i.test(ua)) {
return { brand: 'Lenovo', series: null, model: null };
}
if (/Nothing/i.test(ua)) {
return { brand: 'Nothing', series: 'Phone', model: null };
}
if (/Infinix/i.test(ua)) {
return { brand: 'Infinix', series: null, model: null };
}
if (/Tecno/i.test(ua)) {
return { brand: 'Tecno', series: null, model: null };
}
// ========== DESKTOP FALLBACK ==========
if (/Windows/i.test(ua)) {
return { brand: 'Windows PC', series: null, model: null };
}
if (/Linux/i.test(ua) && !/Android/i.test(ua)) {
return { brand: 'Linux PC', series: null, model: null };
}
if (/CrOS/i.test(ua)) {
return { brand: 'Chromebook', series: null, model: null };
}
return { brand: 'Unknown', model: null, series: null };
},
/**
* Parse Apple device details
*/
parseAppleDevice: (ua, type) => {
// Apple devices don't expose model in UA
// We can only detect via screen size + pixel ratio (done elsewhere)
return type;
},
/**
* Parse Mac details
*/
parseMac: (ua) => {
if (/Intel/.test(ua)) return 'Mac (Intel)';
// Apple Silicon doesn't explicitly show, but newer Safari versions imply it
return 'Mac';
},
/**
* Parse Samsung model code
* SM-G = Galaxy S, SM-A = Galaxy A, SM-F = Galaxy Fold, SM-Z = Galaxy Z, SM-N = Note
*/
parseSamsung: (match) => {
const prefix = match[1].toUpperCase();
const number = match[2];
const seriesMap = {
'S': 'Galaxy S', // Flagship
'G': 'Galaxy S', // Older flagship
'A': 'Galaxy A', // Mid-range
'M': 'Galaxy M', // Budget
'F': 'Galaxy F/Fold',
'Z': 'Galaxy Z', // Foldables
'N': 'Galaxy Note',
'T': 'Galaxy Tab',
};
const series = seriesMap[prefix] || 'Galaxy';
// Try to determine specific model
let model = null;
if (prefix === 'S' || prefix === 'G') {
// Galaxy S series - SM-S9xx = S2x, SM-G99x = S21, etc
if (number.startsWith('9')) {
const gen = parseInt(number.charAt(1));
if (gen >= 0) model = `Galaxy S2${gen + 1}`;
}
}
return {
brand: 'Samsung',
series,
model: model || `${series} (${match[0]})`
};
},
/**
* Parse Xiaomi ecosystem devices
*/
parseXiaomi: (ua) => {
if (/POCO/i.test(ua)) {
const model = DeviceDetector.extractModel(ua, /POCO\s*([^\s;)]+)/i);
return { brand: 'POCO', series: null, model };
}
if (/Redmi/i.test(ua)) {
const model = DeviceDetector.extractModel(ua, /Redmi\s*([^\s;)]+)/i);
return { brand: 'Redmi', series: null, model };
}
if (/Black\s*Shark/i.test(ua)) {
return { brand: 'Black Shark', series: 'Gaming', model: null };
}
const model = DeviceDetector.extractModel(ua, /Mi\s*([^\s;)]+)|Xiaomi\s*([^\s;)]+)/i);
return { brand: 'Xiaomi', series: 'Mi', model };
},
/**
* Parse OPPO devices
*/
parseOPPO: (ua) => {
// Check for Find series (flagship)
if (/Find/i.test(ua)) {
return { brand: 'OPPO', series: 'Find', model: null };
}
// Check for Reno series
if (/Reno/i.test(ua)) {
return { brand: 'OPPO', series: 'Reno', model: null };
}
const cphMatch = ua.match(/CPH(\d{4})/i);
if (cphMatch) {
return { brand: 'OPPO', series: null, model: `CPH${cphMatch[1]}` };
}
return { brand: 'OPPO', series: null, model: null };
},
/**
* Parse OnePlus devices
*/
parseOnePlus: (ua) => {
const match = ua.match(/OnePlus\s*([^\s;)]+)|ONEPLUS\s+([^\s;)]+)/i);
if (match) {
const model = match[1] || match[2];
return { brand: 'OnePlus', series: null, model };
}
return { brand: 'OnePlus', series: null, model: null };
},
/**
* Helper to extract model from pattern
*/
extractModel: (ua, regex) => {
const match = ua.match(regex);
return match ? (match[1] || match[2] || null) : null;
}
};
// ============================================
// 3. SCREEN & DISPLAY INFO
// ============================================
const ScreenDetector = {
/**
* Get all screen-related information
*/
getInfo: () => {
const screen = window.screen;
return {
// Physical screen
width: screen.width,
height: screen.height,
availWidth: screen.availWidth,
availHeight: screen.availHeight,
// Color
colorDepth: screen.colorDepth,
pixelDepth: screen.pixelDepth,
// Viewport
innerWidth: window.innerWidth,
innerHeight: window.innerHeight,
outerWidth: window.outerWidth,
outerHeight: window.outerHeight,
// Pixel ratio (retina detection)
devicePixelRatio: window.devicePixelRatio || 1,
// Orientation
orientation: ScreenDetector.getOrientation(),
// Calculated
isRetina: window.devicePixelRatio > 1,
aspectRatio: ScreenDetector.calculateAspectRatio(screen.width, screen.height),
// Screen type estimation
screenType: ScreenDetector.estimateScreenType(screen.width, screen.height, window.devicePixelRatio),
};
},
/**
* Get screen orientation
*/
getOrientation: () => {
if (screen.orientation) {
return screen.orientation.type; // portrait-primary, landscape-primary, etc
}
// Fallback
return window.innerWidth > window.innerHeight ? 'landscape' : 'portrait';
},
/**
* Calculate aspect ratio
*/
calculateAspectRatio: (width, height) => {
const gcd = (a, b) => b === 0 ? a : gcd(b, a % b);
const divisor = gcd(width, height);
return `${width / divisor}:${height / divisor}`;
},
/**
* Estimate screen type based on dimensions
*/
estimateScreenType: (width, height, dpr) => {
const maxDim = Math.max(width, height);
const minDim = Math.min(width, height);
const physicalWidth = maxDim / dpr;
// Mobile phones
if (minDim <= 480 || (minDim <= 600 && dpr >= 2)) {
if (maxDim >= 2400) return 'flagship-phone';
if (maxDim >= 1920) return 'mid-range-phone';
return 'budget-phone';
}
// Tablets
if (minDim <= 1024 && minDim > 600) {
return 'tablet';
}
// Monitors
if (maxDim >= 3840) return '4k-display';
if (maxDim >= 2560) return 'qhd-display';
if (maxDim >= 1920) return 'fhd-display';
if (maxDim >= 1366) return 'hd-display';
return 'standard-display';
}
};
// ============================================
// 4. CONNECTION INFO (WiFi vs Cellular)
// ============================================
const ConnectionDetector = {
/**
* Get network connection information
*/
getInfo: () => {
const connection = navigator.connection ||
navigator.mozConnection ||
navigator.webkitConnection;
if (!connection) {
return {
supported: false,
type: null,
effectiveType: null,
downlink: null,
rtt: null,
saveData: null,
isWifi: null,
isCellular: null,
networkQuality: 'unknown'
};
}
const type = connection.type || null;
const effectiveType = connection.effectiveType || null;
const downlink = connection.downlink || null;
const rtt = connection.rtt || null;
const saveData = connection.saveData || false;
// Determine if WiFi or Cellular
const isWifi = type === 'wifi' || type === 'ethernet';
const isCellular = type === 'cellular' ||
['2g', '3g', '4g', '5g'].includes(type);
// Estimate network quality
let networkQuality = 'unknown';
if (effectiveType === '4g' && downlink >= 10) {
networkQuality = 'excellent';
} else if (effectiveType === '4g' || (effectiveType === '3g' && downlink >= 1.5)) {
networkQuality = 'good';
} else if (effectiveType === '3g') {
networkQuality = 'moderate';
} else if (effectiveType === '2g' || effectiveType === 'slow-2g') {
networkQuality = 'poor';
}
return {
supported: true,
type,
effectiveType,
downlink, // Mbps
downlinkFormatted: downlink ? `${downlink} Mbps` : null,
rtt, // ms round-trip time
saveData, // Data saver mode
isWifi,
isCellular,
isMetered: isCellular, // Cellular usually metered
networkQuality,
// Human readable description
description: ConnectionDetector.getDescription(type, effectiveType, downlink, isWifi, isCellular)
};
},
/**
* Generate human-readable description
*/
getDescription: (type, effectiveType, downlink, isWifi, isCellular) => {
if (isWifi) {
if (downlink >= 50) return 'WiFi berkecepatan tinggi (mungkin fiber)';
if (downlink >= 20) return 'WiFi standar';
if (downlink >= 5) return 'WiFi lambat';
return 'WiFi';
}
if (isCellular || type === 'cellular') {
if (effectiveType === '4g' && downlink >= 10) return 'Data seluler 4G/LTE (sinyal kuat)';
if (effectiveType === '4g') return 'Data seluler 4G/LTE';
if (effectiveType === '3g') return 'Data seluler 3G';
if (effectiveType === '2g') return 'Data seluler 2G (sinyal lemah)';
return 'Data seluler';
}
if (type === 'ethernet') return 'Koneksi kabel (Ethernet)';
if (type === 'none') return 'Tidak ada koneksi';
// Fallback estimation based on effective type
if (effectiveType === '4g') return 'Koneksi cepat (WiFi/4G)';
if (effectiveType === '3g') return 'Koneksi menengah';
if (effectiveType === '2g') return 'Koneksi lambat';
return 'Tipe koneksi tidak terdeteksi';
},
/**
* Monitor connection changes (optional)
*/
onChange: (callback) => {
const connection = navigator.connection ||
navigator.mozConnection ||
navigator.webkitConnection;
if (connection) {
connection.addEventListener('change', callback);
return () => connection.removeEventListener('change', callback);
}
return () => {};
}
};
// ============================================
// 5. TIMEZONE & LOCALE INFO
// ============================================
const TimezoneDetector = {
/**
* Get timezone and locale information
*/
getInfo: () => {
const dateTimeFormat = Intl.DateTimeFormat().resolvedOptions();
const now = new Date();
return {
// Timezone
timezone: dateTimeFormat.timeZone || null,
timezoneOffset: now.getTimezoneOffset(), // minutes from UTC
timezoneOffsetFormatted: TimezoneDetector.formatOffset(now.getTimezoneOffset()),
// Locale
locale: dateTimeFormat.locale || navigator.language,
calendar: dateTimeFormat.calendar || 'gregory',
numberingSystem: dateTimeFormat.numberingSystem || 'latn',
// Regional hints
hourCycle: dateTimeFormat.hourCycle || null, // h11, h12, h23, h24
firstDayOfWeek: TimezoneDetector.getFirstDayOfWeek(),
// Formats
dateFormat: TimezoneDetector.detectDateFormat(),
numberFormat: TimezoneDetector.detectNumberFormat(),
currencyHint: TimezoneDetector.guessCurrency(dateTimeFormat.locale),
// Current time info
isDST: TimezoneDetector.isDaylightSaving(),
};
},
/**
* Format timezone offset
*/
formatOffset: (minutes) => {
const hours = Math.abs(Math.floor(minutes / 60));
const mins = Math.abs(minutes % 60);
const sign = minutes <= 0 ? '+' : '-';
return `UTC${sign}${hours.toString().padStart(2, '0')}:${mins.toString().padStart(2, '0')}`;
},
/**
* Detect first day of week (0 = Sunday, 1 = Monday)
*/
getFirstDayOfWeek: () => {
// Most of the world uses Monday, US/Canada use Sunday
const locale = navigator.language || 'en';
const sundayLocales = ['en-US', 'en-CA', 'pt-BR', 'ja-JP', 'ko-KR', 'zh-CN'];
for (const l of sundayLocales) {
if (locale.startsWith(l.split('-')[0]) || locale === l) {
if (sundayLocales.includes(locale)) return 0;
}
}
return 1;
},
/**
* Detect date format preference
*/
detectDateFormat: () => {
const locale = navigator.language || 'en';
// US uses MM/DD/YYYY
if (locale === 'en-US') return 'MM/DD/YYYY';
// Most of Asia uses YYYY-MM-DD
if (['ja', 'ko', 'zh', 'hu'].some(l => locale.startsWith(l))) {
return 'YYYY-MM-DD';
}
// Most of Europe/Indonesia uses DD/MM/YYYY or DD.MM.YYYY
return 'DD/MM/YYYY';
},
/**
* Detect number format (decimal separator)
*/
detectNumberFormat: () => {
const formatted = (1234.5).toLocaleString();
if (formatted.includes(',') && formatted.includes('.')) {
// 1,234.5 = English style
if (formatted.indexOf(',') < formatted.indexOf('.')) {
return { decimal: '.', thousand: ',' };
}
// 1.234,5 = European/Indonesian style
return { decimal: ',', thousand: '.' };
}
if (formatted.includes(',')) {
return { decimal: ',', thousand: ' ' };
}
return { decimal: '.', thousand: ',' };
},
/**
* Guess currency based on locale
*/
guessCurrency: (locale) => {
const currencyMap = {
'id': 'IDR',
'en-US': 'USD',
'en-GB': 'GBP',
'en-AU': 'AUD',
'de': 'EUR',
'fr': 'EUR',
'ja': 'JPY',
'ko': 'KRW',
'zh-CN': 'CNY',
'zh-TW': 'TWD',
'th': 'THB',
'vi': 'VND',
'ms': 'MYR',
'hi': 'INR',
};
// Check exact match first
if (currencyMap[locale]) return currencyMap[locale];
// Check prefix match
const prefix = locale.split('-')[0];
if (currencyMap[prefix]) return currencyMap[prefix];
return 'USD'; // Default fallback
},
/**
* Check if currently in Daylight Saving Time
*/
isDaylightSaving: () => {
const now = new Date();
const jan = new Date(now.getFullYear(), 0, 1);
const jul = new Date(now.getFullYear(), 6, 1);
const stdOffset = Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
return now.getTimezoneOffset() < stdOffset;
}
};
// ============================================
// COMBINED BASIC FINGERPRINT COLLECTOR
// ============================================
const BasicFingerprint = {
/**
* Collect all basic fingerprint data
*/
collect: () => {
const navigatorInfo = NavigatorDetector.getInfo();
const os = NavigatorDetector.parseOS(navigatorInfo.userAgent);
const browser = NavigatorDetector.parseBrowser(navigatorInfo.userAgent);
const deviceType = NavigatorDetector.getDeviceType(navigatorInfo.userAgent, navigatorInfo.maxTouchPoints);
const device = DeviceDetector.parse(navigatorInfo.userAgent);
const screenInfo = ScreenDetector.getInfo();
const connectionInfo = ConnectionDetector.getInfo();
const timezoneInfo = TimezoneDetector.getInfo();
return {
// Navigator
navigator: navigatorInfo,
// Parsed info
os,
browser,
deviceType,
device,
// Screen
screen: screenInfo,
// Connection
connection: connectionInfo,
// Timezone
timezone: timezoneInfo,
// Meta
collectedAt: new Date().toISOString(),
userLanguage: Utils.detectLanguage(),
};
}
};
// ============================================
// EXPORT / ATTACH TO WINDOW (for next parts)
// ============================================
window.FingerprintApp = window.FingerprintApp || {};
window.FingerprintApp.Utils = Utils;
window.FingerprintApp.AppState = AppState;
window.FingerprintApp.NavigatorDetector = NavigatorDetector;
window.FingerprintApp.DeviceDetector = DeviceDetector;
window.FingerprintApp.ScreenDetector = ScreenDetector;
window.FingerprintApp.ConnectionDetector = ConnectionDetector;
window.FingerprintApp.TimezoneDetector = TimezoneDetector;
window.FingerprintApp.BasicFingerprint = BasicFingerprint;
console.log('📍 Fingerprint App - Part 1 Loaded (Navigator, Screen, Connection, Device)');
/**
* ============================================
* WHO ARE YOU? - Browser Fingerprint Demo
* ============================================
*
* app.js - Part 2: Advanced Fingerprinting
* - WebGL & GPU Detection
* - Canvas Fingerprint
* - Audio Fingerprint
* - Font Detection
* - WebRTC IP Leak
* - Media Devices
* ============================================
*/
// Get references from Part 1
// Gunakan window.FingerprintApp.Utils langsung, tidak perlu destructure
// ============================================
// 6. WEBGL & GPU DETECTION
// ============================================
const WebGLDetector = {
/**
* Get WebGL and GPU information
*/
getInfo: () => {
const canvas = document.createElement('canvas');
let gl = null;
let version = null;
// Try WebGL2 first, then WebGL1
try {
gl = canvas.getContext('webgl2');
if (gl) version = 'WebGL 2.0';
} catch (e) {}
if (!gl) {
try {
gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
if (gl) version = 'WebGL 1.0';
} catch (e) {}
}
if (!gl) {
return {
supported: false,
version: null,
vendor: null,
renderer: null,
gpuBrand: null,
gpuModel: null,
extensions: [],
parameters: {}
};
}
// Get debug info extension for real GPU info
const debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
let vendor = gl.getParameter(gl.VENDOR);
let renderer = gl.getParameter(gl.RENDERER);
// Get unmasked (real) values if available
if (debugInfo) {
vendor = gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL) || vendor;
renderer = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL) || renderer;
}
// Parse GPU brand and model
const gpuInfo = WebGLDetector.parseGPU(vendor, renderer);
// Get extensions
const extensions = gl.getSupportedExtensions() || [];
// Get important parameters
const parameters = {
maxTextureSize: gl.getParameter(gl.MAX_TEXTURE_SIZE),
maxViewportDims: gl.getParameter(gl.MAX_VIEWPORT_DIMS),
maxRenderbufferSize: gl.getParameter(gl.MAX_RENDERBUFFER_SIZE),
maxVertexAttribs: gl.getParameter(gl.MAX_VERTEX_ATTRIBS),
maxVertexUniformVectors: gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS),
maxFragmentUniformVectors: gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS),
maxVaryingVectors: gl.getParameter(gl.MAX_VARYING_VECTORS),
aliasedLineWidthRange: Array.from(gl.getParameter(gl.ALIASED_LINE_WIDTH_RANGE) || []),
aliasedPointSizeRange: Array.from(gl.getParameter(gl.ALIASED_POINT_SIZE_RANGE) || []),