const express = require('express') var { Readability } = require('@mozilla/readability'); var { JSDOM } = require('jsdom'); const request = require('request'); const e = require('express'); const { head } = require('request'); const DDG = require('duck-duck-scrape'); const app = express() const port = 3001 //which port? const noPortInDomain = true //is there a port visible in the domain? const httpOrHttps = "https" //is set to http when changed to anything besides the default (http) const subdomain = "server.sparksammy.com" //subdomain where your basednet instance resides. var siteName; // code below. if (httpOrHttps == "https") { if (noPortInDomain == false) { siteName = `https://${subdomain}:${port}` } else { siteName = `https://${subdomain}` } } else { if (noPortInDomain == false) { siteName = `http://${subdomain}:${port}` } else { siteName = `http://${subdomain}` } } const proxying = `${siteName}/net?url=` var headHTML = ` BasedNet ` app.get('/', (req, res) => { res.send(` ${headHTML}

BasedNet




Check out the other project, BasedFind!

Copyright Samuel Lord. Licensed under the MIT license.
Source available on the BasedNet GitHub.

`) }) app.get('/find', (req, res) => { const search = DDG.search(req.query.q) let thtml; search.results.forEach(function(e,i) { thtml = `${thtml}
$search.results[i].title}` }); res.send(thtml); }) app.get('/basedfind', (req, res) => { let dp; if (noPortInDomain == false) { dp = port } else { dp = 80 } res.send(` ${headHTML}

BasedFind *early build*




Back to BasedNet.

Copyright Samuel Lord. Licensed under the MIT license. Powered by DuckDuckGo Lite.
Source available on the BasedNet GitHub.

