added stop/resume on found the first item

This commit is contained in:
2026-06-30 19:20:06 +03:30
parent 42ddcdd22e
commit 78265d92ba
5 changed files with 16 additions and 2 deletions
+2
View File
@@ -86,6 +86,7 @@ class FlowConfigIn(BaseModel):
target_item_ids: list[str] = []
target_url: str = ""
scenario: str = "dynamic"
stop_on_first_click: bool = False
def _to_db_dict(body: FlowConfigIn) -> dict[str, Any]:
@@ -113,6 +114,7 @@ def _to_db_dict(body: FlowConfigIn) -> dict[str, Any]:
"target_item_ids_json": body.target_item_ids,
"target_url": body.target_url,
"scenario": body.scenario,
"stop_on_first_click": int(body.stop_on_first_click),
}
+8
View File
@@ -186,6 +186,11 @@
<input id="cfg-target-url" type="url" placeholder="https://example.com" />
</div>
<div class="fg" style="display:flex;align-items:center;gap:10px;margin-bottom:14px">
<input id="cfg-stop-on-first-click" type="checkbox" style="width:16px;height:16px;accent-color:var(--accent);cursor:pointer" />
<label for="cfg-stop-on-first-click" style="margin:0;cursor:pointer;color:var(--text)">Stop after first successful click</label>
</div>
<div class="fg" style="margin-top:6px">
<label>Search Texts <span style="color:var(--muted)">(one per line)</span></label>
<textarea id="cfg-search-texts" placeholder="shoes&#10;blue sneakers&#10;running shoes"></textarea>
@@ -1028,6 +1033,7 @@ function openNewForm() {
document.getElementById('cfg-target-url').value = '';
document.getElementById('cfg-search-texts').value = '';
document.getElementById('cfg-item-ids').value = '';
document.getElementById('cfg-stop-on-first-click').checked = false;
_resetAdvanced();
document.getElementById('adv-details').removeAttribute('open');
_applyScenario('dynamic');
@@ -1069,6 +1075,7 @@ function openEditForm(id) {
// DigiPay fields
const dpMatch = (scenario === 'digipay') ? (_ist || 'onclick') : 'onclick';
document.getElementById('cfg-digipay-match').value = dpMatch;
document.getElementById('cfg-stop-on-first-click').checked = c.stop_on_first_click !== 0;
document.getElementById('cfg-dp-max-scrolls').value = c.max_scrolls ?? 20;
document.getElementById('cfg-dp-scroll-pause').value = c.scroll_pause_ms ?? 1500;
document.getElementById('digipay-onclick-hint').style.display = dpMatch === 'onclick' ? '' : 'none';
@@ -1090,6 +1097,7 @@ function collectForm() {
target_url: document.getElementById('cfg-target-url').value.trim(),
search_texts: document.getElementById('cfg-search-texts').value.split('\n').map(s => s.trim()).filter(Boolean),
target_item_ids: document.getElementById('cfg-item-ids').value.split('\n').map(s => s.trim()).filter(Boolean),
stop_on_first_click: document.getElementById('cfg-stop-on-first-click').checked,
};
if (scenario === 'digipay') {
+3
View File
@@ -136,6 +136,9 @@ class DynamicFlow:
click_step = self._run_click(item_id, scroll_step.data.get("element"))
result.steps.append(click_step)
if click_step.success and self.cfg.get("stop_on_first_click", 0):
log.info("Item '%s' clicked — stopping flow", item_id)
return result
human_delay(1.0, 2.5)
log.info(
+1
View File
@@ -98,6 +98,7 @@ def _migrate(conn: sqlite3.Connection) -> None:
"pagination_wait_ms": "INTEGER NOT NULL DEFAULT 1500",
"target_url": "TEXT NOT NULL DEFAULT ''",
"scenario": "TEXT NOT NULL DEFAULT 'dynamic'",
"stop_on_first_click": "INTEGER NOT NULL DEFAULT 0",
}
for col, definition in additions.items():
if col not in existing:
+1 -1
View File
@@ -17,7 +17,7 @@ _FIELDS = [
"max_scrolls", "scroll_pause_ms", "no_new_content_timeout_ms",
"pagination_selector", "pagination_selector_type", "max_pages", "pagination_wait_ms",
"item_selector_template", "item_selector_type", "item_url_template", "target_item_ids_json",
"target_url", "scenario",
"target_url", "scenario", "stop_on_first_click",
]