forked from jiji262/wooyun_articles
-
Notifications
You must be signed in to change notification settings - Fork 5
/
wooyun.js
54 lines (41 loc) · 1.56 KB
/
wooyun.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
var fs = require("fs");
var path = require('path');
var async = require("async");
var cheerio = require("cheerio");
var imagesLink = [];
var parseData = function(data) {
var $ = cheerio.load(data, {
decodeEntities: false
});
var images = $("img");
for (var i = 0; i < images.length; i++) {
var imageSrc = $(images[i]).attr("src");
imagesLink.push(imageSrc);
}
$("head").append('<link rel="stylesheet" type="text/css" href="../stylesheets/stylesheet.css" media="screen"><link rel="stylesheet" type="text/css" href="../stylesheets/github-dark.css" media="screen"><link rel="stylesheet" type="text/css" href="../stylesheets/print.css" media="print"><style type="text/css">body {width: 90%;max-width: 960px;display: block;margin: 0 auto;}img {max-width: 900px;}</style>');
return $.html();
};
fs.readdir('./drops', (err, files) => {
if (err) throw err;
async.map(files, function(file, cb) {
if (/\.html$/.test(file)) {
fs.appendFile(path.join(__dirname, "link.html"), "<div class='link'><a href='drops/" + file + "'>" + file.replace("\.html", "") + "</a></div>\n", (err) => {
if (err) throw err;
});
fs.readFile("./drops/" + file, "utf8", (err, data) => {
if (err) throw err;
data = parseData(data);
fs.writeFile(path.join(__dirname, "/result/" + file), data, (err) => {
if (err) throw err;
console.log('[SAVED:] ' + file);
cb(null, file);
});
});
}
}, function(err, results) {
// console.log(results);
// for (var i = 0; i < imagesLink.length; i++) {
// console.log("'"+imagesLink[i]+ "',");
// }
});
});