`) }) app.get('/net', (req, res) => { const reqf = req; const resf = res; var baseurl = "" let dp; if (noPortInDomain == false) { dp = port } else { dp = 80 } request(req.query.url, { json: false }, (err, res, body) => { if (err) { return console.log(err); } //console.log(body) try { if (req.query.url.startsWith("http://")) { baseurl = req.query.url.replace("http://","") } else { baseurl = req.query.url.replace("https://","") } var arrOfURL = req.query.url.split("/") var urlNoDoc = req.query.url for (let i = 0; i < arrOfURL.length; i++) { if (String(arrOfURL[i]).includes("html")) { arrOfURL.pop(i) urlNoDoc = arrOfURL.join("/") break; } } var arrOfURL2 = req.query.url.split("/") const domain = arrOfURL2[2] var olddom = new JSDOM(`${body}`, { url: req.query.url}); var newbody = body var arrOfTags = [] newbody = newbody.replace(/)<[^<]*)*<\/script>/gi, "") newbody = newbody.replace(/)<[^<]*)*<\/style>/gi, "") newbody = newbody.replace(/)<[^<]*)*<\/link>/gi, "") newbody = newbody.replace(/)<[^<]*)*<\/meta>/gi, "") newbody = newbody.replace(/)<[^<]*)*<\/iframe>/gi, "") newbody = newbody.replace(/)<[^<]*)*<\/form>/gi, "") newbody = newbody.replace(/href="\//g, `href="${proxying}http://${domain}/`) newbody = newbody.replace(/href='\//g, `href='${proxying}http://${domain}/`) newbody = newbody.replace(/href="/g, `href="${proxying}/`) newbody = newbody.replace(/href='/g, `href='${proxying}/`) var newdom = new JSDOM(`${newbody}`, { url: req.query.url}); var reader = new Readability(newdom.window.document); var liteRead = reader.parse(); var contentLatest = liteRead.content.split(`href="https://www.${baseurl}`).join(`href="${proxying}https://${baseurl}`) contentLatest = contentLatest.split(`href="https://www.${baseurl}`).join(`href="${proxying}https://${baseurl}`) contentLatest = contentLatest.split(`href="http://www.${baseurl}`).join(`href="${proxying}http://${baseurl}`) contentLatest = contentLatest.split(`href='https://${baseurl}`).join(`href='${proxying}https://${baseurl}`) contentLatest = contentLatest.split(`href='http://${baseurl}`).join(`href='${proxying}http://${baseurl}`) contentLatest = contentLatest.split(`${urlNoDoc}/http://`).join(`http://`) contentLatest = contentLatest.split(`${urlNoDoc}/https://`).join(`https://`) contentLatest = contentLatest.split(`${proxying}//`).join(`${proxying}https://`) contentLatest = contentLatest.split(`${proxying}${req.query.url}///`).join(`${proxying}https://`) contentLatest = contentLatest.split('based.sparksammy.com/net?url=/').join('based.sparksammy.com/net?url=') contentLatest = contentLatest.split('https://based.sparksammy.com/net?url=https://based.sparksammy.com/net?url=').join('https://based.sparksammy.com/net?url=') contentLatest = contentLatest.split('http://based.sparksammy.com/net?url=http://based.sparksammy.com/net?url=').join('http://based.sparksammy.com/net?url=') resf.send(` ${headHTML} BasedNet

BasedFind *early build*

${liteRead.title}


${contentLatest} `) } catch (error) { console.log(error); if (req.query.url.startsWith("http://")) { baseurl = req.query.url.replace("http://","") } else { baseurl = req.query.url.replace("https://","") } var arrOfURL = req.query.url.split("/") var urlNoDoc = req.query.url for (let i = 0; i < arrOfURL.length; i++) { if (String(arrOfURL[i]).includes("html")) { arrOfURL.pop(i) urlNoDoc = arrOfURL.join("/") break; } } var olddom = new JSDOM(`${body}`, { url: req.query.url}); var newbody = body var arrOfTags = [] newbody = newbody.replace(/)<[^<]*)*<\/script>/gi, "") newbody = newbody.replace(/)<[^<]*)*<\/style>/gi, "") newbody = newbody.replace(/)<[^<]*)*<\/link>/gi, "") newbody = newbody.replace(/)<[^<]*)*<\/meta>/gi, "") newbody = newbody.replace(/)<[^<]*)*<\/iframe>/gi, "") newbody = newbody.replace(/)<[^<]*)*<\/form>/gi, "") newbody = newbody.replace(/href="/g, `href="${proxying}/`) newbody = newbody.replace(/href='/g, `href='${proxying}/`) newbody = newbody.replace(/href="/g, `href="${proxying}/`) newbody = newbody.replace(/href='/g, `href='${proxying}/`) newbody = newbody.split(`href="https://www.${baseurl}`).join(`href="${proxying}https://${baseurl}`) newbody = newbody.split(`href="http://www.${baseurl}`).join(`href="${proxying}http://${baseurl}`) newbody = newbody.split(`href='https://${baseurl}`).join(`href='${proxying}https://${baseurl}`) newbody = newbody.split(`href='http://${baseurl}`).join(`href='${proxying}http://${baseurl}`) newbody = newbody.split(`${urlNoDoc}/http://`).join(`http://`) newbody = newbody.split(`${urlNoDoc}/https://`).join(`https://`) newbody = newbody.split(`${proxying}//`).join(`${proxying}https://`) newbody = newbody.split(`${proxying}${req.query.url}///`).join(`${proxying}https://`) newbody = newbody.split('based.sparksammy.com/net?url=/').join('based.sparksammy.com/net?url=') newbody = newbody.split('https://based.sparksammy.com/net?url=https://based.sparksammy.com/net?url=').join('https://based.sparksammy.com/net?url=') newbody = newbody.split('http://based.sparksammy.com/net?url=http://based.sparksammy.com/net?url=').join('http://based.sparksammy.com/net?url=') resf.send(` ${headHTML} BasedNet

BasedFind *early build*
${newbody} `) } }); }) app.listen(port, () => { console.log(`BasedNet listening at http://localhost:${port}`) })