diff --git a/index.js b/index.js index 8713699..ec8cb4e 100755 --- a/index.js +++ b/index.js @@ -167,20 +167,26 @@ let args = yargs alias: 'h', desc: __`Show help` }) + .option("completion", { + type: "boolean", + desc: __`Print script for bash/zsh completion` + }) .option("base", { alias: 'b', type: "string", desc: __`Set the document URL when parsing standard input or a local file (this affects relative links)` }) - .option("completion", { - type: "boolean", - desc: __`Print script for bash/zsh completion` - }) .option("insane", { alias: 'S', type: "boolean", desc: __`Don't sanitize HTML` }) + .option("insecure", { + alias: 'K', + type: "boolean", + desc: __`Allow invalid SSL certificates`, + default: false + }) .option("is-file", { alias: 'f', type: "boolean", @@ -218,6 +224,11 @@ let args = yargs desc: __`Output specific properties of the parsed article`, choices: Array.from(Properties.keys()) }) + .option("proxy", { + alias: 'x', + type: "string", + desc: __`Use specified proxy (can also use HTTPS_PROXY environment variable)` + }) .option("quiet", { alias: 'q', type: "boolean", @@ -236,6 +247,11 @@ let args = yargs hidden: true, //deprecated: true //completion script does not respect this value, so just say it in the description }) + .option("user-agent", { + alias: 'A', + type: "string", + desc: __`Set custom user agent string` + }) .option("version", { alias: 'V', type: "boolean", @@ -286,6 +302,8 @@ if (args["url"]) { args["base"] = args["url"]; } +const proxy = args["proxy"] || process.env.HTTPS_PROXY; + function printUsage() { yargs.showHelp(); @@ -373,12 +391,21 @@ if (inputIsFromStdin) { } else { if (!args["quiet"]) console.error(__`Retrieving...`); - const JSDOM = require("jsdom").JSDOM; + const jsdom = require("jsdom"); + let promiseGetHTML; if (inputURL) { - promiseGetHTML = JSDOM.fromURL(inputURL) + console.error(args["user-agent"]); + const resourceLoader = new jsdom.ResourceLoader({ + proxy: proxy, + strictSSL: !args["insecure"], + userAgent: args["user-agent"] + }); + promiseGetHTML = jsdom.JSDOM.fromURL(inputURL, { + resources: resourceLoader + }); } else if (inputFile) { - promiseGetHTML = JSDOM.fromFile(inputFile, { + promiseGetHTML = jsdom.JSDOM.fromFile(inputFile, { url: documentURL }); } diff --git a/locales/en.json b/locales/en.json index d97bbeb..c81c7a3 100644 --- a/locales/en.json +++ b/locales/en.json @@ -4,6 +4,9 @@ "Print script for bash/zsh completion": "Print script for bash/zsh completion", "Print version": "Print version", "Show help": "Show help", + "Allow invalid SSL certificates": "Allow invalid SSL certificates", + "Set custom user agent string": "Set custom user agent string", + "Use specified proxy (can also use HTTPS_PROXY environment variable)": "Use specified proxy (can also use HTTPS_PROXY environment variable)", "The file to which the result should be output": "The file to which the result should be output", "What to do if Readability.js is uncertain about what the core content actually is": "What to do if Readability.js is uncertain about what the core content actually is", "Output specific properties of the parsed article": "Output specific properties of the parsed article", diff --git a/locales/ru.json b/locales/ru.json index 7a5dfa3..41bc987 100644 --- a/locales/ru.json +++ b/locales/ru.json @@ -4,6 +4,9 @@ "Print script for bash/zsh completion": "Напечатать скрипт для автодополнения Bash/Zsh", "Print version": "Показать информацию про версию и выйти", "Show help": "Показать помощь", + "Allow invalid SSL certificates": "Разрешить небезопасные подключения (неверные SSL сертификаты)", + "Set custom user agent string": "Указать свою строку user agent", + "Use specified proxy (can also use HTTPS_PROXY environment variable)": "Использовать указаный прокси-сервер (также можно использовать переменную среды HTTPS_PROXY)", "The file to which the result should be output": "Файл, в который записывается результат", "What to do if Readability.js is uncertain about what the core content actually is": "Что делать, когда Readability не может определить целевой контент", "Output specific properties of the parsed article": "Показать определённые характеристики текста",