Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Luen committed Aug 15, 2022
0 parents commit e32e5b4
Show file tree
Hide file tree
Showing 7 changed files with 293 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"env": {
"node": true
},
"extends": "airbnb/base",
"parserOptions": {
"sourceType": "script",
"ecmaVersion": 2022
},
"globals": {
"window": true,
"document": true
},
"rules": {
"max-len": 0,
"arrow-parens": 0,
"no-console": 0,
"no-await-in-loop": 0,
"object-curly-newline": 0,
'no-restricted-syntax': [
'error',
{
selector: 'ForInStatement',
message: 'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
},
{
selector: 'LabeledStatement',
message: 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
},
{
selector: 'WithStatement',
message: '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
},
],
}
}
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
127 changes: 127 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 L

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Quillbot

Quillbot is a AI article rewriter/spinner. This script uses Chrome Headless Browser and rephrases (plagiarise).
They no longer have an API so this is the slow scraping method using Puppeteer.
This was a learning project for myself.

# Install

git clone
npm install


# run

node index
71 changes: 71 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const puppeteer = require('puppeteer');

function truncate(str, n) {
if (str.length <= n) { return str; }
const subString = str.match(/\b[\w']+(?:[^\w\n]+[\w']+){0,125}\b/g); // split up text into n words
return subString[0].slice(0, subString[0].lastIndexOf('.') + 1); // find nearest end of stentence
}

async function quillbot(text) {
try {
const inputSelector = 'div#inputText';
const buttonSelector = 'button.quillArticleBtn';
const outputSelector = 'div#outputText';
let str = text.trim();
let parts = [];
let output = '';

// 125 words per paraphrase for a free account
if (str.match(/(\w+)/g).length > 125) {
while (str.match(/(\w+)/g).length > 125) {
const part = truncate(str, 125);
str = str.slice(part.length);
parts.push(part);
}
parts.push(str);
} else {
parts.push(str);
}

const browser = await puppeteer.launch({ headless: false });

const page = await browser.newPage();
await page.goto('https://quillbot.com/');

for (let i = 0; i < parts.length; i++) {
const part = parts[i];

// Wait for input
const input = await page.waitForSelector(inputSelector);

await page.evaluate((selector) => { document.querySelector(selector).textContent = ''; }, inputSelector);
// Input the string in the text area
await input.type(' ');
// await page.waitFor(1000);
/* await page.evaluate((selector, text) => {
document.querySelector(selector).textContent = text;
}, inputSelector, part); */
await input.type(part);

// Generate the result
await page.click(buttonSelector);

// wait for paraphising to complete - button to become enabled
await page.waitForSelector(`${buttonSelector}:not([disabled])`);

const paraphrased = await page.evaluate((selector) => document.querySelector(selector).textContent, outputSelector);

output += paraphrased;

}
// Display result
console.log(output);

browser.close();
} catch (error) {
console.log(`Error: ${error}`);
process.exit();
}
}

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.');
21 changes: 21 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "Quillbot",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"puppeteer": "^1.20.0"
},
"devDependencies": {
"eslint": "^8.22.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.26.0"
}
}

0 comments on commit e32e5b4

Please sign in to comment.