Skip to content

Instantly share code, notes, and snippets.

@ecwu
Last active December 24, 2018 08:00
Show Gist options
  • Save ecwu/e451017418f249760114ea1556f48cad to your computer and use it in GitHub Desktop.
Save ecwu/e451017418f249760114ea1556f48cad to your computer and use it in GitHub Desktop.
[Server status checker] #JavaScript
function tableMaker(num,name,status,detail,domain,style){
var table = "<td>" + num + "</td>" + "<td>" + name + "</td>" + "<td class='" + style + "'>" + status + "</td>" + "<td>" + detail + "</td>" + "<td>" + domain + "</td>";
return table;
}
function inlineContentsGenerator(order,requestUrl,siteName,id){
respondCode = get_status_code(requestUrl);
if (respondCode === "200"){
var contents = tableMaker(order,siteName,"Service Online",parseInt(respondCode),requestUrl,"btn-success");
}else{
var contents = tableMaker(order,siteName,"Service Unavailable",parseInt(respondCode),requestUrl,"btn-danger");
}
document.getElementById(id).innerHTML = contents;
}
/*
Respond Code Service Design by DRJ
*/
function get_status_code(checkURL){
var value = $.ajax(
{
type: 'get',
async: false,
url: 'https://demonist.top/status.php',
data: {
url: checkURL
},
dataType: 'jsonp',
jsonp: 'jsoncallback',
jsonpCallback:"success_jsonpCallback",
success: function (data) {
console.log(checkURL + ": " + data.status_code);
return data.status_code;
},
error: function () {
}
});
return parseInt(value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment