Compare commits

..

No commits in common. "a69abb5b2f1ca7f9e6667ef6a80e8cfa2354c1a8" and "4ea99cd4f8e043677673e681496ffbda3397c97f" have entirely different histories.

5 changed files with 6 additions and 169 deletions

View File

@ -12,7 +12,5 @@
"email": "grumpydeveloper@contentnation.net"
}
],
"require": {
"arokettu/arithmetic-parser": "*"
}
"require": {}
}

View File

@ -7,28 +7,6 @@
**/
namespace ScriptedBrowser\Commands;
/**
* calculate given formula
*
* @param \ScriptedBrowser\Main $main main instance
* @param \ScriptedBrowser\Control $control control interface
* @param array<string,mixed> $options options
* @return bool always true
*/
function calc($main, $control, $options)
{
require_once 'vendor/autoload.php';
$input = $main->vars($options['parameter']);
$result = $options['result'];
try {
$calc = \Arokettu\ArithmeticParser\Calculator::evaluate($input);
$main->setVar($result, $calc);
return true;
} catch (\Exception) {
return false;
}
}
/**
* inject and execute given javascript
*
@ -45,21 +23,6 @@ function injectjscript($main, $control, $options)
return true;
}
/**
* press given key
*
* @param \ScriptedBrowser\Main $main
* @param \ScriptedBrowser\Control $control
* @param array<string,mixed> $options options
* @return bool always true
*/
function key($main, $control, $options)
{
$key = $main->vars($options['parameter']);
$control->key($key);
return true;
}
/**
* do mouse left click
*
@ -75,18 +38,6 @@ function leftclick($main, $control, $options) : bool
return true;
}
function leftpress($main, $control, $options) : bool
{
$control->mouseDown(\ScriptedBrowser\MouseButton::Left);
return true;
}
function leftrelease($main, $control, $options) : bool
{
$control->mouseUp(\ScriptedBrowser\MouseButton::Left);
return true;
}
/**
* move mouse to given element
*
@ -98,7 +49,8 @@ function leftrelease($main, $control, $options) : bool
function mousemove($main, $control, $options) : bool
{
$element = $control->selectCSS($main->vars($options['parameter']));
if ($element === [] || array_key_exists('error', $element)) {
$mouseOffset = $main->getMouseOffset();
if ($element === []) {
return false;
}
$element = array_values($element)[0];
@ -109,39 +61,6 @@ function mousemove($main, $control, $options) : bool
$targetX -= $scroll[0];
$targetY -= $scroll[1];
// echo "move $element - $tokens[1] $targetX $targetY\n";
_mousemoveaction($main, $control, $options, $targetX, $targetY);
return true;
}
/**
* move mouse to given target position from variables
*
* @param \ScriptedBrowser\Main $main main instance
* @param \ScriptedBrowser\Control $control control interface
* @param array<string,mixed> $options options
* @return bool true if mouse move, false on error
*/
function mousemovetarget($main, $control, $options) : bool
{
$targetX = $main->vars($options['x']);
$targetY = $main->vars($options['y']);
$scroll = $control->getScrollPosition();
$targetX -= $scroll[0];
$targetY -= $scroll[1];
_mousemoveaction($main, $control, $options, $targetX, $targetY);
return true;
}
/**
* move mouse to given target position
*
* @param \ScriptedBrowser\Main $main main instance
* @param \ScriptedBrowser\Control $control control interface
* @param array<string,mixed> $options options
*/
function _mousemoveaction($main, $control, $options, $targetX, $targetY)
{
$mouseOffset = $main->getMouseOffset();
$mouseX = $main->getMouseX();
$mouseY = $main->getMouseY();
$delta = [$targetX - $mouseX, $targetY - $mouseY];
@ -163,6 +82,7 @@ function _mousemoveaction($main, $control, $options, $targetX, $targetY)
$main->setMouseX($targetX);
$main->setMouseY($targetY);
$control->mousemove($targetX + $mouseOffset[0], $targetY + $mouseOffset[1]);
return true;
}
/**

View File

@ -9,7 +9,7 @@
namespace ScriptedBrowser\Commands;
/**
* run database query and provide result in variable
* inject and execute given javascript
*
* @param \ScriptedBrowser\Main $main main instance
* @param \ScriptedBrowser\Control $control control interface

View File

@ -1,48 +0,0 @@
<?php
/**
* SPDX-FileCopyrightText: 2024 Sascha Nitsch (grumpydeveloper) https://contentnation.net/@grumpydevelop
* SPDX-License-Identifier: GPL-3.0-or-later
*
* @author Sascha Nitsch (grumpydeveloper)
**/
namespace ScriptedBrowser\Commands;
/**
* wrap given element in a <span id="">
*
* @param \ScriptedBrowser\Main $main main instance
* @param \ScriptedBrowser\Control $control control interface
* @unused-param $control
* @param array<string,mixed> $options options
* @return bool true on success
*/
function spanwrap($main, $control, $options)
{
$start = $options['start'];
$end = $options['end'];
$query = $options['parameter'];
$id = $options['id'];
$js = '
const start = ' . $start .';
const end = ' . $end .';
const node = document.querySelector("' . $query . '");
const text = node.innerHTML;
const frontText = (start !== 0) ? text.substring(0, start) : \'\';
const middleText = text.substring(start, end !== 0 ? end : undefined);
const endText = end !== 0 ? text.substring(end) : \'\';
let finalText = frontText + \'<span data-id="' . $id . '">\';
finalText += middleText + \'</span>\' + endText;
node.innerHTML = finalText;
';
$control->executeScript($js);
$e = $control->selectCSS(('span[data-id="'. $id .'"]'));
$element = array_values($e)[0];
$r = $control->getElementRect($element);
$main->setVar($id . '_x', $r['x']);
$main->setVar($id . '_y', $r['y']);
$main->setVar($id . '_width', $r['width']);
$main->setVar($id . '_height', $r['height']);
return true;
}

View File

@ -184,28 +184,6 @@ class Control
return $this->executeScript('return [window.pageXOffset, window.pageYOffset];');
}
/**
* press given key (combination)
*
* @param string $key key to press
* @return void
*/
public function key($key)
{
fwrite($this->xdotool, "key $key\n");
}
/**
* press mouse button
*
* @param MouseButton $button button to press
* @return void
*/
public function mouseDown($button)
{
fwrite($this->xdotool, 'mousedown ' . $button->value . "\n");
}
/**
* move mouse to absolute position
*
@ -229,17 +207,6 @@ class Control
fwrite($this->xdotool, "mousemove_relative $x $y\n");
}
/**
* release mouse button
*
* @param MouseButton $button button to press
* @return void
*/
public function mouseUp($button)
{
fwrite($this->xdotool, 'mouseup ' . $button->value . "\n");
}
/**
* open geckodriver if not already running
*
@ -379,6 +346,6 @@ class Control
public function type($typeSpeed, $text)
{
$delay = 1000 / $typeSpeed;
fwrite($this->xdotool, "type --delay $delay '$text'\n");
fwrite($this->xdotool, "type --delay $delay $text\n");
}
}