support for scrolling up and down
This commit is contained in:
		
							parent
							
								
									91c93f1fe8
								
							
						
					
					
						commit
						7a8895df33
					
				
					 2 changed files with 35 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -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<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
 | 
			
		||||
 *
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
     *
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue