jerry 3 週間 前
コミット
6b610b526e
1 ファイル変更78 行追加28 行削除
  1. 78 28
      plugins/tls_plugin.py

+ 78 - 28
plugins/tls_plugin.py

@@ -530,36 +530,86 @@ class TlsPlugin(IVSPlg):
 
         self._log(f"Found {len(all_possible_slots)} valid slots. selected slot: {selected_date} {selected_time.time} {selected_label}")
         
-        js_inject_and_click = f"""
-        try {{
-            const form = document.querySelector('form');
-            if (!form) return 'Form not found';
-
-            function setReactValue(input, value) {{
-                if (!input) return;
-                input.value = value;
-                input.dispatchEvent(new Event('input', {{ bubbles: true }}));
-                input.dispatchEvent(new Event('change', {{ bubbles: true }}));
+        # ================== 新增:随机选择预订模式 ==================
+        book_mode = random.choice([1, 2])
+        self._log(f"Using booking mode: {book_mode}")
+        
+        if book_mode == 1:
+            rand_x = random.randint(300, 800)
+            rand_y = random.randint(400, 700)
+            self._log(f"Mode 1: Moving mouse to ({rand_x}, {rand_y}) and clicking, select slot")
+            self.mouse.click(rand_x, rand_y, humanize=True)
+            
+            js_update_form = f"""
+            try {{
+                const form = document.querySelector('form');
+                if (!form) return 'Form not found';
+
+                function setReactValue(input, value) {{
+                    if (!input) return;
+                    input.value = value;
+                    input.dispatchEvent(new Event('input', {{ bubbles: true }}));
+                    input.dispatchEvent(new Event('change', {{ bubbles: true }}));
+                }}
+                setReactValue(form.querySelector('input[name="date"]'), '{selected_date}');
+                setReactValue(form.querySelector('input[name="time"]'), '{selected_time.time}');
+                setReactValue(form.querySelector('input[name="appointmentLabel"]'), '{selected_label}');
+                const submitBtn = form.querySelector('button[type="submit"]');
+                if (submitBtn) {{
+                    submitBtn.removeAttribute('disabled');
+                    submitBtn.classList.remove('opacity-50', 'cursor-not-allowed'); 
+                    return 'form_updated';
+                }} else {{
+                    return 'Submit button not found';
+                }}
+            }} catch (e) {{
+                return e.toString();
             }}
-            setReactValue(form.querySelector('input[name="date"]'), '{selected_date}');
-            setReactValue(form.querySelector('input[name="time"]'), '{selected_time.time}');
-            setReactValue(form.querySelector('input[name="appointmentLabel"]'), '{selected_label}');
-            const submitBtn = form.querySelector('button[type="submit"]');
-            if (submitBtn) {{
-                submitBtn.removeAttribute('disabled');
-                submitBtn.classList.remove('opacity-50', 'cursor-not-allowed'); 
-                submitBtn.click();
-                return 'clicked';
-            }} else {{
-                return 'Submit button not found';
+            """
+            update_res = self.page.run_js(js_update_form)
+            self._log(f"Mode 1: Form update triggered: {update_res}")
+            
+            if update_res != 'form_updated':
+                raise BizLogicError(message=f"Failed to update form in Mode 1: {update_res}")
+            
+            submit_btn = self.page.ele('tag:button@@type=submit')
+            if not submit_btn:
+                raise BizLogicError(message="Submit button not found for mouse click")
+                
+            self._log("Mode 1: Moving mouse to submit button and clicking")
+            self.mouse.human_click_ele(submit_btn)
+            inject_res = 'clicked'
+
+        else:
+            js_inject_and_click = f"""
+            try {{
+                const form = document.querySelector('form');
+                if (!form) return 'Form not found';
+
+                function setReactValue(input, value) {{
+                    if (!input) return;
+                    input.value = value;
+                    input.dispatchEvent(new Event('input', {{ bubbles: true }}));
+                    input.dispatchEvent(new Event('change', {{ bubbles: true }}));
+                }}
+                setReactValue(form.querySelector('input[name="date"]'), '{selected_date}');
+                setReactValue(form.querySelector('input[name="time"]'), '{selected_time.time}');
+                setReactValue(form.querySelector('input[name="appointmentLabel"]'), '{selected_label}');
+                const submitBtn = form.querySelector('button[type="submit"]');
+                if (submitBtn) {{
+                    submitBtn.removeAttribute('disabled');
+                    submitBtn.classList.remove('opacity-50', 'cursor-not-allowed'); 
+                    submitBtn.click();
+                    return 'clicked';
+                }} else {{
+                    return 'Submit button not found';
+                }}
+            }} catch (e) {{
+                return e.toString();
             }}
-        }} catch (e) {{
-            return e.toString();
-        }}
-        """
-        
-        inject_res = self.page.run_js(js_inject_and_click)
-        self._log(f"Form submission triggered: {inject_res}")
+            """
+            inject_res = self.page.run_js(js_inject_and_click)
+            self._log(f"Mode 2: Form submission triggered: {inject_res}")
         
         if inject_res != 'clicked':
             raise BizLogicError(message="Failed to inject form or click the submit button")