-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.js
104 lines (95 loc) · 4.21 KB
/
debug.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Debugger ver 1.0 by Gleb
*
* debug.log method show massage in DOM element
* accept:
* @param {String}
*
* debug.error method show error massage in DOM element with red color
* accept:
* @param {String}
*
* for manual test uncomment string 17
*
* param names showOffLine debug
* */
function Debugger (){
var manualDebug = false;
var manualDebug = true;
this.init = function (){
var conf = adapi.getConfiguration();
//conf.param["showOffLine"] = true;
if (conf.param["showOffLine"]) {
$(function () {
var connection;
$("body").append("<div id='connetction' style='background: red; z-index: 10001;color: white; display: none; position: absolute; top:0; padding: 20px;font-size: 50px';>Connection problem!</div>")
setInterval(function () {
if (!connection) {
$("#connetction").show();
$("#connect").text("NO");
} else {
$("#connetction").hide();
$("#connect").text("OK");
}
connection = false;
}, timeout * 4); //timeout * 4 must be include success request but if connection unstable that excludes flicker
$(document).bind("ajaxSuccess", connectionOn)
.bind("ajaxError", connectionOff );
function connectionOn(){
$("#connect").text("OK");
$("#connetction").hide();
connection = true;
}
function connectionOff(){
$("#connect").text("NO");
$("#connetction").show();
connection = false;
}
});
}
if (!conf.param["debug"]&&!manualDebug) return;
this.starttime = new Date().getTime();
$(function(){
window.onerror = function(e,url,lineNumber) {
debug.error("Error: " + e + "in url" + url + "at line" + lineNumber);
};
$('body').prepend("<div id='debug' style='top:0;background-color: white;color:black;position:absolute; z-index: 10000;font-size:25px;width:1920px'></div>")
$('#debug')
.append("<ol id='debug-toolbar' style='border: 1px black solid; padding: 20px;margin:10px 35px ;'</ol>")
.append("<ol id='debug-list' style=';padding-left: 60px; list-style-type:decimal; display:block;float: left' type='1' ></ol>");
$("#debug-toolbar")
.append("<li style='display: inline;padding: 15px 40px'>Internet connetion: <span id='connect'></span> </li>")
.append("<li style='display: inline;padding: 15px 40px'>Current IP: <span id='ip'></span> </li>")
.append("<li style='display: inline;padding: 15px 40px'>Player ID: <span id='playerID'></span> </li>")
.append("<li style='display: inline;padding: 15px 40px'>Player time:"+ new Date() +"</li>");
$.ajax({
url: 'http://widgets01.cms-ds.com/getip.php',
type: 'GET',
success: function (response) {
if (response) {
var data = JSON.parse(response);
if (data) {
$("#connect").text("OK");
$("#ip").text(data.ip);
$("#playerID").text("123456789");
}
}
},
error: function (data,errorType) {
var error = (errorType == "abort" ? "NO" : errorType);
$("#connect").text(error);
}
});
})
};
this.log = function (text){
if (!conf.param["debug"]&&!manualDebug) return;
$('#debug-list').append("<li>"+text+" milisec from star: "+((new Date).getTime()-this.starttime)+"</li>");
};
this.error = function (text){
if (!conf.param["debug"]&&!manualDebug) return;
$('#debug-list').append("<li style='color: red'>"+text+" milisec from star: "+((new Date).getTime()-this.starttime)+"</li>");
};
}
var debug = new Debugger();
debug.init();