add matching unwrap function
This commit is contained in:
		
							parent
							
								
									96b1c19f0a
								
							
						
					
					
						commit
						052ac74ef7
					
				
					 1 changed files with 22 additions and 1 deletions
				
			
		| 
						 | 
					@ -9,7 +9,28 @@
 | 
				
			||||||
namespace ScriptedBrowser\Commands;
 | 
					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\Main $main main instance
 | 
				
			||||||
 * @param \ScriptedBrowser\Control $control control interface
 | 
					 * @param \ScriptedBrowser\Control $control control interface
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue