diff --git a/scriptedbrowser/commands/base.php b/scriptedbrowser/commands/base.php index d84f65b..f6a7295 100644 --- a/scriptedbrowser/commands/base.php +++ b/scriptedbrowser/commands/base.php @@ -98,6 +98,24 @@ function mousemoverel($main, $control, $options) return true; } +/** + * scroll + * + * @param \ScriptedBrowser\Main $main + * @unused-param $main + * @param \ScriptedBrowser\Control $control control interface + * @unused-param $control + * @param array $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 * diff --git a/scriptedbrowser/control.php b/scriptedbrowser/control.php index 8b68d91..295064d 100644 --- a/scriptedbrowser/control.php +++ b/scriptedbrowser/control.php @@ -273,6 +273,23 @@ class Control @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 *