Analyzer.prototype.nodeWalkDocuments = function nodeWalkDocuments(predicate) { for (var href in this._parsedDocuments) { var match = dom5.nodeWalk(this._parsedDocuments[href].ast, predicate); if (match) { return match; } } return null; };
function injectFrameScript(sourceDocument) { let fs = buildFrameScript(); let scriptTag = dom5.constructors.element('script'); dom5.setAttribute(scriptTag, 'designer-exclude', ''); dom5.setTextContent(scriptTag, fs); let head = dom5.query(sourceDocument, dom5.predicates.hasTagName('head')); if (head) { // inject into <head> if (head.childNodes) { let firstChild = head.childNodes[0]; dom5.insertBefore(head, firstChild, scriptTag); } else { dom5.append(head, scriptTag); } } else { // add to top of doc, below doctype let firstNonDoctype = dom5.nodeWalk(doc, (n) => n.nodeName !== '#documentType'); dom5.insertBefore(sourceDocument, firstNonDoctype, scriptTag); } }