add matching unwrap function

This commit is contained in:
Sascha Nitsch 2024-09-09 18:43:35 +02:00
parent 96b1c19f0a
commit 052ac74ef7

View file

@ -9,7 +9,28 @@
namespace ScriptedBrowser\Commands;
/**
* wrap given element in a <span id="">
* unwrap given element from <span data-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 spanunwrap($main, $control, $options)
{
$id = $options['parameter'];
$js = '
const node = document.querySelector("span[data-id=\"' . $id . '\"]");
const text = node.parentNode.innerHTML;
node.parentNode.innerHTML = text.replace(node.outerHTML, node.innerHTML);
';
$control->executeScript($js);
return true;
}
/**
* wrap given element in a <span data-id="">
*
* @param \ScriptedBrowser\Main $main main instance
* @param \ScriptedBrowser\Control $control control interface