Return all DOMNodes whose content is JavaScript

@param  DOMDocument $dom Document
@return DOMNode[]        List of DOMNode instances
438408
public static function getJSNodes(DOMDocument $dom)
	{
		$regexp = '/^(?:data-s9e-livepreview-postprocess$|on)/i';
		$nodes  = array_merge(
			self::getAttributesByRegexp($dom, $regexp),
			self::getElementsByRegexp($dom, '/^script$/i')
		);

		return $nodes;
	}
1196167
protected static function getPreviousElement(\DOMNode $node)
    {
        while ($node && ($node = $node->previousSibling)) {
            if ($node instanceof \DOMElement) {
                break;
            }
        }

        return $node;
    }
1187630
private function visitNode(\DOMNode $node)
    {
        if ($this->node !== $node) {
            $this->node->appendChild($node);
        }

        return $node;
    }
638739
public function xpath($path)
    {
        $xpath = new \DOMXPath($this->dom);

        $list = $xpath->query($path);

        $return = [];
        foreach ($list as $node) {
            $return[] = $this->newElement($node);
        }

        return $return;
    }
1282348
private function getNodeContent(\DOMNode $node)
    {
        $type = $node->attributes->getNamedItem('type');
        if ($type && strtolower($type->nodeValue) == 'xhtml') {
            $result = '';
            foreach ($node->childNodes as $childNode) {
                $result .= $node->ownerDocument->save($childNode);
            }
            return $result;
        } else {
            return $node->nodeValue;
        }
    }
26159
private function protectTags(HtmlDomParser $dom): HtmlDomParser
    {
        // init
        $counter = 0;

        foreach ($dom->find('script, style') as $element) {

            // skip external links
            if ($element->tag === 'script' || $element->tag === 'style') {
                $attributes = $element->getAllAttributes();
                if (isset($attributes['src'])) {
                    continue;
                }
            }

            $this->protectedChildNodes[$counter] = $element->text();
            $element->getNode()->nodeValue = '<' . $this->protectedChildNodesHelper . ' data-' . $this->protectedChildNodesHelper . '="' . $counter . '"></' . $this->protectedChildNodesHelper . '>';

            ++$counter;
        }

        foreach ($dom->find('code, nocompress') as $element) {
            if ($element->isRemoved()) {
                continue;
            }

            $this->protectedChildNodes[$counter] = $element->parentNode()->innerHtml();
            $element->getNode()->parentNode->nodeValue = '<' . $this->protectedChildNodesHelper . ' data-' . $this->protectedChildNodesHelper . '="' . $counter . '"></' . $this->protectedChildNodesHelper . '>';

            ++$counter;
        }

        foreach ($dom->find('//comment()') as $element) {
            $text = $element->text();

            // skip normal comments
            if (!$this->isConditionalComment($text)) {
                continue;
            }

            $this->protectedChildNodes[$counter] = '<!--' . $text . '-->';

            /* @var $node \DOMComment */
            $node = $element->getNode();
            $child = new \DOMText('<' . $this->protectedChildNodesHelper . ' data-' . $this->protectedChildNodesHelper . '="' . $counter . '"></' . $this->protectedChildNodesHelper . '>');
            /** @noinspection UnusedFunctionResultInspection */
            $element->getNode()->parentNode->replaceChild($child, $node);

            ++$counter;
        }

        return $dom;
    }
1234301
protected function getElements($tagName)
	{
		$nodes = [];
		foreach ($this->template->ownerDocument->getElementsByTagName($tagName) as $node)
		{
			if (!$this->onlyIfDynamic || $this->isDynamic($node))
			{
				$nodes[] = $node;
			}
		}

		return $nodes;
	}
107592
protected function nodesFromHtml($html): NodeList {
        $class = get_class($this->document());
        $doc = new $class();
        $nodes = $doc->html($html)->find('body > *');

        return $nodes;
    }
920597
protected function asXml(DomDocument $document)
    {
        $root = $document->createElement($this->getTagName(), $this->content);
        $document->appendChild($root);

        foreach ($this->attributes as $name => $value) {
            $root->setAttribute($name, $value);
        }

        foreach ($this->children as $child) {
            $root->appendChild($child->asXml($document));
        }

        return $root;
    }
907282
protected function getSelectedNode(\DOMDocument $dom, string $selector): \DOMNode
    {
        $xPath = new \DOMXPath($dom);

        return $xPath->query((new CssSelectorConverter())->toXPath($selector))->item(0);
    }
1270298
private function removeScripts(DOMDocument $dom)
    {
        foreach (['script', 'noscript'] as $tag) {
            $nodes = $dom->getElementsByTagName($tag);
            foreach (iterator_to_array($nodes) as $node) {
                NodeUtility::removeNode($node);
            }
        }
    }
1361310
private function loadParam(\DOMXPath $xpath, \DOMNode $node)
    {
        $result = [
            'name' => $this->getValueFromXPath('@name', $xpath, $node),
            'type' => $this->getValueFromXPath('@type', $xpath, $node, 'string'),
            'meta' => $this->loadMeta($xpath, $node),
        ];

        switch ($result['type']) {
            case 'collection':
                $result['value'] = $this->loadParams('x:param', $xpath, $node);
                break;
            default:
                $result['value'] = $this->getValueFromXPath('@value', $xpath, $node);
                break;
        }

        return $result;
    }
1280298
public function parseDom(\DOMDocument $dom)
    {
        $this->logger->info('Running parser: '.(new \ReflectionClass(__CLASS__))->getShortName());
        $items = [];

        $xpath = new \DOMXPath($dom);
        $xpath->registerNamespace('html', self::HTML_PROFILE_URI);

        // Run through all <link> elements with a `rel` attribute
        /** @var \DOMElement $linkType */
        foreach ($xpath->query('//*[local-name(.) = "link" or local-name(.) = "a"][@rel]') as $linkType) {
            $item    = [
                'type'       => $this->parseLinkType($linkType->getAttribute('rel')),
                'id'         => $linkType->getAttribute('id') ?: null,
                'properties' => $this->parseProperties($linkType),
            ];
            $items[] = (object)$item;
        }

        return new ParsingResult(self::FORMAT, $items);
    }
896716
public function getTagsByTagName( $tagName )
	{
		$list	= array();
		$nodes	= $this->document->getElementsByTagName( $tagName );
		foreach( $nodes as $node )
			$list[]	= $node;
		return $list;
	}
746664
public function getTagsByXPath( $query )
	{
		$list	= array();
		$xpath	= new DomXPath( $this->document );
		$nodes	= $xpath->query( $query );
		foreach( $nodes as $node )
		{
			if( preg_match( "#/@[a-z]+$#i", $query ) )
				$node	= $node->textContent;
			$list[]	= $node;
		}
		return $list;
	}
1312591
public function getXML(\DOMDocument $document)
    {
        $xml = $document->createElement('ns2:DataStorageItem');

        $ccData = $this->creditCardData->getXML($document);
        $dataId = $document->createElement('ns2:HostedDataID');
        $dataId->textContent = $this->hostedDataId;

        if ($this->function != null) {
            $function = $document->createElement('ns2:Function');
            $function->textContent = $this->function;
            $xml->appendChild($function);
        }
        if ($this->declineHostedDataDuplicates != null) {
            $declineDuplicates = $document->createElement('ns2:DeclineHostedDataDuplicates');
            $declineDuplicates->textContent = $this->declineHostedDataDuplicates;
            $xml->appendChild($declineDuplicates);
        }

        $xml->appendChild($ccData);
        $xml->appendChild($dataId);

        return $xml;
    }
357588
static protected function get_cell_list(\DOMNode $node)
    {
        $xpath = new \DOMXpath($node->ownerDocument);

        switch ($node->nodeName) {
            default:
            case "table":
                $query = "tr/td | thead/tr/td | tbody/tr/td | tfoot/tr/td | tr/th | thead/tr/th | tbody/tr/th | tfoot/tr/th";
                break;

            case "tbody":
            case "tfoot":
            case "thead":
                $query = "tr/td | tr/th";
                break;

            case "tr":
                $query = "td | th";
                break;
        }

        return $xpath->query($query, $node);
    }