Compare commits
2 Commits
91c93f1fe8
...
4ea99cd4f8
Author | SHA1 | Date |
---|---|---|
Sascha Nitsch | 4ea99cd4f8 | |
Sascha Nitsch | 7a8895df33 |
|
@ -57,6 +57,9 @@ function mousemove($main, $control, $options) : bool
|
|||
$targetPos = $control->getElementRect($element);
|
||||
$targetX = $targetPos['x'] + $targetPos['width'] / 2;
|
||||
$targetY = $targetPos['y'] + $targetPos['height'] / 2;
|
||||
$scroll = $control->getScrollPosition();
|
||||
$targetX -= $scroll[0];
|
||||
$targetY -= $scroll[1];
|
||||
// echo "move $element - $tokens[1] $targetX $targetY\n";
|
||||
$mouseX = $main->getMouseX();
|
||||
$mouseY = $main->getMouseY();
|
||||
|
@ -98,6 +101,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<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
|
||||
*
|
||||
|
|
|
@ -174,6 +174,16 @@ class Control
|
|||
return (!is_array($url)) ? $url : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* get scroll position
|
||||
*
|
||||
* @return [int,int] current scroll position
|
||||
*/
|
||||
public function getScrollPosition()
|
||||
{
|
||||
return $this->executeScript('return [window.pageXOffset, window.pageYOffset];');
|
||||
}
|
||||
|
||||
/**
|
||||
* move mouse to absolute position
|
||||
*
|
||||
|
@ -273,6 +283,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
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue