-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathconsole.js
More file actions
54 lines (51 loc) · 1.48 KB
/
console.js
File metadata and controls
54 lines (51 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var loc = window.location.pathname;
var dir = loc.substring(0, loc.lastIndexOf('/'));
var refreshtime=500;
function tc_console()
{
if(user.level === "admin" || user.level === "mod"){
asyncAjax("GET",dir + "/assets/api/console.php?d=" + server_select + "&s=console",Math.random(),display,{},"console");
}
asyncAjax("GET",dir + "/assets/api/console.php?d=" + server_select + "&s=chat",Math.random(),display,{},"chat");
setTimeout(tc_console,refreshtime);
}
function display(xhr,cdat,scr)
{
if(xhr.readyState==4 && xhr.status==200)
{
var scrollContainer = document.getElementById(scr);
var shouldScroll = scrollContainer.scrollTop + scrollContainer.offsetHeight >= scrollContainer.scrollHeight;
scrollContainer.innerHTML=xhr.responseText;
if(shouldScroll) {
scrollContainer.scrollTop = scrollContainer.scrollHeight;
}
}
}
function asyncAjax(method,url,qs,callback,callbackData,scr)
{
var xmlhttp=new XMLHttpRequest();
//xmlhttp.cdat=callbackData;
if(method=="GET")
{
url+="&t="+qs;
}
var cb=callback;
callback=function()
{
var xhr=xmlhttp;
//xhr.cdat=callbackData;
var cdat2=callbackData;
cb(xhr,cdat2,scr);
return;
};
xmlhttp.open(method,url,true);
xmlhttp.onreadystatechange=callback;
if(method=="POST"){
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xmlhttp.send(qs);
}
else
{
xmlhttp.send(null);
}
}