52 lines
1.7 KiB
JavaScript
52 lines
1.7 KiB
JavaScript
#!/usr/bin/env node
|
|
const esprima = require('esprima');
|
|
const cheerio = require('cheerio');
|
|
const axios = require('axios');
|
|
|
|
let url = null;
|
|
|
|
for(let i=0; i<process.argv.length; i++) {
|
|
const arg = process.argv[i];
|
|
if(arg.startsWith("http://") || arg.startsWith("https://")) {
|
|
url = arg;
|
|
}
|
|
}
|
|
|
|
if(url !== null) {
|
|
axios.get(url).then((resp) => {
|
|
const dom = cheerio.load(resp.data, {xmlMode: false});
|
|
const tags = dom('script').get();
|
|
const data = {};
|
|
let props = [];
|
|
for(let i=0; i<tags.length; i++) {
|
|
const children = tags[i].children;
|
|
for(let j=0; j<children.length; j++) {
|
|
let tdata = {};
|
|
let assign = true;
|
|
try {
|
|
tdata = children[j].data;
|
|
} catch(err) {
|
|
assign = false;
|
|
console.log(err);
|
|
}
|
|
if(assign) {
|
|
const script = esprima.parseScript(tdata);
|
|
for(let k=0; k<script.body.length; k++) {
|
|
const prop = script.body[k].expression.right.properties;
|
|
for(let l=0; l<prop.length; l++) {
|
|
props = [...props, ...(prop[l].value.properties)];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
for(let i=0; i<props.length; i++) {
|
|
const prop = props[i];
|
|
if((prop.key.type === "Identifier") && (prop.value.type === "Literal") && (prop.value.value != "")) {
|
|
data[prop.key.name] = prop.value.value;
|
|
}
|
|
}
|
|
console.log(JSON.stringify(data));
|
|
})
|
|
}
|