Speedo0o commited on
Commit
dd22c73
ยท
verified ยท
1 Parent(s): 3576075

Update openShrinkNew.py

Browse files
Files changed (1) hide show
  1. openShrinkNew.py +631 -1
openShrinkNew.py CHANGED
@@ -399,4 +399,634 @@ async def instant_button_watcher(page):
399
  try:
400
  for sel in selectors:
401
  # 1. ุงู„ุจุญุซ ููŠ ุงู„ุตูุญุฉ ุงู„ุฑุฆูŠุณูŠุฉ
402
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
399
  try:
400
  for sel in selectors:
401
  # 1. ุงู„ุจุญุซ ููŠ ุงู„ุตูุญุฉ ุงู„ุฑุฆูŠุณูŠุฉ
402
+ loc = page.locator(sel).first
403
+ if await loc.is_visible():
404
+ await loc.click(force=True)
405
+ print(f"\n[โšก] ุชู… ุงุตุทูŠุงุฏ ุงู„ุฒุฑ ุงู„ุณุฑูŠุน ูˆุฅุบู„ุงู‚ู‡ (Main Page)!")
406
+ await asyncio.sleep(1) # ุงุณุชุฑุงุญุฉ ู‚ุตูŠุฑุฉ ุจุนุฏ ุงู„ุถุบุท
407
+
408
+ # 2. ุงู„ุจุญุซ ุฏุงุฎู„ ุงู„ุฅุทุงุฑุงุช (Frames)
409
+ for frame in page.frames:
410
+ try:
411
+ f_loc = frame.locator(sel).first
412
+ if await f_loc.is_visible():
413
+ await f_loc.click(force=True)
414
+ print(f"\n[โšก] ุชู… ุงุตุทูŠุงุฏ ุงู„ุฒุฑ ุงู„ุณุฑูŠุน ูˆุฅุบู„ุงู‚ู‡ (Iframe)!")
415
+ await asyncio.sleep(1)
416
+ except Exception:
417
+ continue
418
+ except Exception:
419
+ pass
420
+
421
+ # ูุญุต ุณุฑูŠุน ุฌุฏุงู‹ ูƒู„ 0.3 ุซุงู†ูŠุฉ
422
+ await asyncio.sleep(0.3)
423
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
424
+ # ุงู„ุฏุงู„ุฉ ุงู„ุฑุฆูŠุณูŠุฉ
425
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
426
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
427
+ # ู…ุฑุงู‚ุจ ุฒุฑ "Check Again" (ูŠุนู…ู„ ููŠ ุงู„ุฎู„ููŠุฉ ุฏุงุฆู…ุงู‹)
428
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
429
+ async def recheck_button_watcher(page):
430
+ selectors = [
431
+ "button[data-action='recheck']",
432
+ "button:has-text('Check Again')",
433
+ "xpath=//button[contains(normalize-space(.), 'Check Again')]"
434
+ ]
435
+ while True:
436
+ try:
437
+ for sel in selectors:
438
+ loc = page.locator(sel).first
439
+ if await loc.is_visible(timeout=500):
440
+ await loc.click(force=True)
441
+ print("\n[โ™ป๏ธ] ุชู… ุงุตุทูŠุงุฏ ุฒุฑ 'Check Again' ุงู„ู…ุฒุนุฌ ูˆุงู„ุถุบุท ุนู„ูŠู‡!")
442
+ await asyncio.sleep(2.5) # ุงุณุชุฑุงุญุฉ ุจุนุฏ ุงู„ุถุบุท ู„ุชุญุฏูŠุซ ุงู„ุตูุญุฉ
443
+ except:
444
+ pass
445
+ await asyncio.sleep(1) # ูุญุต ูƒู„ ุซุงู†ูŠุฉ
446
+
447
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
448
+ # ุฏุงู„ุฉ ุงู„ุฑุคูŠุฉ ุงู„ุจุตุฑูŠุฉ (Computer Vision) ุงู„ู…ุญุฏุซุฉ
449
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
450
+ async def visual_click(page, template_filename="box.png", max_attempts=1):
451
+ template_path = os.path.join(base_path, template_filename)
452
+ if not os.path.exists(template_path):
453
+ print(f"[โŒ] ู…ุณุงุฑ ุงู„ุตูˆุฑุฉ ุบูŠุฑ ู…ูˆุฌูˆุฏ: {template_path}")
454
+ return False
455
+
456
+ template = cv2.imread(template_path, cv2.IMREAD_GRAYSCALE)
457
+ tH, tW = template.shape[:2]
458
+
459
+ for attempt in range(1, max_attempts + 1):
460
+ try:
461
+ screenshot_bytes = await page.screenshot()
462
+ nparr = np.frombuffer(screenshot_bytes, np.uint8)
463
+ img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
464
+ gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
465
+
466
+ best_match = None
467
+ for scale in np.linspace(0.5, 2.5, 25):
468
+ width = int(tW * scale)
469
+ height = int(tH * scale)
470
+ if width <= 10 or height <= 10: continue
471
+ resized_template = cv2.resize(template, (width, height))
472
+
473
+ if resized_template.shape[0] > gray_img.shape[0] or resized_template.shape[1] > gray_img.shape[1]:
474
+ continue
475
+
476
+ res = cv2.matchTemplate(gray_img, resized_template, cv2.TM_CCOEFF_NORMED)
477
+ _, max_val, _, max_loc = cv2.minMaxLoc(res)
478
+
479
+ if best_match is None or max_val > best_match[0]:
480
+ best_match = (max_val, max_loc, scale, width, height)
481
+
482
+ if best_match and best_match[0] >= 0.70:
483
+ max_val, max_loc, best_scale, w, h = best_match
484
+ print(f"[๐ŸŽฏ] ุชู… ุงู„ุฑุตุฏ ุงู„ุจุตุฑูŠ! ุงู„ุชุทุงุจู‚: {max_val*100:.1f}%")
485
+
486
+ click_x = int(max_loc[0] + (w / 2))
487
+ click_y = int(max_loc[1] + (h / 2))
488
+
489
+ await page.mouse.move(click_x, click_y, steps=10)
490
+ await asyncio.sleep(0.3)
491
+ await page.mouse.down()
492
+ await asyncio.sleep(random.uniform(0.08, 0.15))
493
+ await page.mouse.up()
494
+
495
+ print("[โœ…] ุชู… ุงู„ู†ู‚ุฑ ุงู„ุจุตุฑูŠ ุจู†ุฌุงุญ!")
496
+ return True
497
+ except Exception as e:
498
+ pass
499
+ await asyncio.sleep(1)
500
+
501
+ return False
502
+
503
+ async def main():
504
+ user_data_dir = Path(USER_DATA_DIR)
505
+ if RESET_PROFILE_ON_START and user_data_dir.exists():
506
+ shutil.rmtree(user_data_dir)
507
+ user_data_dir.mkdir(exist_ok=True)
508
+
509
+ async with async_playwright() as p:
510
+ # โ”€โ”€ 1. ูุญุต IP ุนุจุฑ ุงู„ุจุฑูˆูƒุณูŠ (ู…ู† cut_prim) โ”€โ”€
511
+ print("\n[๐Ÿ”] ุฌุงุฑูŠ ูุญุต ุงู„ู€ IP ุนุจุฑ ุจุฑูˆูƒุณูŠ SOCKS5...")
512
+ ip_data = {}
513
+ real_tz = "UTC"
514
+ real_locale = "en-US"
515
+ try:
516
+ req_ctx = await p.request.new_context(proxy={"server": "socks5://127.0.0.1:23321"})
517
+ resp = await req_ctx.get("http://ip-api.com/json/", timeout=int(15_000 * TM))
518
+ ip_data = await resp.json()
519
+ await req_ctx.dispose()
520
+ except Exception:
521
+ pass
522
+
523
+ if ip_data.get("status") == "success":
524
+ real_tz = ip_data.get("timezone", "UTC")
525
+ country_code = ip_data.get("countryCode", "US")
526
+ real_langs = COUNTRY_LOCALES.get(country_code, [f"en-{country_code}", "en-US", "en"])
527
+ real_locale = real_langs[0]
528
+ print(f"[๐ŸŒ] IP ู…ูุญุฏูŽู‘ุฏ | ุงู„ุฏูˆู„ุฉ: {country_code} | ุงู„ู…ู†ุทู‚ุฉ: {real_tz} | ุงู„ู„ุบุฉ: {real_locale}")
529
+ else:
530
+ print("[โš ๏ธ] ูุดู„ ุชุญุฏูŠุฏ ุงู„ู€ IP โ€” ุณูŠุชู… ุงุณุชุฎุฏุงู… ุงู„ุฅุนุฏุงุฏุงุช ุงู„ุงูุชุฑุงุถูŠุฉ")
531
+
532
+ # โ”€โ”€ 2. ุชูˆู„ูŠุฏ ุงู„ุจุตู…ุฉ ุงู„ุดุงู…ู„ุฉ ูˆุงู„ูˆุงู‚ุนูŠุฉ (Anti-Intercept V4 - Mixed Edition) โ”€โ”€
533
+ # ุฒูŠุงุฏุฉ ู†ุทุงู‚ ุงู„ู€ Seed ู„ุถู…ุงู† ุนุฏู… ุชูƒุฑุงุฑ ุงู„ุจุตู…ุฉ ุชู…ุงู…ุงู‹ ููŠ 10 ุขู„ุงู ุชุดุบูŠู„ุฉ
534
+ fingerprint_seed = random.randint(10000000, 99999999)
535
+
536
+ # ุชุญุฏูŠุฏ ุฅุตุฏุงุฑ ุงู„ู…ุชุตูุญ: 90% ู„ู„ุฅุตุฏุงุฑ 149 ูˆ 10% ู„ู„ุฅุตุฏุงุฑ 148
537
+ chrome_version = "150" if random.random() < 0.90 else "149"
538
+ full_version = f"{chrome_version}.0.0.0"
539
+
540
+ # ุชุญุฏูŠุฏ ู†ูˆุน ุงู„ุฌู‡ุงุฒ: 80% ู‡ูˆุงุชูุŒ 20% ูˆูŠู†ุฏูˆุฒ
541
+ is_mobile_device = random.random() < 0.87
542
+
543
+ if is_mobile_device:
544
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
545
+ # โ”€โ”€ ุฅุนุฏุงุฏุงุช ุงู„ู‡ูˆุงุชู (Android) - 80%
546
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
547
+ platform_choice = "linux" # ุงู„ู…ู†ุตุฉ ุงู„ุชู‚ู†ูŠุฉ ุงู„ุฃู‚ุฑุจ ู„ู„ุฃู†ุฏุฑูˆูŠุฏ
548
+ is_mobile_mode = True
549
+ has_touch_mode = True
550
+ brand_choice = "Chrome"
551
+
552
+ # ุงุณุชุฎุฏุงู… ุงู„ุจุตู…ุฉ ุงู„ู…ุฌู…ุฏุฉ (Frozen UA) ู„ุฌู…ูŠุน ู‡ูˆุงุชู ุงู„ุฃู†ุฏุฑูˆูŠุฏ ู„ุชูƒูˆู† ุทุจูŠุนูŠุฉ 100%
553
+ user_agent = f"Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/{full_version} Mobile Safari/537.36"
554
+
555
+ MOBILE_SCREENS = [
556
+ (360, 800), (384, 854), (390, 844), (393, 852),
557
+ (412, 915), (414, 896), (428, 926), (430, 932)
558
+ ]
559
+ # ุฃูˆุฒุงู† ู„ุฃุจุนุงุฏ ุดุงุดุงุช ุงู„ู…ูˆุจุงูŠู„
560
+ vp_w, vp_h = random.choices(MOBILE_SCREENS, weights=[20, 10, 20, 20, 10, 10, 5, 5])[0]
561
+ print(f"[๐Ÿ“ฑ] ู†ูˆุน ุงู„ุจุตู…ุฉ: ู‡ุงุชู (Android 10 Frozen UA)")
562
+
563
+ else:
564
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
565
+ # โ”€โ”€ ุฅุนุฏุงุฏุงุช ุงู„ูˆูŠู†ุฏูˆุฒ (Desktop) - 20%
566
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
567
+ platform_choice = "windows"
568
+ is_mobile_mode = False
569
+ has_touch_mode = False
570
+
571
+ # ุชุญุฏูŠุฏ ุงู„ู…ุชุตูุญ ู„ู„ูˆูŠู†ุฏูˆุฒ: 80% ูƒุฑูˆู…ุŒ 20% ุฅูŠุฏุฌ
572
+ if random.random() < 0.80:
573
+ brand_choice = "Chrome"
574
+ user_agent = f"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/{full_version} Safari/537.36"
575
+ print(f"[๐Ÿ’ป] ู†ูˆุน ุงู„ุจุตู…ุฉ: ูƒู…ุจูŠูˆุชุฑ ู…ูƒุชุจูŠ (Windows - Chrome)")
576
+ else:
577
+ brand_choice = "Edge"
578
+ # ุตูŠุบุฉ User-Agent ุงู„ุฎุงุตุฉ ุจู…ุชุตูุญ ุฅูŠุฏุฌ
579
+ user_agent = f"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/{full_version} Safari/537.36 Edg/{full_version}"
580
+ print(f"[๐Ÿ’ป] ู†ูˆุน ุงู„ุจุตู…ุฉ: ูƒู…ุจูŠูˆุชุฑ ู…ูƒุชุจูŠ (Windows - Edge)")
581
+
582
+ DESKTOP_SCREENS = [
583
+ (1920, 1080), (1366, 768), (1536, 864), (1440, 900), (1280, 720), (2560, 1440)
584
+ ]
585
+ # ุชูˆุฒูŠุน ู…ู†ุทู‚ูŠ ู„ุฃุจุนุงุฏ ุดุงุดุงุช ุงู„ูƒู…ุจูŠูˆุชุฑ: 1080p ูˆ 768p ู‡ู…ุง ุงู„ุฃูƒุซุฑ ุดูŠูˆุนุงู‹ ุนุงู„ู…ูŠุงู‹
586
+ vp_w, vp_h = random.choices(DESKTOP_SCREENS, weights=[50, 20, 15, 8, 5, 2])[0]
587
+
588
+ print(f"[๐ŸŽญ] Seed: {fingerprint_seed} | Platform: {platform_choice} | Brand: {brand_choice} | Version: {full_version}")
589
+ print(f"[๐ŸŒ] UA: {user_agent}")
590
+ print(f"[๐Ÿ–ฅ๏ธ] ุงู„ุฃุจุนุงุฏ: {vp_w}x{vp_h}")
591
+
592
+ # โ”€โ”€ 3. ุฅุนุฏุงุฏ ุฃูˆุงู…ุฑ ุงู„ู…ุชุตูุญ โ”€โ”€
593
+ browser_args = [
594
+ f"--fingerprint={fingerprint_seed}",
595
+ f"--fingerprint-platform={platform_choice}",
596
+ f"--fingerprint-brand={brand_choice}",
597
+ f"--fingerprint-brand-version={chrome_version}",
598
+ f"--timezone={real_tz}",
599
+ f"--lang={real_locale}",
600
+ f"--accept-lang={real_locale},en",
601
+ f"--user-agent={user_agent}",
602
+ # ุฃูˆุงู…ุฑ ุงู„ุชุฎููŠ
603
+ "--disable-blink-features=AutomationControlled",
604
+ "--no-sandbox",
605
+ "--disable-dev-shm-usage",
606
+ "--disable-infobars",
607
+ "--no-first-run",
608
+ "--no-default-browser-check",
609
+ "--mute-audio",
610
+ "--disable-popup-blocking",
611
+ # ุชุญู…ูŠู„ ุฅุถุงูุฉ ุงู„ูƒุงุจุชุดุง
612
+ f"--disable-extensions-except={EXTENSION_PATH}",
613
+ f"--load-extension={EXTENSION_PATH}",
614
+ ]
615
+
616
+ # ุชุนุทูŠู„ ุชุฒูŠูŠู ุงู„ู€ GPU ู„ู„ู‡ูˆุงุชู ู„ุชุฌู†ุจ ุชุณุฑูŠุจ ูƒุงุฑุช ุงู„ุดุงุดุฉ ุงู„ู…ูƒุชุจูŠ
617
+ if is_mobile_mode:
618
+ browser_args.append("--disable-spoofing=gpu")
619
+
620
+ proxy_settings = {"server": "socks5://127.0.0.1:23321"}
621
+
622
+ # โ”€โ”€ 4. ุชุดุบูŠู„ ุงู„ู…ุชุตูุญ ุงู„ู…ุนุฏู„ โ”€โ”€
623
+ context = await p.chromium.launch_persistent_context(
624
+ user_data_dir=str(user_data_dir),
625
+ executable_path=CUSTOM_CHROMIUM_PATH,
626
+ headless=False,
627
+ proxy=proxy_settings,
628
+ args=browser_args,
629
+ no_viewport=False,
630
+ viewport={"width": vp_w, "height": vp_h},
631
+ is_mobile=is_mobile_mode,
632
+ has_touch=has_touch_mode,
633
+ java_script_enabled=True,
634
+ ignore_https_errors=True,
635
+ )
636
+
637
+
638
+
639
+
640
+
641
+
642
+ page = context.pages[0] if context.pages else await context.new_page()
643
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
644
+ # ู†ุธุงู… ุงู„ุชุฎููŠ ุงู„ุนู…ูŠู‚ ูˆุชุฏู…ูŠุฑ Anti-Adblock
645
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
646
+
647
+
648
+
649
+ # โ”€โ”€ 5. ูุชุญ ุงู„ู…ูˆู‚ุน ู…ุน ุงู„ุฑูŠููŠุฑ (ู…ู† cut_prim) โ”€โ”€
650
+ # ... (ุจุงู‚ูŠ ูƒูˆุฏูƒ ุงู„ู‚ุฏูŠู… ูŠูƒู…ู„ ู…ู† ู‡ู†ุง ุจุดูƒู„ ุทุจูŠุนูŠ) ...
651
+
652
+
653
+
654
+
655
+
656
+
657
+
658
+
659
+
660
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
661
+ # ู†ุธุงู… ุงู„ุงุญุชู…ุงู„ุงุช ุงู„ุฏู‚ูŠู‚ (50% ูุดู„ ูƒู„ูŠุŒ 40% ุงุฑุชุฏุงุฏุŒ 10% ู†ุฌุงุญ)
662
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
663
+ rand_val = random.random()
664
+ action_type = ""
665
+
666
+ if rand_val < 0.00:
667
+ # 0% ูุดู„ ูƒู„ูŠ (ุชู… ุฅู„ุบุงุคู‡)
668
+ action_type = "hard_fail"
669
+ elif rand_val < 0.00:
670
+ # 0% ูุดู„ ุฌุฒุฆูŠ (ุชู… ุฅู„ุบุงุคู‡)
671
+ action_type = "soft_fail"
672
+ else:
673
+ # 100% ู†ุฌุงุญ ุชูุงุนู„ูŠ ูƒุงู…ู„ ุฏุงุฆู…ุงู‹
674
+ action_type = "success"
675
+
676
+ if action_type == "hard_fail":
677
+ print("\n[๐Ÿ’ฅ] ูุดู„ ูƒู„ูŠ (50%): ุชู… ุชูุนูŠู„ ุงู„ุฅู„ุบุงุก ุงู„ู…ุจูƒุฑ. ู„ู† ูŠุชู… ูุชุญ ุงู„ุฑุงุจุท ุฃุตู„ุงู‹.")
678
+ await context.close()
679
+ if user_data_dir.exists():
680
+ try:
681
+ await asyncio.sleep(1.0)
682
+ shutil.rmtree(user_data_dir)
683
+ print("[๐Ÿ—‘๏ธ] ุชู… ุชู†ุธูŠู ุงู„ู†ุธุงู… ูˆุฅุบู„ุงู‚ ุงู„ุณูƒุฑุจุช.")
684
+ except Exception: pass
685
+ return # ุฅู†ู‡ุงุก ุงู„ุณูƒุฑุจุช ููˆุฑุงู‹
686
+
687
+ print(f"\n[โณ] ู‚ุฑุงุฑ ุงู„ู†ุธุงู…: {'ุงุฑุชุฏุงุฏ (ูุดู„ ุฌุฒุฆูŠ)' if action_type == 'soft_fail' else 'ู†ุฌุงุญ ุชูุงุนู„ูŠ'}... ุฌุงุฑูŠ ุงู„ู…ุชุงุจุนุฉ.")
688
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
689
+
690
+ # โ”€โ”€ 5. ูุชุญ ุงู„ู…ูˆู‚ุน ู…ุน ุงู„ุฑูŠููŠุฑ (ุงู„ุชูˆุฌูŠู‡ ุงู„ุทุจูŠุนูŠ ู„ู…ุญุงูƒุงุฉ ุงู„ู…ุณุชุฎุฏู…) โ”€โ”€
691
+ selected_referrer = random.choice(SOCIAL_REFERRERS)
692
+ chosen_referrer = selected_referrer["url"]
693
+ referrer_name = selected_referrer["name"]
694
+
695
+ print(f"\n[๐Ÿ”—] ูุชุญ ู…ูˆู‚ุน ุงู„ุฑูŠููŠุฑ ุฃูˆู„ุงู‹: {referrer_name} ({chosen_referrer})")
696
+ try:
697
+ await page.goto(chosen_referrer, wait_until="domcontentloaded", timeout=PAGE_LOAD_TIMEOUT)
698
+ await asyncio.sleep(random.uniform(2.5, 4.5))
699
+
700
+ print(f"[๐Ÿš€] ุงู„ุงู†ุชู‚ุงู„ ุทุจูŠุนูŠุงู‹ ุฅู„ู‰ ุงู„ู…ูˆู‚ุน ุงู„ู…ุณุชู‡ุฏู: {TARGET_URL}")
701
+ await page.evaluate(f'''() => {{
702
+ const link = document.createElement('a');
703
+ link.href = '{TARGET_URL}';
704
+ link.target = '_self';
705
+ document.body.appendChild(link);
706
+ link.click();
707
+ }}''')
708
+ except PlaywrightTimeout: pass
709
+ except Exception: pass
710
+
711
+ # โ”€โ”€ 6. ุงู†ุชุธุงุฑ ุฐูƒูŠ ู„ุงูƒุชู…ุงู„ ุงู„ุชุญู…ูŠู„ (ู…ู† cut_prim) โ”€โ”€
712
+ await smart_wait_for_load(page)
713
+
714
+ # โ”€โ”€ ุชุดุบูŠู„ ุงู„ู…ุฑุงู‚ุจูŠู† ููŠ ุงู„ุฎู„ููŠุฉ โ”€โ”€
715
+ popup_task = asyncio.create_task(close_popup_watcher(page))
716
+ cookie_task = asyncio.create_task(auto_accept_cookies(page))
717
+ tab_watcher_task = asyncio.create_task(global_tab_watcher(context, page))
718
+ instant_btn_task = asyncio.create_task(instant_button_watcher(page))
719
+ recheck_task = asyncio.create_task(recheck_button_watcher(page))
720
+
721
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
722
+ # ู…ุนุงู„ุฌุฉ ุงู„ูุดู„ ุงู„ุฌุฒุฆูŠ (ุงู„ุงุฑุชุฏุงุฏ)
723
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
724
+ if action_type == "soft_fail":
725
+ wait_time = random.uniform(3.0, 7.0)
726
+ print(f"\n[โšก] ูุดู„ ุฌุฒุฆูŠ (40%): ุชู… ูุชุญ ุงู„ุฑุงุจุท. ุณู†ู†ุชุธุฑ ({wait_time:.1f} ุซูˆุงู†ูŠ) ู„ู…ุญุงูƒุงุฉ ุฒุงุฆุฑ ู„ู… ูŠุนุฌุจู‡ ุงู„ู…ูˆู‚ุน ุซู… ู†ุบู„ู‚.")
727
+ await asyncio.sleep(wait_time)
728
+
729
+ for t in [popup_task, cookie_task, tab_watcher_task, instant_btn_task]:
730
+ t.cancel()
731
+
732
+ await context.close()
733
+ if user_data_dir.exists():
734
+ try:
735
+ await asyncio.sleep(1.0)
736
+ shutil.rmtree(user_data_dir)
737
+ print("[๐Ÿ—‘๏ธ] ุชู… ุชู†ุธูŠู ุงู„ู†ุธุงู… ูˆุฅุบู„ุงู‚ ุงู„ุณูƒุฑุจุช.")
738
+ except Exception: pass
739
+ return # ุฅู†ู‡ุงุก ุงู„ุณูƒุฑุจุช ู‡ู†ุง
740
+
741
+ print("\n[๐ŸŽฏ] ู†ุฌุงุญ (10%): ุงู„ุณูƒุฑุจุช ุณูŠูƒู…ู„ ุฌู…ูŠุน ุงู„ุฎุทูˆุงุช ูˆุชุฎุทูŠ ุงู„ูƒุงุจุชุดุง ูˆุงู„ู†ู‚ุฑุงุช...")
742
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
743
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
744
+
745
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
746
+ # ุงู„ุฏุงู„ุฉ ุงู„ุฐูƒูŠุฉ (Smart Click V3) โ€” ู…ุชูˆุงูู‚ุฉ ู…ุน ุงู„ู…ุฑุงู‚ุจ ุงู„ุดุงู…ู„
747
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
748
+ async def smart_click(selectors, btn_name, max_wait=45):
749
+ print(f"\n[๐Ÿ”] ุงู„ุจุญุซ ุนู† ุฒุฑ: {btn_name}...")
750
+ # ... (ุจุงู‚ูŠ ูƒูˆุฏ ุงู„ุฏุงู„ุฉ ูƒู…ุง ู‡ูˆ ุจุฏูˆู† ุชุบูŠูŠุฑ) ...
751
+ deadline = time.monotonic() + max_wait
752
+
753
+ # ุชุตููŠุฑ ุนุฏุงุฏ ุงู„ุงุนุชุฑุงุถุงุช ู‚ุจู„ ุจุฏุก ุงู„ู†ู‚ุฑ
754
+ context.popup_intercepted = False
755
+
756
+ while time.monotonic() < deadline:
757
+ clicked_in_this_loop = False
758
+
759
+ # ุชู…ุฑูŠุฑ ุงู„ุดุงุดุฉ ู„ู„ุฃุณูู„ ุจุจุทุก ู„ุฅุฌุจุงุฑ ุงู„ุนู†ุงุตุฑ ุงู„ู…ุฎููŠุฉ ุนู„ู‰ ุงู„ุธู‡ูˆุฑ
760
+ try:
761
+ await page.evaluate("window.scrollBy(0, 500);")
762
+ except: pass
763
+
764
+ # 1. ู…ุญุงูˆู„ุฉ ุฅูŠุฌุงุฏ ุงู„ุฒุฑ ูˆุงู„ุถุบุท ุนู„ูŠู‡
765
+ for sel in selectors:
766
+ try:
767
+ is_xpath = sel.startswith("xpath=") or sel.startswith("/")
768
+ css_sel = None if is_xpath else sel.replace("css=", "")
769
+ xpath_sel = (sel if sel.startswith("xpath=") else f"xpath={sel}") if is_xpath else None
770
+
771
+ # ุงู„ู…ุญุงูˆู„ุฉ 1: ุงู„ุญู‚ู† ุงู„ู…ุจุงุดุฑ
772
+ if css_sel:
773
+ try:
774
+ ok = await page.evaluate(f"""() => {{
775
+ const e = document.querySelector({repr(css_sel)});
776
+ if (!e) return false;
777
+ e.scrollIntoView({{behavior: 'smooth', block: 'center'}});
778
+ e.click();
779
+ return true;
780
+ }}""")
781
+ if ok:
782
+ clicked_in_this_loop = True
783
+ break
784
+ except: pass
785
+
786
+ # ุงู„ู…ุญุงูˆู„ุฉ 2: ุงู„ุทุฑูŠู‚ุฉ ุงู„ุนุงุฏูŠุฉ ู„ู€ Playwright
787
+ loc = page.locator(xpath_sel if is_xpath else f"css={css_sel}")
788
+ if await loc.first.is_visible():
789
+ await loc.first.scroll_into_view_if_needed(timeout=1000)
790
+ await asyncio.sleep(0.5)
791
+ await loc.first.click(force=True, timeout=2000)
792
+ clicked_in_this_loop = True
793
+ break
794
+ except: continue
795
+
796
+ # 2. ุงู„ุชุญู‚ู‚ ู…ู…ุง ุฅุฐุง ูƒุงู† ุงู„ู…ุฑุงู‚ุจ ุงู„ุดุงู…ู„ ู‚ุฏ ุงู„ุชู‚ุท ุฅุนู„ุงู†ุงู‹
797
+ if clicked_in_this_loop:
798
+ print(f"[๐Ÿ‘†] ุชู… ุงู„ู†ู‚ุฑ ุนู„ู‰ '{btn_name}'... ุฌุงุฑูŠ ุงู„ุชุญู‚ู‚ ู…ู† ุงู„ุฅุนู„ุงู†ุงุช.")
799
+ await asyncio.sleep(1.5) # ูˆู‚ุช ู‚ุตูŠุฑ ู„ูƒูŠ ูŠู„ุญู‚ ุงู„ู…ุฑุงู‚ุจ ุจุงู„ุฅุบู„ุงู‚ ูˆุชุณุฌูŠู„ ุงู„ุงุนุชุฑุงุถ
800
+
801
+ if getattr(context, 'popup_intercepted', False):
802
+ print(f"[๐Ÿ“ข] ุงู„ู…ุฑุงู‚ุจ ุงู„ุดุงู…ู„ ุงู„ุชู‚ุท ุจูˆุจ-ุขุจ ูˆู‚ุงู… ุจุฅุบู„ุงู‚ู‡! ุณูŠุชู… ุฅุนุงุฏุฉ ุงู„ู†ู‚ุฑุฉ...")
803
+ context.popup_intercepted = False # ุชุตููŠุฑ ุงู„ุนุฏุงุฏ ู„ู„ู…ุญุงูˆู„ุฉ ุงู„ู‚ุงุฏู…ุฉ
804
+ await page.bring_to_front()
805
+ await asyncio.sleep(1.0)
806
+ continue # ุฅุนุงุฏุฉ ุงู„ู…ุญุงูˆู„ุฉ ููˆุฑุงู‹
807
+ else:
808
+ print(f"[โœ…] ุชู…ุช ุงู„ู†ู‚ุฑุฉ ุงู„ู†ุธูŠูุฉ ุนู„ู‰ '{btn_name}' ุจู†ุฌุงุญ.")
809
+ return True
810
+
811
+ await asyncio.sleep(1.0)
812
+
813
+ print(f"[โš ๏ธ] ูุดู„ ุงู„ุนุซูˆุฑ ุนู„ู‰ ุฒุฑ '{btn_name}' ุจุนุฏ ุงุณุชู†ูุงุฐ ุงู„ูˆู‚ุช ({max_wait} ุซุงู†ูŠุฉ).")
814
+ return False
815
+
816
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
817
+ # ู†ุธุงู… ุงู„ุชุฎุทูŠ ุงู„ู…ุชู‚ุฏู… (ุงู„ู†ุณุฎุฉ ุงู„ู†ู‡ุงุฆูŠุฉ ุงู„ุดุงู…ู„ุฉ)
818
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
819
+ import re
820
+
821
+ # โ”€โ”€ ุงู„ุฏูˆุงู„ ุงู„ู…ุณุงุนุฏุฉ (Helper Functions) โ”€โ”€
822
+ async def wait_for_title_timer(main_page):
823
+ print("[โฑ๏ธ] ุฌุงุฑูŠ ู…ุฑุงู‚ุจุฉ ุงู„ุนุฏุงุฏ ุงู„ุฒู…ู†ูŠ ููŠ ุนู†ูˆุงู† ุงู„ุตูุญุฉ...")
824
+ for _ in range(60):
825
+ try:
826
+ title = await main_page.title()
827
+ nums = re.findall(r'\d+', title)
828
+ if nums:
829
+ current_time = int(nums[0])
830
+ print(f" โณ ุงู„ุนุฏุงุฏ ุงู„ุญุงู„ูŠ ููŠ ุงู„ุนู†ูˆุงู†: {current_time}")
831
+ if current_time <= 0:
832
+ break
833
+ except: pass
834
+ await asyncio.sleep(1)
835
+ print("[โœ…] ุงู†ุชู‡ู‰ ุนุฏุงุฏ ุงู„ุนู†ูˆุงู†.")
836
+
837
+ async def detect_current_step():
838
+ print("[๐Ÿ”] ุฌุงุฑูŠ ู‚ุฑุงุกุฉ ุงู„ุตูุญุฉ ู„ู…ุนุฑูุฉ ุงู„ุฎุทูˆุฉ ุงู„ุญุงู„ูŠุฉ ุจุฏู‚ุฉ...")
839
+ for _ in range(3):
840
+ try: # ู…ุญุงูˆู„ุฉ ุงู„ู…ุณุงุฑ ุงู„ู…ุจุงุดุฑ
841
+ loc = page.locator("/html/body/main/div/div/div[3]/div[1]/strong").first
842
+ if await loc.is_visible(timeout=1000):
843
+ text = await loc.inner_text()
844
+ nums = re.findall(r'\d+', text)
845
+ if len(nums) >= 1: return int(nums[0]) # ุงู„ุชุนุฏูŠู„: ูŠูƒููŠ ุฌู„ุจ ุงู„ุฑู‚ู… ุงู„ุฃูˆู„ ูู‚ุท
846
+ except: pass
847
+
848
+ try: # ู…ุญุงูˆู„ุฉ ู‚ุฑุงุกุฉ ูƒู„ ู†ุตูˆุต ุงู„ุตูุญุฉ
849
+ body_text = await page.evaluate("document.body.innerText || ''")
850
+ # ุงู„ุชุนุฏูŠู„: ุงู„ุชูˆุงูู‚ ู…ุน ุฃูŠ ุฑู‚ู… ู„ู„ุฎุทูˆุฉ (3 ุฃูˆ 4)
851
+ match = re.search(r'Step\s+(\d+)\s+of\s+\d+', body_text, re.IGNORECASE)
852
+ if match: return int(match.group(1))
853
+ except: pass
854
+ await asyncio.sleep(1)
855
+ return None
856
+
857
+ async def safe_click_ad_button(loc, description):
858
+ print(f"[๐Ÿ›ก๏ธ] ุฅูŠู‚ุงู ุงู„ู…ุฑุงู‚ุจ ู…ุคู‚ุชุงู‹ ู„ุถุบุท '{description}' ุจุฃู…ุงู†...")
859
+ context.pause_watcher = True
860
+ try:
861
+ await loc.click(force=True)
862
+ print(f"[๐Ÿ–ฑ๏ธ] ุชู… ุงู„ุถุบุท ุนู„ู‰ {description}.")
863
+ except Exception as e:
864
+ print(f"[โš ๏ธ] ุฎุทุฃ ุฃุซู†ุงุก ุงู„ุถุบุท: {e}")
865
+
866
+ print(f"[โณ] ุงู†ุชุธุงุฑ 2.5 ุซุงู†ูŠุฉ ู„ุชุณุฌูŠู„ ุงู„ู†ู‚ุฑุฉ...")
867
+ await asyncio.sleep(2.5)
868
+
869
+ for p in context.pages:
870
+ if id(p) != id(page) and not p.is_closed():
871
+ try:
872
+ await p.close()
873
+ print("[๐Ÿ—‘๏ธ] ุชู… ุฅุบู„ุงู‚ ุชุงุจ ุฅุนู„ุงู†ูŠุฉ ูŠุฏูˆูŠุงู‹.")
874
+ except: pass
875
+
876
+ await page.bring_to_front()
877
+ context.pause_watcher = False
878
+ print(f"[โœ…] ุชู… ุฅุนุงุฏุฉ ุชุดุบูŠู„ ุงู„ู…ุฑุงู‚ุจ ุงู„ุดุฑุณ.")
879
+ return True
880
+
881
+ last_clicked_button = ""
882
+ async def aggressive_fallback_search():
883
+ nonlocal last_clicked_button
884
+ print("[๐Ÿšจ] ุชูุนูŠู„ ูˆุถุน ุงู„ุจุญุซ ุงู„ู…ูƒุซู...")
885
+ fallback_selectors = {
886
+ "Verify": ["#verify-button", "button:has(span:text('Verify'))", "//button[span[text()='Verify']]"],
887
+ "Verify reading": [".inline-verify-button:not([disabled])", "button:has-text('Verify reading')"],
888
+ "Continue reading": ["span:has-text('Continue reading')", "//*[contains(text(), 'Continue reading')]"]
889
+ }
890
+
891
+ for _ in range(3):
892
+ clicked_any = False
893
+ for btn_name, selectors in fallback_selectors.items():
894
+ if btn_name == last_clicked_button: continue
895
+ for sel in selectors:
896
+ try:
897
+ loc = page.locator(sel).first
898
+ if await loc.is_visible(timeout=1000):
899
+ print(f"[๐Ÿ”ฅ] ุชู… ุงุตุทูŠุงุฏ ุงู„ุฒุฑ ุจุงู„ุจุญุซ ุงู„ู…ูƒุซู: {btn_name}")
900
+ await safe_click_ad_button(loc, btn_name)
901
+ last_clicked_button = btn_name
902
+ clicked_any = True
903
+ await asyncio.sleep(2)
904
+ return True
905
+ except: pass
906
+ if not clicked_any: await asyncio.sleep(2)
907
+ print("[โŒ] ู„ู… ูŠุนุซุฑ ุงู„ุจุญุซ ุงู„ู…ูƒุซู ุนู„ู‰ ุดูŠุก.")
908
+ return False
909
+
910
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
911
+ # ู†ุธุงู… ุงู„ุชุฎุทูŠ ุงู„ู…ุชุณู„ุณู„ ู„ู„ุฃุฒุฑุงุฑ ูˆุงู„ุนุฏุงุฏุงุช (ุงู„ุฌุฏูŠุฏ)
912
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
913
+ print("\n[๐ŸŽฏ] ================= ุจุฏุก ุชุฎุทูŠ ุงู„ุฑูˆุงุจุท ูˆุงู„ุฃุฒุฑุงุฑ ุจุงู„ุชุฑุชูŠุจ =================")
914
+
915
+ async def wait_and_click_step(page, btn_name, selector, expected_text="", check_timer=False):
916
+ print(f"\n[๐Ÿ”] ุฌุงุฑูŠ ุงู„ุจุญุซ ุนู† ุฎุทูˆุฉ: {btn_name}")
917
+ for _ in range(45): # ุงู„ู…ุญุงูˆู„ุฉ ู„ู…ุฏุฉ 45 ุซุงู†ูŠุฉ ู„ูƒู„ ุฒุฑ
918
+ try:
919
+ # 1. ุงู„ุชุญู‚ู‚ ู…ู† ูˆุฌูˆุฏ ุงู„ุฒุฑ
920
+ loc = page.locator(selector).first
921
+ if await loc.is_visible(timeout=500):
922
+ await loc.scroll_into_view_if_needed()
923
+
924
+ text_content = await loc.inner_text()
925
+ class_name = await loc.evaluate("node => node.className || ''")
926
+
927
+ # 2. ุงู„ุชุญู‚ู‚ ู…ู† ุงู„ุนุฏุงุฏ (ุฅุฐุง ูƒุงู† ู…ุทู„ูˆุจุงู‹)
928
+ if check_timer:
929
+ if "cursor-wait" in class_name or "wait" in text_content.lower() or re.search(r'\d+', text_content):
930
+ print(f" ๏ฟฝ๏ฟฝ๏ฟฝ ุงู„ุนุฏุงุฏ ูŠุนู…ู„ ({text_content.strip()})... ู†ู†ุชุธุฑ 1 ุซุงู†ูŠุฉ.")
931
+ await asyncio.sleep(1)
932
+ continue # ุฅุนุงุฏุฉ ุงู„ู…ุญุงูˆู„ุฉ ุญุชู‰ ูŠุฎุชููŠ ุงู„ุนุฏุงุฏ
933
+
934
+ # 3. ุงู„ุชุญู‚ู‚ ู…ู† ุชุทุงุจู‚ ุงู„ู†ุต (ู„ู„ุชุฃูƒุฏ ุฃู† ุงู„ุฒุฑ ุชู… ุชุญุฏูŠุซู‡ ูˆู„ู… ู†ุถุบุท ุนู„ู‰ ุฒุฑ ู‚ุฏูŠู…)
935
+ if expected_text and expected_text.lower() not in text_content.lower():
936
+ await asyncio.sleep(1)
937
+ continue
938
+
939
+ # 4. ุงู„ุฒุฑ ุฌุงู‡ุฒ! ู†ูˆู‚ู ู…ุฑุงู‚ุจ ุงู„ุฅุนู„ุงู†ุงุช ู„ุชุณุฌูŠู„ ุงู„ู†ู‚ุฑุฉ
940
+ print(f"[๐Ÿ‘†] ุงู„ุฒุฑ '{btn_name}' ุฌุงู‡ุฒ! ุฌุงุฑูŠ ุงู„ู†ู‚ุฑ...")
941
+ context.pause_watcher = True
942
+
943
+ # ู…ุญุงูˆู„ุฉ ุงู„ู†ู‚ุฑ ุนุจุฑ JS ู„ุชุฌุงูˆุฒ ุฃูŠ ู…ุดุงูƒู„ุŒ ุซู… ุงู„ู†ู‚ุฑ ุงู„ุนุงุฏูŠ ูƒุจุฏูŠู„
944
+ try:
945
+ await loc.evaluate("node => node.click()")
946
+ except:
947
+ await loc.click(force=True)
948
+
949
+ print(f" [โณ] ุงู†ุชุธุงุฑ ู„ูุชุญ ุงู„ุฑุงุจุท ุงู„ุฅุนู„ุงู†ูŠ...")
950
+ await asyncio.sleep(3.0)
951
+
952
+ # 5. ุฅุบู„ุงู‚ ุงู„ุชุงุจุงุช ุงู„ุฅุนู„ุงู†ูŠุฉ ุงู„ุฌุฏูŠุฏุฉ ุงู„ุชูŠ ููุชุญุช
953
+ for p in context.pages:
954
+ if id(p) != id(page) and not p.is_closed():
955
+ try:
956
+ await p.close()
957
+ print(" [๐Ÿ—‘๏ธ] ุชู… ุฅุบู„ุงู‚ ุงู„ุชุงุจ ุงู„ุฅุนู„ุงู†ูŠ ุจู†ุฌุงุญ.")
958
+ except: pass
959
+
960
+ # 6. ุงู„ุนูˆุฏุฉ ู„ู„ุตูุญุฉ ุงู„ุฃุตู„ูŠุฉ ูˆุชูุนูŠู„ ุงู„ู…ุฑุงู‚ุจ ู…ุฑุฉ ุฃุฎุฑู‰
961
+ await page.bring_to_front()
962
+ context.pause_watcher = False
963
+
964
+ print(f"[โœ…] ุชู…ุช ุฎุทูˆุฉ '{btn_name}' ุจู†ุฌุงุญ!")
965
+ await asyncio.sleep(2) # ุฑุงุญุฉ ู‚ุตูŠุฑุฉ ู„ู„ุณู…ุงุญ ู„ู„ู…ูˆู‚ุน ุจุชุญุฏูŠุซ ุงู„ุฒุฑ ุงู„ุชุงู„ูŠ
966
+ return True
967
+ except Exception as e:
968
+ pass
969
+
970
+ # ูุญุต ุณุฑูŠุน ู„ุนู…ู„ ุณูƒุฑูˆู„ ุฎููŠู ู‚ุฏ ูŠุณุงุนุฏ ููŠ ุฅุธู‡ุงุฑ ุงู„ุฃุฒุฑุงุฑ ุงู„ู…ุฎููŠุฉ
971
+ try: await page.evaluate("window.scrollBy(0, 100);")
972
+ except: pass
973
+
974
+ await asyncio.sleep(1)
975
+
976
+ print(f"[โŒ] ูุดู„ ุงู„ุนุซูˆุฑ ุนู„ู‰ ุฎุทูˆุฉ: {btn_name} ุฃูˆ ุงู†ุชู‡ู‰ ุงู„ูˆู‚ุช.")
977
+ return False
978
+
979
+ # ุชุฑุชูŠุจ ุงู„ุฃุฒุฑุงุฑ ุจุงู„ุถุจุท ูƒู…ุง ุทู„ุจุช ู…ุน ู†ุตูˆุตู‡ุง ูˆู…ุญุฏุฏุงุชู‡ุง
980
+ sequence_steps = [
981
+ {"name": "ุงู„ุฒุฑ ุงู„ุฃูˆู„ (Open)", "selector": "#verify > a", "text": "Open", "timer": True},
982
+ {"name": "ุงู„ุฒุฑ ุงู„ุซุงู†ูŠ (Next)", "selector": "#verify > a", "text": "Next", "timer": False},
983
+ {"name": "ุงู„ุฒุฑ ุงู„ุซุงู„ุซ (Open)", "selector": "#second_open_placeholder > a", "text": "Open", "timer": False},
984
+ {"name": "ุงู„ุฒุฑ ุงู„ุฑุงุจุน (Open)", "selector": "#verify > a", "text": "Open", "timer": True},
985
+ {"name": "ุงู„ุฒุฑ ุงู„ุฎุงู…ุณ (Go to Link)", "selector": "#verify > a", "text": "Go to Link", "timer": False},
986
+ {"name": "ุงู„ุฒุฑ ุงู„ุฃุฎูŠุฑ (OPEN LINK)", "selector": "#cvFY94W7TL", "text": "OPEN LINK", "timer": False}
987
+ ]
988
+
989
+ # ุชู†ููŠุฐ ุงู„ุฎุทูˆุงุช ุจุงู„ุชุฑุชูŠุจ
990
+ for step in sequence_steps:
991
+ success = await wait_and_click_step(
992
+ page,
993
+ btn_name=step["name"],
994
+ selector=step["selector"],
995
+ expected_text=step["text"],
996
+ check_timer=step["timer"]
997
+ )
998
+
999
+ if not success:
1000
+ print(f"\n[โš ๏ธ] ุชูˆู‚ู ุงู„ุณูƒุฑุจุช ุนู†ุฏ ุฎุทูˆุฉ '{step['name']}'. ุฌุงุฑูŠ ุชุฌุฑุจุฉ ุงู„ู†ู‚ุฑ ุงู„ุจุตุฑูŠ ุงู„ุงุญุชูŠุงุทูŠ...")
1001
+ # ู…ุญุงูˆู„ุฉ ุฃุฎูŠุฑุฉ ุนุจุฑ ุงู„ุฑุคูŠุฉ ุงู„ุจุตุฑูŠุฉ ููŠ ุญุงู„ ูุดู„ ุงู„ูƒูˆุฏ
1002
+ await visual_click(page, template_filename="box.png", max_attempts=1)
1003
+ break # ุฅุฐุง ูุดู„ุช ุฎุทูˆุฉ ุฃุณุงุณูŠุฉ ู†ุชูˆู‚ู ุนู† ุฅูƒู…ุงู„ ุงู„ุจุงู‚ูŠ ู„ุชุฌู†ุจ ุงู„ุฃุฎุทุงุก
1004
+
1005
+ print("\n[๐ŸŽ‰] ุชู… ุฅู†ู‡ุงุก ุฌู…ูŠุน ุงู„ุฎุทูˆุงุช ุงู„ู…ุจุฑู…ุฌุฉ.")
1006
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
1007
+ # ุนู…ู„ูŠุงุช ุงู„ุชู†ุธูŠู ูˆุงู„ุฅุบู„ุงู‚
1008
+ # โ•โ•โ•โ•โ•โ•โ•โ•๏ฟฝ๏ฟฝโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
1009
+ print("\n[๐Ÿงน] ุฌุงุฑูŠ ุชู†ุธูŠู ุงู„ู†ุธุงู… ูˆุฅุบู„ุงู‚ ุงู„ุณูƒุฑุจุช...")
1010
+
1011
+ # 1. ุฅู„ุบุงุก ุฌู…ูŠุน ุงู„ู…ุฑุงู‚ุจูŠู† ุงู„ุฐูŠู† ูŠุนู…ู„ูˆู† ููŠ ุงู„ุฎู„ููŠุฉ
1012
+ for t in [popup_task, cookie_task, tab_watcher_task, recheck_task]:
1013
+ try:
1014
+ t.cancel()
1015
+ except:
1016
+ pass
1017
+
1018
+ # 2. ุฅุบู„ุงู‚ ุงู„ู…ุชุตูุญ ูˆุงู„ุณูŠุงู‚ ุจุงู„ูƒุงู…ู„ ู„ุชุญุฑูŠุฑ ุงู„ู…ู„ูุงุช
1019
+ await context.close()
1020
+
1021
+ # 3. ู…ุณุญ ู…ุฌู„ุฏ ุงู„ุจุฑูˆูุงูŠู„ ู…ู† ุงู„ู‡ุงุฑุฏ ุฏูŠุณูƒ ููˆุฑุงู‹
1022
+ if user_data_dir.exists():
1023
+ try:
1024
+ await asyncio.sleep(1.0)
1025
+ shutil.rmtree(user_data_dir)
1026
+ print("[๐Ÿ—‘๏ธ] ุชู… ุญุฐู ู…ุฌู„ุฏ ุงู„ุจุฑูˆูุงูŠู„ ุจู†ุฌุงุญ ูˆุชู†ุธูŠู ุงู„ู†ุธุงู….")
1027
+ except Exception as e:
1028
+ print(f"[โš ๏ธ] ุชุนุฐุฑ ุญุฐู ู…ุฌู„ุฏ ุงู„ุจุฑูˆูุงูŠู„ ุชู„ู‚ุงุฆูŠุงู‹: {e}")
1029
+
1030
+ if __name__ == "__main__":
1031
+ asyncio.run(main())
1032
+