1 Star 0 Fork 1.1K

jiaomy/BookStack

forked from 进击的皇虫/BookStack 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cover.js 1.31 KB
一键复制 编辑 原始数据 按行查看 历史
进击的皇虫 提交于 2019-11-17 21:18 . 实现自定义电子书封面
'use strict';
// 说明: 这段js是用来进行书籍封面截屏的,请勿随便删除或改动
const puppeteer = require('puppeteer');
const fs = require("fs");
let args = process.argv.splice(2);
let l=args.length;
let url, identify,folder;
for(let i=0;i<l;i++){
switch (args[i]){
case "--url":
url = args[i+1];
if (url==undefined){
url = "";
}
break;
case '--identify':
identify = args[i+1];
break;
}
i++;
}
async function screenshot() {
const browser = await puppeteer.launch({args: ['--no-sandbox', '--disable-setuid-sandbox'], headless: true, ignoreHTTPSErrors: true});
const page = await browser.newPage();
page.setViewport({width: 800, height: 1068}); // A4 宽高
folder="cache/books/"+identify+"/"
page.setExtraHTTPHeaders({
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,co;q=0.7,fr;q=0.6,zh-HK;q=0.5,zh-TW;q=0.4",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3766.2 Safari/537.36"
});
await page.goto(url, {"waitUntil" : ['networkidle2', 'domcontentloaded'], "timeout":5000});
await page.screenshot({path: folder+'cover.png'});
await browser.close();
}
if (url && identify) screenshot();
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/jiaomy/BookStack.git
[email protected]:jiaomy/BookStack.git
jiaomy
BookStack
BookStack
master

搜索帮助