-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
159 lines (123 loc) · 3.84 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Necro(ネクロ)
// start
'use strict';
// imports
const puppeteer = require('puppeteer');
const cheerio = require('cheerio');
const express = require('express');
const bodyParser = require('body-parser');
const sleep = require('util').promisify(setTimeout);
// settings
const app = express();
app.use(bodyParser.urlencoded({
extended: true
}));
var browser = {},
page = {},
content_search = [],
content_choose = [],
content_read = [];
app.use(express.static('public'));
// functions
async function starter() {
browser = await puppeteer.launch();
page = await browser.newPage();
await page.goto('https://kissmanga.com/', {
timeout: 100000
});
await page.waitForNavigation({
timeout: 100000,
waitUntil: 'domcontentloaded'
});
return ('Connection Established!');
}
async function searcher(us) {
const orgURL = await page.url();
await page.waitFor('#keyword');
await page.evaluate(typed => document.querySelector('#keyword').value = typed, us);
await page.evaluate((sel) => {
var elements = document.querySelectorAll(sel);
for (var i = 0; i < elements.length; i++) {
elements[i].parentNode.removeChild(elements[i]);
}
}, 'iframe');
while (orgURL == await page.url()) {
await page.bringToFront();
await page.click('#imgSearch');
await page.bringToFront();
}
try {
await page.waitFor('td');
} catch (err) {
return ['', 'Not Found... Disconnect and try again'];
}
const $ = cheerio.load(await page.content());
content_search = $('td').map(function (index, item) {
return [$(item).find('a').attr('href'), $(item).find('a').text()];
}).get();
content_search = content_search.filter(cleaner);
function cleaner(v, i, a) {
return i % 4 == 0 || i % 4 == 1;
}
return content_search;
}
async function selecter(us) {
await page.goto('https://kissmanga.com/' + content_search[us], {
waitUntil: 'domcontentloaded'
});
const $ = cheerio.load(await page.content());
content_choose = $('td>a').map(function (index, item) {
return [$(item).attr('href'), $(item).text()];
}).get();
return content_choose;
}
async function chooser(uc) {
await page.goto('https://kissmanga.com/' + content_choose[uc], {
waitUntil: 'domcontentloaded'
});
await page.waitFor('p>img');
const $ = cheerio.load(await page.content());
content_read = $('p>img').map(function (index, item) {
return $(item).attr('src');
}).get();
console.log(content_choose[++uc]);
return [content_choose[uc], content_read, uc];
}
async function extractor(keys) {
var result = [], total = 0;
for (var i = 0; i < keys.length; i++) {
result.push(await chooser(keys[i] - 1));
total += result[i][1].length;
await sleep(5000);
}
return [result, total];
}
async function ender() {
await browser.close();
return ('Disconnected!');
}
// routes
app.get('/', (req, res) => {
res.sendFile(__dirname + '/public/index.html');
});
app.post('/connect', async (req, res) => {
res.send(await starter());
});
app.post('/search', async (req, res) => {
res.send(await searcher(req.body.userSearch));
});
app.post('/select', async (req, res) => {
res.send(await selecter(req.body.selection));
});
app.post('/read', async (req, res) => {
res.send(await chooser(req.body.choice));
});
app.post('/download', async (req, res) => {
res.send(await extractor(Object.keys(req.body)));
});
app.post('/disconnect', async (req, res) => {
res.send(await ender());
});
app.listen(process.env.PORT || 3000);
// end