(Medium) - Mobile API
View original- current
This article is too short to summarise.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| // Example HTML structure: | |
| // <html> | |
| // <script> ... </script> | |
| // <p> | |
| // Some text node | |
| // <input type="text"> | |
| // <script> ... </script> | |
| // </p> | |
| // </html> | |
| const renderElementAndChildren = (element) => { | |
| // SCRIPT: | |
| // Represents an element to allow the browser to evaluate some JavaScript code. | |
| if (element.type === 'SCRIPT') { | |
| evaluateScript(element.innerHTML); | |
| } | |
| // CONTAINER: | |
| // Represents an element that can contain one or more childs of any type | |
| if (element.type === 'CONTAINER') { | |
| element.childElements().forEach(renderElementAndChildren); | |
| } | |
| // TEXT_NODE: | |
| // Represents an element that the browser will render as a piece of text | |
| if (element.type === 'TEXT_NODE') { | |
| renderText(element.innerHTML); | |
| } | |
| // INPUT: | |
| // Represents an element that the browser will render as a data input of some sort | |
| if (element === 'INPUT') { | |
| renderInput(element); | |
| } | |
| }; | |
| pageContent.childElements().forEach(renderElementAndChildren); |