-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontent.js
More file actions
1324 lines (1161 loc) · 46.8 KB
/
content.js
File metadata and controls
1324 lines (1161 loc) · 46.8 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
// Bot state management
let botRunning = false;
let botInterval = null;
const CHECK_INTERVAL = 1000; // Check every second
let targetCountries = ['bangladesh']; // Default target country
let notificationSound = true; // Enable sound notifications by default
let greetingMessage = 'Hi'; // Default greeting message
let continuousMode = false; // Continuous mode (auto-restart when disconnected)
let foundTargetUser = false; // Flag to track if we found a target user
let lastConnectionStatus = false; // Track previous connection status
// Country name variations for better matching
const COUNTRY_VARIATIONS = {
'United States': ['USA', 'United States', 'America', 'US', 'United States of America'],
'United Kingdom': ['UK', 'United Kingdom', 'Great Britain', 'Britain', 'England', 'Scotland', 'Wales'],
'India': ['India', 'Bharat', 'Hindustan'],
'China': ['China', 'PRC', 'People\'s Republic of China'],
'Japan': ['Japan', 'Nippon', 'Nihon'],
'Russia': ['Russia', 'Russian Federation', 'RF'],
'Brazil': ['Brazil', 'Brasil'],
'Canada': ['Canada', 'Canadian'],
'Australia': ['Australia', 'Aussie'],
'Germany': ['Germany', 'Deutschland'],
// ... Add more countries as needed
};
// List of all supported countries with their variations
const COUNTRY_VARIATIONS_FULL = {
'afghanistan': ['afghan', 'kabul'],
'albania': ['albanian', 'tirana'],
'algeria': ['algerian', 'algiers'],
'andorra': ['andorran'],
'angola': ['angolan', 'luanda'],
'argentina': ['argentinian', 'buenos aires'],
'armenia': ['armenian', 'yerevan'],
'australia': ['aussie', 'sydney', 'melbourne', 'brisbane', 'perth'],
'austria': ['austrian', 'vienna'],
'azerbaijan': ['azerbaijani', 'baku'],
'bahamas': ['bahamian', 'nassau'],
'bahrain': ['bahraini', 'manama'],
'bangladesh': ['bangla', 'dhaka', 'bd', 'bangladeshi'],
'belarus': ['belarusian', 'minsk'],
'belgium': ['belgian', 'brussels'],
'bhutan': ['bhutanese', 'thimphu'],
'bolivia': ['bolivian', 'la paz'],
'brazil': ['brazilian', 'rio', 'sao paulo'],
'brunei': ['bruneian', 'bandar seri begawan'],
'bulgaria': ['bulgarian', 'sofia'],
'cambodia': ['cambodian', 'phnom penh'],
'cameroon': ['cameroonian', 'yaounde'],
'canada': ['canadian', 'toronto', 'vancouver', 'montreal'],
'china': ['chinese', 'beijing', 'shanghai'],
'colombia': ['colombian', 'bogota'],
'croatia': ['croatian', 'zagreb'],
'cuba': ['cuban', 'havana'],
'cyprus': ['cypriot', 'nicosia'],
'czech republic': ['czech', 'prague'],
'denmark': ['danish', 'copenhagen'],
'egypt': ['egyptian', 'cairo'],
'estonia': ['estonian', 'tallinn'],
'ethiopia': ['ethiopian', 'addis ababa'],
'finland': ['finnish', 'helsinki'],
'france': ['french', 'paris'],
'germany': ['german', 'berlin', 'munich'],
'ghana': ['ghanaian', 'accra'],
'greece': ['greek', 'athens'],
'india': ['indian', 'delhi', 'mumbai', 'bangalore'],
'indonesia': ['indonesian', 'jakarta'],
'iran': ['iranian', 'tehran'],
'iraq': ['iraqi', 'baghdad'],
'ireland': ['irish', 'dublin'],
'israel': ['israeli', 'jerusalem', 'tel aviv'],
'italy': ['italian', 'rome', 'milan'],
'japan': ['japanese', 'tokyo', 'osaka'],
'jordan': ['jordanian', 'amman'],
'kazakhstan': ['kazakh', 'almaty'],
'kenya': ['kenyan', 'nairobi'],
'kuwait': ['kuwaiti', 'kuwait city'],
'laos': ['laotian', 'vientiane'],
'latvia': ['latvian', 'riga'],
'lebanon': ['lebanese', 'beirut'],
'libya': ['libyan', 'tripoli'],
'malaysia': ['malaysian', 'kuala lumpur'],
'maldives': ['maldivian', 'male'],
'mexico': ['mexican', 'mexico city'],
'mongolia': ['mongolian', 'ulaanbaatar'],
'morocco': ['moroccan', 'rabat'],
'myanmar': ['burmese', 'yangon'],
'nepal': ['nepali', 'kathmandu'],
'netherlands': ['dutch', 'amsterdam'],
'new zealand': ['kiwi', 'auckland', 'wellington'],
'nigeria': ['nigerian', 'lagos'],
'north korea': ['north korean', 'pyongyang'],
'norway': ['norwegian', 'oslo'],
'oman': ['omani', 'muscat'],
'pakistan': ['pakistani', 'karachi', 'lahore', 'islamabad'],
'palestine': ['palestinian', 'gaza'],
'philippines': ['filipino', 'manila'],
'poland': ['polish', 'warsaw'],
'portugal': ['portuguese', 'lisbon'],
'qatar': ['qatari', 'doha'],
'romania': ['romanian', 'bucharest'],
'russia': ['russian', 'moscow', 'saint petersburg'],
'saudi arabia': ['saudi', 'riyadh', 'jeddah'],
'singapore': ['singaporean', 'singapore'],
'south africa': ['south african', 'johannesburg', 'cape town'],
'south korea': ['korean', 'seoul', 'busan'],
'spain': ['spanish', 'madrid', 'barcelona'],
'sri lanka': ['sri lankan', 'colombo'],
'sudan': ['sudanese', 'khartoum'],
'sweden': ['swedish', 'stockholm'],
'switzerland': ['swiss', 'zurich', 'geneva'],
'syria': ['syrian', 'damascus'],
'taiwan': ['taiwanese', 'taipei'],
'thailand': ['thai', 'bangkok'],
'turkey': ['turkish', 'istanbul', 'ankara'],
'ukraine': ['ukrainian', 'kyiv'],
'united arab emirates': ['uae', 'dubai', 'abu dhabi'],
'united kingdom': ['uk', 'british', 'london', 'england', 'scotland', 'wales'],
'united states': ['usa', 'us', 'american', 'new york', 'los angeles', 'chicago'],
'vietnam': ['vietnamese', 'hanoi', 'ho chi minh city'],
'yemen': ['yemeni', 'sanaa']
};
// Initialize bot state from local storage
chrome.storage.local.get(['botRunning', 'targetCountries', 'notificationSound', 'greetingMessage', 'continuousMode'], (result) => {
if (result.targetCountries && Array.isArray(result.targetCountries)) {
targetCountries = result.targetCountries;
}
if (result.notificationSound !== undefined) {
notificationSound = result.notificationSound;
}
if (result.greetingMessage) {
greetingMessage = result.greetingMessage;
}
if (result.continuousMode !== undefined) {
continuousMode = result.continuousMode;
}
if (result.botRunning === true) {
startBot();
}
});
// Listen for messages from popup
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === 'START_BOT') {
// Update target countries if provided
if (message.targetCountries && Array.isArray(message.targetCountries)) {
targetCountries = message.targetCountries;
chrome.storage.local.set({ targetCountries });
}
// Update notification sound setting if provided
if (message.notificationSound !== undefined) {
notificationSound = message.notificationSound;
chrome.storage.local.set({ notificationSound });
}
// Update greeting message if provided
if (message.greetingMessage) {
greetingMessage = message.greetingMessage;
chrome.storage.local.set({ greetingMessage });
}
// Update continuous mode setting if provided
if (message.continuousMode !== undefined) {
continuousMode = message.continuousMode;
chrome.storage.local.set({ continuousMode });
}
startBot();
} else if (message.action === 'STOP_BOT') {
stopBot();
} else if (message.action === 'TOGGLE_SOUND') {
notificationSound = message.enabled;
chrome.storage.local.set({ notificationSound });
logMessage(`Sound notifications ${notificationSound ? 'enabled' : 'disabled'}`, 'info');
} else if (message.action === 'UPDATE_GREETING') {
greetingMessage = message.greetingMessage;
chrome.storage.local.set({ greetingMessage });
logMessage(`Greeting message updated to: "${greetingMessage}"`, 'info');
} else if (message.action === 'UPDATE_CONTINUOUS_MODE') {
continuousMode = message.continuousMode;
chrome.storage.local.set({ continuousMode });
logMessage(`Continuous mode ${continuousMode ? 'enabled' : 'disabled'}`, 'info');
}
});
// Log messages (sends to popup and shows in console)
function logMessage(message, type = 'info') {
console.log(`[Uhmegle Bot] ${message}`);
chrome.runtime.sendMessage({
action: 'LOG',
message: message,
type: type
});
}
// Start the bot monitoring
function startBot() {
if (botRunning) return;
botRunning = true;
foundTargetUser = false;
lastConnectionStatus = false;
chrome.storage.local.set({ botRunning: true });
logMessage(`Bot started monitoring for countries: ${targetCountries.join(', ')}`);
logMessage(`Continuous mode is ${continuousMode ? 'enabled' : 'disabled'}`);
botInterval = setInterval(checkStranger, CHECK_INTERVAL);
}
// Stop the bot
function stopBot() {
if (!botRunning) return;
botRunning = false;
foundTargetUser = false;
chrome.storage.local.set({ botRunning: false });
logMessage('Bot stopped monitoring');
if (botInterval) {
clearInterval(botInterval);
botInterval = null;
}
// Notify popup that bot status changed
chrome.runtime.sendMessage({
action: 'UPDATE_STATUS',
isRunning: false
});
}
// Check if we're connected to a stranger and process accordingly
function checkStranger() {
try {
// Check if we're connected to someone
const isConnected = checkIfConnected();
// Detect disconnection from target user
if (foundTargetUser && lastConnectionStatus && !isConnected) {
logMessage('Disconnected from target country user', 'info');
if (continuousMode) {
logMessage('Continuous mode active - resuming search for target countries', 'info');
foundTargetUser = false;
// Add a small delay before continuing
setTimeout(() => {
// Check if there's a "New Chat" or similar button to click
const buttons = document.querySelectorAll('button');
let newChatButton = null;
for (const btn of buttons) {
const btnText = btn.textContent.trim().toLowerCase();
if ((btn.offsetParent !== null) &&
(btnText.includes('new') || btnText.includes('start') || btnText.includes('chat'))) {
newChatButton = btn;
break;
}
}
if (newChatButton) {
newChatButton.click();
logMessage('Clicked "New Chat" button to resume searching', 'info');
}
}, 1000);
} else {
logMessage('Bot stopped after disconnection (continuous mode disabled)', 'info');
stopBot();
}
}
// Update last connection status
lastConnectionStatus = isConnected;
// Run page structure extraction occasionally for debugging
if (Math.random() < 0.1) { // 10% chance to run extraction each check
extractPageStructure();
}
if (!isConnected) {
if (!foundTargetUser) {
logMessage('Waiting for connection...', 'info');
}
return;
}
// Skip this check if we already found a target user
if (foundTargetUser) {
return;
}
// Get location info from the page
const locationInfo = getStrangerLocation();
if (!locationInfo) {
logMessage('Unable to detect location, waiting...', 'info');
return;
}
// Extract country and source from location info
const { country, source } = parseLocationInfo(locationInfo);
logMessage(`Detected location: ${country} (${source})`, 'info');
// Check if location matches any target country
if (isTargetCountry(country)) {
// Set flag that we found a target user immediately to prevent multiple matches
foundTargetUser = true;
// Add a small delay to ensure UI has stabilized
setTimeout(() => {
logMessage(`MATCH FOUND! User from ${country} (${source})`, 'success');
// Play sound notification
if (notificationSound) {
playNotificationSound();
}
// Show browser notification
showNotification('Target Country User Found!', `Location: ${country} (${source})`);
// Send the configured greeting message with a small delay to ensure notifications are shown first
setTimeout(() => {
logMessage(`Sending greeting: "${greetingMessage}"`, 'info');
sendMessage(greetingMessage);
// Give time for the message to be sent before potentially stopping the bot
if (!continuousMode) {
// If continuous mode is disabled, stop the bot after a delay to ensure message is sent
logMessage('Bot will stop in 5 seconds (continuous mode disabled)', 'info');
setTimeout(() => {
stopBot();
}, 5000);
} else {
logMessage('Continuous mode active - bot will continue after disconnection', 'info');
}
}, 1000);
}, 500); // Short delay of 500ms for UI stabilization
} else {
handleNonTargetUser(country);
}
} catch (error) {
logMessage(`Error: ${error.message}`, 'skip');
}
}
// Extract the location of the stranger from the page
function getStrangerLocation() {
// Method 1: Check for shared interests/tags in status messages
const statusLogs = document.querySelectorAll('.logitem, .statuslog');
for (const log of statusLogs) {
const text = log.textContent.toLowerCase();
// Look for "You both like..." or similar shared interests text
if (text.includes('you both like') || text.includes('you\'re now chatting with a random stranger') ||
text.includes('you have common interests')) {
// Generic check for any target country in shared interests
for (const country of targetCountries) {
const countryLower = country.toLowerCase();
if (text.includes(countryLower)) {
logMessage(`Found ${country} in shared interests: "${text}"`, 'info');
return `${country} (from shared interests)`;
}
// Special case handling for country variations
switch(countryLower) {
case 'bangladesh':
if (text.includes('dhaka') || text.includes('bd')) {
logMessage(`Found Bangladesh in shared interests: "${text}"`, 'info');
return 'Bangladesh (from shared interests)';
}
break;
case 'india':
if (text.includes('delhi') || text.includes('mumbai')) {
logMessage(`Found India in shared interests: "${text}"`, 'info');
return 'India (from shared interests)';
}
break;
case 'usa':
if (text.includes('american') || text.includes('united states') || text.includes('us ')) {
logMessage(`Found USA in shared interests: "${text}"`, 'info');
return 'USA (from shared interests)';
}
break;
case 'uk':
if (text.includes('britain') || text.includes('england') || text.includes('london')) {
logMessage(`Found UK in shared interests: "${text}"`, 'info');
return 'UK (from shared interests)';
}
break;
}
}
}
// Look for explicit country mentions in status logs
if (text.includes('country') || text.includes('location') || text.includes(' from ')) {
const countryText = log.textContent.trim();
// Check for each target country in the status message
for (const country of targetCountries) {
const countryLower = country.toLowerCase();
if (countryText.toLowerCase().includes(countryLower)) {
logMessage(`Found ${country} in status message: "${countryText}"`, 'info');
return `${country} (from status message)`;
}
}
return countryText;
}
}
// Method 2: Look for country flag indicator
const flagElements = document.querySelectorAll('img[alt*="flag"], .flag, [class*="flag"], [class*="country"]');
for (const flag of flagElements) {
// Check visible elements near the flag for country name
if (flag.offsetParent !== null) {
// Check the flag element itself
const flagAlt = flag.getAttribute('alt') || '';
const flagTitle = flag.getAttribute('title') || '';
const flagText = flag.textContent || '';
// Check for any target country in flag attributes
for (const country of targetCountries) {
const countryLower = country.toLowerCase();
if (flagAlt.toLowerCase().includes(countryLower) ||
flagTitle.toLowerCase().includes(countryLower) ||
flagText.toLowerCase().includes(countryLower)) {
logMessage(`Found ${country} flag indicator`, 'info');
return `${country} (from flag)`;
}
}
// If we found a flag with country info but it's not in our target countries,
// still return it for processing by isTargetCountry which has more advanced matching
if (flagAlt && (flagAlt.includes('flag') || flagTitle.includes('flag'))) {
const possibleCountry = flagAlt || flagTitle;
logMessage(`Found possible country flag: ${possibleCountry}`, 'info');
return possibleCountry;
}
// Check surrounding elements (parent and siblings)
const parent = flag.parentElement;
if (parent) {
const parentText = parent.textContent.toLowerCase();
// Check for any target country in parent text
for (const country of targetCountries) {
const countryLower = country.toLowerCase();
if (parentText.includes(countryLower)) {
logMessage(`Found ${country} in flag parent element`, 'info');
return `${country} (from flag parent)`;
}
}
// Check siblings
const siblings = Array.from(parent.children);
for (const sibling of siblings) {
const siblingText = sibling.textContent.toLowerCase();
// Check for any target country in sibling text
for (const country of targetCountries) {
const countryLower = country.toLowerCase();
if (siblingText.includes(countryLower)) {
logMessage(`Found ${country} in flag sibling element`, 'info');
return `${country} (from flag sibling)`;
}
}
}
}
}
}
// Method 3: Check if the stranger has mentioned their country in chat
const strangerMsgs = document.querySelectorAll('.strangermsg');
for (const msg of strangerMsgs) {
const text = msg.textContent.toLowerCase();
// Check for country mentions in messages
for (const country of targetCountries) {
const countryLower = country.toLowerCase();
if (text.includes(countryLower)) {
logMessage(`Found ${country} in chat message: "${text}"`, 'info');
return `${country} (from chat message)`;
}
// Special case handling for country variations in chat
switch(countryLower) {
case 'usa':
if (text.includes('american') || text.includes('united states') || (text.includes('us') && !text.includes('use'))) {
logMessage(`Found USA in chat message: "${text}"`, 'info');
return 'USA (from chat message)';
}
break;
case 'uk':
if (text.includes('britain') || text.includes('england') || text.includes('london')) {
logMessage(`Found UK in chat message: "${text}"`, 'info');
return 'UK (from chat message)';
}
break;
}
}
// Check for location patterns in messages
const countryPatterns = [
/i(?:'|'|'m|\s+am)\s+from\s+(\w+)/i,
/from\s+(\w+)/i,
/i(?:'|'|m|\s+am)\s+in\s+(\w+)/i
];
for (const pattern of countryPatterns) {
const match = text.match(pattern);
if (match && match[1]) {
const possibleCountry = match[1].trim();
logMessage(`Possible country mention: "${possibleCountry}" in "${text}"`, 'info');
return `${possibleCountry} (from chat pattern)`;
}
}
}
// Method 4: Look specifically for elements containing shared interests
const allElements = document.querySelectorAll('*');
for (const elem of allElements) {
if (elem.offsetParent !== null) { // Only consider visible elements
const text = elem.textContent.trim().toLowerCase();
if (text.includes('you both like') || text.includes('common interests')) {
// Check for any target country in shared interests
for (const country of targetCountries) {
const countryLower = country.toLowerCase();
if (text.includes(countryLower)) {
logMessage(`Found ${country} in shared interests element: "${text}"`, 'info');
return `${country} (from interests)`;
}
// Special cases for common variations
switch(countryLower) {
case 'bangladesh':
if (text.includes('dhaka') || text.includes('bd')) {
logMessage(`Found Bangladesh in shared interests element: "${text}"`, 'info');
return 'Bangladesh (from interests)';
}
break;
case 'india':
if (text.includes('delhi') || text.includes('mumbai')) {
logMessage(`Found India in shared interests element: "${text}"`, 'info');
return 'India (from interests)';
}
break;
case 'usa':
if (text.includes('american') || text.includes('united states')) {
logMessage(`Found USA in shared interests element: "${text}"`, 'info');
return 'USA (from interests)';
}
break;
case 'uk':
if (text.includes('britain') || text.includes('england') || text.includes('london')) {
logMessage(`Found UK in shared interests element: "${text}"`, 'info');
return 'UK (from interests)';
}
break;
case 'australia':
if (text.includes('aussie') || text.includes('sydney')) {
logMessage(`Found Australia in shared interests element: "${text}"`, 'info');
return 'Australia (from interests)';
}
break;
}
}
}
}
}
// If we can't find specific location but we're connected, use placeholder
if (checkIfConnected()) {
return "Unknown Location";
}
return null;
}
// Parse location info into country and source
function parseLocationInfo(locationInfo) {
// Handle the case where locationInfo is already a detected location with source
if (locationInfo.includes('(from')) {
const parts = locationInfo.split('(from');
return {
country: parts[0].trim().toLowerCase(),
source: `from ${parts[1].replace(')', '').trim()}`
};
}
// Handle the case where it might contain a country name
for (const country of targetCountries) {
const countryLower = country.toLowerCase();
if (locationInfo.toLowerCase().includes(countryLower)) {
return {
country: country.toLowerCase(),
source: 'detected in text'
};
}
// Special cases for country variations
switch(countryLower) {
case 'usa':
if (locationInfo.toLowerCase().includes('american') ||
locationInfo.toLowerCase().includes('united states') ||
locationInfo.toLowerCase().includes('us ')) {
return {
country: 'usa',
source: 'detected variation'
};
}
break;
case 'uk':
if (locationInfo.toLowerCase().includes('britain') ||
locationInfo.toLowerCase().includes('england') ||
locationInfo.toLowerCase().includes('london')) {
return {
country: 'uk',
source: 'detected variation'
};
}
break;
}
}
// Default case - just the location string
return {
country: locationInfo.toLowerCase(),
source: 'detected'
};
}
// Check if the location matches any target country
function isTargetCountry(location) {
if (!location) return false;
const text = location.toLowerCase();
logMessage(`Checking if "${text}" matches any target country: ${targetCountries.join(', ')}`, 'info');
// Check for each target country
for (const country of targetCountries) {
const countryLower = country.toLowerCase();
// Get variations for this country
const variations = COUNTRY_VARIATIONS[countryLower] || [];
// Check exact match
if (text === countryLower) {
logMessage(`Found exact match for country: ${country}`, 'info');
return true;
}
// Check if text contains the country name
if (text.includes(countryLower)) {
logMessage(`Found country name in text: ${country}`, 'info');
return true;
}
// Check all variations
for (const variation of variations) {
if (text.includes(variation.toLowerCase())) {
logMessage(`Found country variation: ${variation} for ${country}`, 'info');
return true;
}
}
}
logMessage(`No match found for: ${text}`, 'info');
return false;
}
// Handle a non-target country user
function handleNonTargetUser(location) {
logMessage(`Skipping user from ${location}`, 'skip');
// Click the skip button to move to next user
skipUser();
}
// Check if we're connected to a stranger
function checkIfConnected() {
// Method 1: Check for active chat input
const chatInput = document.querySelector('textarea') ||
document.querySelector('input[type="text"]');
if (chatInput && !chatInput.disabled) {
return true;
}
// Method 2: Check for specific status messages
const statusLogs = document.querySelectorAll('.logitem, .statuslog');
for (const log of statusLogs) {
const text = log.textContent.toLowerCase();
if (text.includes('connected') ||
text.includes('you\'re now chatting with') ||
text.includes('stranger is typing') ||
text.includes('you: ') ||
text.includes('stranger: ')) {
return true;
}
}
// Method 3: Check for disconnect/skip button
const buttons = document.querySelectorAll('button');
for (const button of buttons) {
const text = button.textContent.toLowerCase();
if ((button.offsetParent !== null) && // is visible
(text.includes('disconnect') || text.includes('stop') ||
text.includes('next') || text.includes('skip'))) {
return true;
}
}
// Method 4: Check if stranger has sent a message
const strangerMsgs = document.querySelectorAll('.strangermsg');
if (strangerMsgs && strangerMsgs.length > 0) {
return true;
}
return false;
}
// Send a message in the chat
function sendMessage(text) {
try {
logMessage(`Attempting to send message: "${text}"`, 'info');
// Find the chat input field using multiple strategies
let chatInput = null;
// METHOD 1: Try common chat input selectors
const potentialInputs = [
'textarea.chatmsg',
'#chatmsg',
'textarea[name="chatmsg"]',
'input.chatmsg',
'input[type="text"]',
'textarea'
];
for (const selector of potentialInputs) {
const found = document.querySelector(selector);
if (found && found.offsetParent !== null) {
chatInput = found;
logMessage(`Found chat input using selector: ${selector}`, 'info');
break;
}
}
if (!chatInput) {
// METHOD 2: Find any enabled text input that looks like a chat box
const allInputs = Array.from(document.querySelectorAll('textarea, input[type="text"]'));
const visibleInputs = allInputs.filter(input => !input.disabled && input.offsetParent !== null);
if (visibleInputs.length > 0) {
// Prefer textareas over inputs as they're more commonly used for chat
const textareas = visibleInputs.filter(el => el.tagName.toLowerCase() === 'textarea');
if (textareas.length > 0) {
chatInput = textareas[0];
logMessage('Using first visible textarea as chat input', 'info');
} else {
chatInput = visibleInputs[0];
logMessage('Using first visible text input as chat input', 'info');
}
}
}
if (!chatInput) {
throw new Error('Chat input not found');
}
// Make sure the input is focused and clear any existing text
chatInput.focus();
chatInput.click();
chatInput.value = '';
// Now set the new value
chatInput.value = text;
// Dispatch events to simulate real typing
const events = ['input', 'change', 'keydown', 'keypress', 'keyup'];
events.forEach(eventType => {
const event = new Event(eventType, { bubbles: true });
chatInput.dispatchEvent(event);
});
// Find and click the send button using multiple strategies
let sendButton = null;
// METHOD 1: Common send button selectors
const potentialButtons = [
'button.sendbtn',
'button[data-key="enter"]',
'input[type="submit"]',
'button[type="submit"]',
'button#send',
'button.send',
'button.sendButton'
];
for (const selector of potentialButtons) {
const found = document.querySelector(selector);
if (found && found.offsetParent !== null) {
sendButton = found;
logMessage(`Found send button using selector: ${selector}`, 'info');
break;
}
}
// METHOD 2: Find by text content
if (!sendButton) {
const buttons = Array.from(document.querySelectorAll('button'));
const visibleButtons = buttons.filter(btn => btn.offsetParent !== null);
for (const btn of visibleButtons) {
const btnText = btn.textContent.trim().toLowerCase();
if (btnText === 'send' || btnText === '>' || btnText.includes('send')) {
sendButton = btn;
logMessage(`Found send button by text: ${btnText}`, 'info');
break;
}
}
}
// METHOD 3: Look for a button near the chat input
if (!sendButton) {
// Try to find a nearby button (often the send button is adjacent to the input)
let currentNode = chatInput;
// Look up through 3 parent levels to find nearby buttons
for (let i = 0; i < 3; i++) {
if (!currentNode.parentElement) break;
currentNode = currentNode.parentElement;
const nearbyButtons = Array.from(currentNode.querySelectorAll('button'))
.filter(btn => btn.offsetParent !== null);
if (nearbyButtons.length > 0) {
// Prefer buttons positioned to the right of the input (common pattern)
sendButton = nearbyButtons[nearbyButtons.length - 1];
logMessage('Using button near chat input as send button', 'info');
break;
}
}
}
// First try clicking the send button if found
if (sendButton) {
// Create and dispatch proper mouse events for more reliable clicking
['mousedown', 'mouseup', 'click'].forEach(eventType => {
const clickEvent = new MouseEvent(eventType, {
bubbles: true,
cancelable: true,
view: window
});
sendButton.dispatchEvent(clickEvent);
});
logMessage(`Message sent via button click: "${text}"`, 'info');
} else {
// Fallback: Try to submit by pressing Enter key
['keydown', 'keypress', 'keyup'].forEach(eventType => {
const keyEvent = new KeyboardEvent(eventType, {
key: 'Enter',
code: 'Enter',
which: 13,
keyCode: 13,
bubbles: true,
cancelable: true
});
chatInput.dispatchEvent(keyEvent);
});
logMessage(`Message sent by pressing Enter: "${text}"`, 'info');
}
// Final fallback: If there's a form, try to submit it
const form = chatInput.closest('form');
if (form) {
const submitEvent = new Event('submit', { bubbles: true, cancelable: true });
form.dispatchEvent(submitEvent);
logMessage('Attempted form submission as final fallback', 'info');
}
// Confirm message was sent by checking if input was cleared
setTimeout(() => {
if (chatInput.value === '') {
logMessage('Message successfully sent (input field cleared)', 'success');
} else if (chatInput.value === text) {
logMessage('Message may not have been sent (input field not cleared)', 'skip');
// Try one more time with Enter key
chatInput.dispatchEvent(new KeyboardEvent('keypress', {
key: 'Enter',
code: 'Enter',
which: 13,
keyCode: 13,
bubbles: true
}));
}
}, 500);
return true;
} catch (error) {
logMessage(`Failed to send message: ${error.message}`, 'skip');
return false;
}
}
// Click the skip button to move to next user
function skipUser() {
try {
// Find all buttons on the page
const allButtons = Array.from(document.querySelectorAll('button'));
let skipButton = null;
// METHOD 1: Find by common skip/disconnect button text
const skipButtonTexts = ['skip', 'next', 'disconnect', 'stop', 'new'];
for (const btn of allButtons) {
const btnText = btn.textContent.trim().toLowerCase();
// Check if this button has skip-related text and is visible
if (skipButtonTexts.some(text => btnText.includes(text)) && btn.offsetParent !== null) {
skipButton = btn;
logMessage(`Found skip button by text: ${btnText}`, 'info');
break;
}
}
// METHOD 2: Find by key attributes
if (!skipButton) {
skipButton = document.querySelector('button[data-key="esc"]') ||
document.querySelector('button.disconnectbtn') ||
document.querySelector('#disconnectbtn') ||
document.querySelector('.skipbtn');
if (skipButton && skipButton.offsetParent !== null) {
logMessage('Found skip button by attribute', 'info');
} else {
skipButton = null;
}
}
// METHOD 3: Try to find by position or appearance
if (!skipButton) {
// In many chat sites, the skip button is at the bottom or right side
// Check for buttons that are visible and might be positioned at the bottom
const visibleButtons = allButtons.filter(btn => btn.offsetParent !== null);
if (visibleButtons.length > 0) {
// Often the skip button is the last visible button or has specific styling
skipButton = visibleButtons[visibleButtons.length - 1];
logMessage('Using last visible button as skip button (fallback)', 'info');
}
}
if (skipButton) {
// Click the skip button
skipButton.click();
logMessage('Skipped to next user', 'info');
// Additional safety measure: add a small delay to prevent rapid skipping
setTimeout(() => {
// Force reload connections if needed
const startButtons = document.querySelectorAll('button');
for (const btn of startButtons) {
const btnText = btn.textContent.trim().toLowerCase();
if (btnText.includes('start') || btnText.includes('new chat') || btnText.includes('new')) {
if (btn.offsetParent !== null) {
btn.click();
logMessage('Clicked start/new chat button', 'info');
break;
}
}
}
}, 300);
return true;
}
throw new Error('Skip button not found with any method');
} catch (error) {
logMessage(`Failed to skip user: ${error.message}`, 'skip');
// Try keyboard shortcuts as fallback
try {
// Try pressing Escape key
document.dispatchEvent(new KeyboardEvent('keydown', {
key: 'Escape',
code: 'Escape',
which: 27,
keyCode: 27,
bubbles: true
}));
logMessage('Attempted to skip using Escape key', 'info');