-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstat.js
executable file
·59 lines (51 loc) · 1.69 KB
/
stat.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
/*
* Скрипт подсчета времени пребывания пользователя на странице портала.
* @author fvn-20120323 v.1
*/
var mediamStatHash = '';
var mediamStatCount = 0;
var mediamTime0 = 0;
var mediamTime1 = 0;
var mediamStatMax = 0;
var mediamStatTimer = null;
var mediamStatUrl = '';
function sendTimer(p) {
var r = false;
if (window.XMLHttpRequest) {
r = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {
r = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
r = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) { }
}
}
if (!r) return false;
r.open('POST', mediamStatUrl, true);
r.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
r.setRequestHeader("Accept","application/json");
// r.setRequestHeader("Content-length", p.length);
r.setRequestHeader("Connection", "close");
r.setRequestHeader("X_REQUESTED_WITH", "XMLHttpRequest");
r.send(p + '&rnd='+Math.random());
}
function mediamTimer() {
clearTimeout(mediamStatTimer);
if( ++mediamStatCount <= mediamStatMax ) {
sendTimer('h=' + mediamStatHash + '&c=' + mediamStatCount + '&t='+mediamTime1);
if( mediamStatCount % 2 == 0) {
mediamTime1 = mediamTime1 + mediamTime1;
}
mediamStatTimer = setTimeout(mediamTimer, mediamTime1);
}
}
function stat2mediam(data) {
mediamStatCount = 0;
mediamStatUrl = data.statUrl;
sendTimer('h=' + (mediamStatHash=data.hash) + '&d=1' + '&sw=' + screen.width + '&sh=' + screen.height
+ '&t=' + (mediamTime0=mediamTime1=data.period) + '&m=' + (mediamStatMax=data.maxPeriod)
);
window.onload = function() { mediamStatTimer = setTimeout(mediamTimer , data.period); }
}