UNPKG

als-document

Version:

A powerful HTML parser & DOM manipulation library for both backend and frontend.

38 lines (32 loc) 1.46 kB
function createIframe(htmlContent) { const iframe = document.createElement('iframe'); return new Promise((resolve,reject) => { iframe.onload = function() { const iframeDocument = iframe.contentDocument; iframeDocument.childNodes[0].innerHTML = htmlContent // iframeDocument.body.insertAdjacentHTML('afterbegin',htmlContent) resolve(iframeDocument) } document.body.appendChild(iframe); }) } class RandomSentenceGenerator { constructor() { this.subjects = ["The cat", "A monkey", "A child", "The robot", "The alien", "My friend"]; this.verbs = ["jumps", "runs", "flies", "dances", "sings", "reads"]; this.objects = ["on the bed", "in the garden", "above the clouds", "in the spaceship", "with a book", "under the tree"]; this.adverbs = ["quickly", "happily", "sadly", "gracefully", "lazily", "silently"]; } getRandomItem(arr) { const randomIndex = Math.floor(Math.random() * arr.length); return arr[randomIndex]; } generate() { const subject = this.getRandomItem(this.subjects); const verb = this.getRandomItem(this.verbs); const object = this.getRandomItem(this.objects); const adverb = this.getRandomItem(this.adverbs); return `${subject} ${verb} ${object} ${adverb}.`; } } const generator = new RandomSentenceGenerator()