|
| 1 | +const puppeteer = require('puppeteer'); |
| 2 | + |
| 3 | +function truncate(str, n) { |
| 4 | + if (str.length <= n) { return str; } |
| 5 | + const subString = str.match(/\b[\w']+(?:[^\w\n]+[\w']+){0,125}\b/g); // split up text into n words |
| 6 | + return subString[0].slice(0, subString[0].lastIndexOf('.') + 1); // find nearest end of stentence |
| 7 | +} |
| 8 | + |
| 9 | +async function quillbot(text) { |
| 10 | + try { |
| 11 | + const inputSelector = 'div#inputText'; |
| 12 | + const buttonSelector = 'button.quillArticleBtn'; |
| 13 | + const outputSelector = 'div#outputText'; |
| 14 | + let str = text.trim(); |
| 15 | + let parts = []; |
| 16 | + let output = ''; |
| 17 | + |
| 18 | + // 125 words per paraphrase for a free account |
| 19 | + if (str.match(/(\w+)/g).length > 125) { |
| 20 | + while (str.match(/(\w+)/g).length > 125) { |
| 21 | + const part = truncate(str, 125); |
| 22 | + str = str.slice(part.length); |
| 23 | + parts.push(part); |
| 24 | + } |
| 25 | + parts.push(str); |
| 26 | + } else { |
| 27 | + parts.push(str); |
| 28 | + } |
| 29 | + |
| 30 | + const browser = await puppeteer.launch({ headless: false }); |
| 31 | + |
| 32 | + const page = await browser.newPage(); |
| 33 | + await page.goto('https://quillbot.com/'); |
| 34 | + |
| 35 | + for (let i = 0; i < parts.length; i++) { |
| 36 | + const part = parts[i]; |
| 37 | + |
| 38 | + // Wait for input |
| 39 | + const input = await page.waitForSelector(inputSelector); |
| 40 | + |
| 41 | + await page.evaluate((selector) => { document.querySelector(selector).textContent = ''; }, inputSelector); |
| 42 | + // Input the string in the text area |
| 43 | + await input.type(' '); |
| 44 | + // await page.waitFor(1000); |
| 45 | + /* await page.evaluate((selector, text) => { |
| 46 | + document.querySelector(selector).textContent = text; |
| 47 | + }, inputSelector, part); */ |
| 48 | + await input.type(part); |
| 49 | + |
| 50 | + // Generate the result |
| 51 | + await page.click(buttonSelector); |
| 52 | + |
| 53 | + // wait for paraphising to complete - button to become enabled |
| 54 | + await page.waitForSelector(`${buttonSelector}:not([disabled])`); |
| 55 | + |
| 56 | + const paraphrased = await page.evaluate((selector) => document.querySelector(selector).textContent, outputSelector); |
| 57 | + |
| 58 | + output += paraphrased; |
| 59 | + |
| 60 | + } |
| 61 | + // Display result |
| 62 | + console.log(output); |
| 63 | + |
| 64 | + browser.close(); |
| 65 | + } catch (error) { |
| 66 | + console.log(`Error: ${error}`); |
| 67 | + process.exit(); |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +quillbot('TCP is a connection-oriented protocol, which means that the end-to-end communications is set up using handshaking. Once the connection is set up, user data may be sent bi-directionally over the connection. Compared to TCP, UDP is a simpler message based connectionless protocol, which means that the end-to-end connection is not dedicated and information is transmitted in one direction from the source to its destination without verifying the readiness or state of the receiver. TCP controls message acknowledgment, retransmission and timeout. TCP makes multiple attempts to deliver messages that get lost along the way, In TCP therefore, there is no missing data, and if ever there are multiple timeouts, the connection is dropped. When a UDP message is sent there is no guarantee that the message it will reach its destination; it could get lost along the way.'); |
0 commit comments