mirror of
https://github.com/gnh1201/caterpillar.git
synced 2024-11-26 15:31:45 +00:00
Update console.html
This commit is contained in:
parent
6aebfa3cd3
commit
8c02b81c0a
27
console.html
27
console.html
|
@ -16,11 +16,21 @@
|
||||||
<script type="text/javascript">//<!--<![CDATA[
|
<script type="text/javascript">//<!--<![CDATA[
|
||||||
var env = {
|
var env = {
|
||||||
"target": "http://localhost/",
|
"target": "http://localhost/",
|
||||||
"method": ""
|
"method": "",
|
||||||
|
"filename": null
|
||||||
};
|
};
|
||||||
var pretty_jsonify = function(data) {
|
var pretty_jsonify = function(data) {
|
||||||
return JSON.stringify(data, null, 4);
|
return JSON.stringify(data, null, 4);
|
||||||
};
|
};
|
||||||
|
var download_text = function(filename, text) {
|
||||||
|
var element = document.createElement('a');
|
||||||
|
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
|
||||||
|
element.setAttribute('download', filename);
|
||||||
|
element.style.display = 'none';
|
||||||
|
document.body.appendChild(element);
|
||||||
|
element.click();
|
||||||
|
document.body.removeChild(element);
|
||||||
|
}
|
||||||
var jsonrpc2_request = function(term, method, params) {
|
var jsonrpc2_request = function(term, method, params) {
|
||||||
var requestData = {
|
var requestData = {
|
||||||
jsonrpc: "2.0",
|
jsonrpc: "2.0",
|
||||||
|
@ -39,15 +49,22 @@
|
||||||
xhr.setRequestHeader("X-User-Agent", "php-httpproxy/0.1.5 (Client; WebConsole; abuse@catswords.net)");
|
xhr.setRequestHeader("X-User-Agent", "php-httpproxy/0.1.5 (Client; WebConsole; abuse@catswords.net)");
|
||||||
},
|
},
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
|
var text = "";
|
||||||
if ("error" in response) {
|
if ("error" in response) {
|
||||||
term.echo(response.error.message);
|
text = response.error.message;
|
||||||
} else {
|
} else {
|
||||||
if (typeof response.result.data === "object") {
|
if (typeof response.result.data === "object") {
|
||||||
term.echo(pretty_jsonify(response.result.data));
|
text = pretty_jsonify(response.result.data);
|
||||||
} else {
|
} else {
|
||||||
term.echo(response.result.data);
|
text = response.result.data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
term.echo(text);
|
||||||
|
|
||||||
|
// save as a file
|
||||||
|
if (env.filename != null) {
|
||||||
|
download_text(env.filename, text);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
error: function(xhr, status, error) {
|
error: function(xhr, status, error) {
|
||||||
term.echo(error);
|
term.echo(error);
|
||||||
|
@ -63,7 +80,7 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
env[k] = v;
|
env[k] = v || null;
|
||||||
|
|
||||||
if (k == "method") {
|
if (k == "method") {
|
||||||
this.set_prompt('method([[b;red;black]' + env.method + '])> ');
|
this.set_prompt('method([[b;red;black]' + env.method + '])> ');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user