diff options
Diffstat (limited to 'scrape-links.js')
-rw-r--r-- | scrape-links.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/scrape-links.js b/scrape-links.js new file mode 100644 index 0000000..0b3f2b9 --- /dev/null +++ b/scrape-links.js @@ -0,0 +1,33 @@ +const fetch = require("node-fetch") +const child = require("child_process") + +module.exports = async (page, link) => { + let data + + try { + data = await (await fetch(page)).text() + } catch {} + + if (!data) + return false + + const ids = [] + + while (true) { + const pos = data.search(link) + + if (pos == -1) + break; + + data = data.slice(pos + link.length) + const id = parseInt(data) + if (id) + ids.push(id) + } + + if (ids.length < 1) + return false + + child.spawnSync("nhentai", ["--id", ids.join(",")], { stdio: "inherit" }) + return true +} |