"use strict";
// 页面停留时长
// initstatistics()
Object.defineProperty(exports, "__esModule", { value: true });
var NetManager_1 = require("../../libs/tw/manager/NetManager");
var startTimer = new Date().getTime();
var endTimer;
//设置隐藏属性和改变可见属性的事件的名称
var hidden, visibilityChange;
if (typeof document.hidden !== 'undefined') {
    hidden = 'hidden';
    visibilityChange = 'visibilitychange';
}
else if (typeof document['msHidden'] !== 'undefined') {
    hidden = 'msHidden';
    visibilityChange = 'msvisibilitychange';
}
else if (typeof document['webkitHidden'] !== 'undefined') {
    hidden = 'webkitHidden';
    visibilityChange = 'webkitvisibilitychange';
}
var handleVisibilityChange = function (e) {
    if (document.visibilityState == "visible") {
        startTimer = new Date().getTime();
        console.log('starttimer', startTimer);
    }
    if (document.visibilityState == "hidden") {
        endTimer = new Date().getTime();
        console.log('endTimer', endTimer);
        sendData();
    }
};
var sendData = function () {
    var t0 = endTimer - startTimer;
    console.log('停留时间是', t0);
    if (localStorage.getItem('xxl_first_statistics') == null) {
        // NetManager.ins.remainDuration(t0, true);
        NetManager_1.NetManager.ins.remainDurationProjectX(t0, true);
        localStorage.setItem('xxl_first_statistics', '1');
    }
    else {
        // NetManager.ins.remainDuration(t0, false);
        NetManager_1.NetManager.ins.remainDurationProjectX(t0, false);
    }
};
exports.initstatistics = function () {
    document.addEventListener(visibilityChange, handleVisibilityChange, false);
    document.body['onbeforeunload'] = function () {
        endTimer = new Date().getTime();
        return sendData();
    };
};
//# sourceMappingURL=statistics.js.map