diff --git a/scriptedbrowser/commands/spanwrap.php b/scriptedbrowser/commands/spanwrap.php new file mode 100644 index 0000000..d8cbf24 --- /dev/null +++ b/scriptedbrowser/commands/spanwrap.php @@ -0,0 +1,48 @@ + + * + * @param \ScriptedBrowser\Main $main main instance + * @param \ScriptedBrowser\Control $control control interface + * @unused-param $control + * @param array $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 + \'\'; + finalText += middleText + \'\' + 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; +}