Last active
October 19, 2017 23:02
-
-
Save cedriczirtacic/d48fce8e223e20d6ab3f38240f4a5950 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env node | |
// https://gist.github.com/cedriczirtacic | |
var argv = process.argv; | |
if (argv.length < 3) { | |
console.info("%s <url>", argv[1]); | |
process.exit(1); | |
} | |
var url = argv[2]; | |
var http_options = {} | |
var http; | |
var r; | |
if (( r = /^(https*):\/\/(.+?)(?:([0-9]+))?(\/.+)$/gi.exec(url))) { | |
http = require(r[1]); | |
if (r[3] != undefined) { | |
http_options.port = r[3]; | |
} | |
http_options.host = r[2]; | |
http_options.path = r[4]; | |
} else { | |
console.error("error: bad url (\"%s\")", url); | |
process.exit(2); | |
} | |
var url_parse = /(?:url\:["'](.+?)['"]|load\(["'](.+?)['"]\)|(?:\(|=|:)\s*['"](\/*[\/%\w\d=_\.\-]+(\.[\w]*)\??)+)/gmi; | |
let http_data = ''; | |
http.get(http_options, (res) => { | |
if (res.statusCode != 200){ | |
console.error("error: status code %d", res.statusCode); | |
process.exitCode = 1; | |
return false; | |
} | |
res.on('data', (data) => { | |
if (r[3] == "https") | |
http_data += data.text; | |
else | |
http_data += data; | |
}) | |
.on('end', () => { | |
http_data = http_data.replace(/(;|\{|\})+/g, "$1\n"); | |
var parsed_data; | |
while (parsed_data = url_parse.exec(http_data)){ | |
var path; | |
if (parsed_data[1] == undefined) | |
path = parsed_data[0]; | |
else | |
path = parsed_data[1]; | |
path = path.replace(/^(?:[\(=:]["'])/g, ''); | |
//if (!/^\//.test(path)) | |
// path = "/"+path; | |
console.info(path); | |
} | |
}); | |
}).on('error', (error) => { | |
console.error(error.message); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment