support for scrolling up and down

develop
Sascha Nitsch 2024-09-04 18:57:52 +02:00
parent 91c93f1fe8
commit 7a8895df33
2 changed files with 35 additions and 0 deletions

View File

@ -98,6 +98,24 @@ function mousemoverel($main, $control, $options)
return true; return true;
} }
/**
* scroll
*
* @param \ScriptedBrowser\Main $main
* @unused-param $main
* @param \ScriptedBrowser\Control $control control interface
* @unused-param $control
* @param array<string,mixed> $options options
* @return bool always true
*/
function scroll($main, $control, $options)
{
$amount = $options['parameter'];
$delay = $options['delay'];
$control->scroll(intval($amount), floatval($delay));
return true;
}
/** /**
* sleep * sleep
* *

View File

@ -273,6 +273,23 @@ class Control
@socket_close($socket); @socket_close($socket);
} }
/**
* scroll given amount
*
* @param int $amount
* @param float $delay delay per scroll
* @return void
*/
public function scroll($amount, $delay)
{
$dir = $amount > 0 ? 5 : 4;
$count = abs($amount);
for ($i = 0; $i < $count; ++$i) {
fwrite($this->xdotool, "click $dir\n");
usleep($delay * 1000 * 1000);
}
}
/** /**
* find elements with given css selector * find elements with given css selector
* *