/**
 * Created by webshow on 2019/11/22.
 */
 var bbb = location.href;
 if (bbb.indexOf("footseen.xyz") > -1) {
    $ip = "https://cpapi.footseen.xyz/";
    $ws = "wss://websocket.footseen.xyz:12308/"
    if(bbb.indexOf("libaiCensor")==-1){
        checkIp()
    }
}
else{
    $ip='http://cpapitest.yabolive.net:81/'
    $ws = "ws://47.242.178.187:12308/"
}

//移動端
if (bbb.indexOf("footseen.xyz/video.html") > -1) {
    $ip = 'https://webserver.yabolive.net';
    $ws='wss://zhiboweb.ishuaji.cn/yzsocket/ws?type=2'
    $url ='https://activity.ishuaji.cn/'
    $pay='https://pay.ishuaji.cn/'
    $api='https://zhibo.lvdou66.com/'
    checkIp()
}

// $ip = "https://cpapi.footseen.xyz/";
// $ws = "wss://websocket.footseen.xyz:12308/"
 var data = url_get_params(bbb)
 if (sessionStorage.kkk == undefined) {
     sessionStorage.kkk = data.token; //t
     sessionStorage.bbb = data.uid; //u
     sessionStorage.version = data.appversion;
     sessionStorage.pkg=data.pkg
 }
 if(sessionStorage.roomId==data.roomId){
    sessionStorage.ref=1
    sessionStorage.roomId = data.roomId;
 }else{
    sessionStorage.roomId = data.roomId;
    sessionStorage.ref=0
 }

sessionStorage.topicId=data.topicId
sessionStorage.go=data.go
if(data.tag==undefined||data.tag=='undefined')data.tag=''
if(sessionStorage.pmt==undefined||sessionStorage.pmt=="undefined"){
    sessionStorage.pmt=data.pmt
}

if(sessionStorage.pmt!=undefined&&sessionStorage.pmt!="undefined"){
    var pmtNumber=sessionStorage.pmt.split('/d/')[1]
    myCid='ftsweb'
    $.ajax({
        url:$ip+'frontPage/queryLinkNumberCid',
        type: 'get',
        data:{
            lang:2,
            os:'pc_web',
            cid:'ftsweb',
            webVersion:'1000',
            linkNumber:pmtNumber,
            // pageID:localStorage.canvasCode,
        },
        dataType: "JSON",
        async:false,
        success:function(data){
            console.log(data)
            if(data.code==1){
               myCid=data.pcCid
               sessionStorage.apkDown=data.downloadLink
            }
        }
    })
     //ajax设置默认参数
    $.ajaxSetup({
        global: false,
        type: 'get',
        data: {
            lang:2,
            os:'pc_web',
            cid:myCid,
            webVersion:'1000'
        },
        dataType: "JSON"
    })
}else{
 //ajax设置默认参数
    $.ajaxSetup({
        global: false,
        type: 'get',
        data: {
            lang:2,
            os:'pc_web',
            cid:'ftsweb',
            webVersion:'1000'
        },
        dataType: "JSON"
    })  
} 
sessionStorage.tag=data.tag
sessionStorage.qd=data.qd
sessionStorage.like=data.like;
 if(sessionStorage.open==undefined)sessionStorage.open=1
//跳轉移動端
var ua = window.navigator.userAgent.toLowerCase();
try {

    if(ua.indexOf('Googlebot')>-1){
    
    }else{
        if (/iphone|ipad|ipod/.test(ua)) {
            if (bbb.indexOf("/videoRoom") > -1){
                window.location.href='https://www.footseen.xyz/mobile/video.html?topicId='+sessionStorage.topicId+'&tag='+sessionStorage.tag+''
            }else if(bbb.indexOf("/imagesRoom") > -1){
                window.location.href='https://www.footseen.xyz/mobile/Graphics.html?topicId='+sessionStorage.topicId+'&tag=';
            }
            else window.location.href="https://www.footseen.xyz/mobile/index.html"
    
        } else if (/android/.test(ua)) {
            if (bbb.indexOf("/videoRoom") > -1){
                window.location.href='https://www.footseen.xyz/mobile/video.html?topicId='+sessionStorage.topicId+'&tag='+sessionStorage.tag+''
            }else if(bbb.indexOf("/imagesRoom") > -1){
                window.location.href='https://www.footseen.xyz/mobile/Graphics.html?topicId='+sessionStorage.topicId+'&tag=';
            }
            else window.location.href="https://www.footseen.xyz/mobile/index.html"
        }
    }

} catch (e) {
}
 try {
     if (/iphone|ipad|ipod/.test(ua)) {
         sessionStorage.os='ios'
     } else if (/android/.test(ua)) {
         sessionStorage.os='android'
     }
 } catch (e) {
 }
 function checkIp() {
    $.ajax({
        url:"https://webserver.yabolive.net/user/checkIpIsChina.html",
        async: false,
        success: function (res) {
            var result = JSON.parse(res);
            if (result.code === 1) {
                if (result.checkResult) {
                    window.location.hash = "no-back";
                    window.location.hash = "Again-No-back-button";
                    window.onhashchange = function () { window.location.hash = "no-back"; }
                    window.location.href = 'https://www.footseen.xyz/content.html?ip=' + result.ip;
                }
            }
        }
    })
}
 function url_get_params(url_path) {
     var url = url_path;
     var theRequest = new Object();
     if (url.indexOf("?") != -1) {
         var str = url.substr(url.indexOf("?") + 1);
         strs = str.split("&");
         for (var i = 0; i < strs.length; i++) {
             theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
         }
     }
     return theRequest;
 }

 if (bbb.indexOf("file:///") > -1) {

 }



 //点击刷新
 $(".ref").on("click", function () {
     sessionStorage.jump=undefined;
     window.location.reload()
 })
 $(".callKf").on("click",function(){
    callFK()
})
 function btnHref(e){
     var myJson = {
         "cid": 12,
         "reqCode": new Date().getTime(),
         "data": {
             "msg":'跳转页面',
             "jump": e,
         }
     }
     var obj=JSON.stringify(myJson);
     appCollaboration(obj)
 }

stat()
webActive()
function stat(){
    if(sessionStorage.stat==1)return;
    if(localStorage.canvasCode=="oneEnter"||localStorage.canvasCode==undefined)return
    if(localStorage.token!==undefined){
        $.ajax({
            url:$ip+'stat/log',
            data:{
                resolution:screen.width+'*'+screen.height,
                pageID:localStorage.canvasCode,
                uid:localStorage.uid
            },
            success:function(data){
                // console.log('上報',data)
                sessionStorage.stat=1
            }
        })
        return;
    }
    $.ajax({
        url:$ip+'stat/log',
        data:{
            resolution:screen.width+'*'+screen.height,
            pageID:localStorage.canvasCode
        },
        success:function(data){
            // console.log('上報',data)
            sessionStorage.stat=1
        }
    })
}
function webActive(){
    if(sessionStorage.stat2==1)return;
    if(localStorage.canvasCode=="oneEnter"||localStorage.canvasCode==undefined)return;
    $.ajax({
        url:$ip+'activeLog/webActive',
        data:{
            activeType:0,
            pageID:localStorage.canvasCode,
        },
        success:function(data){
            sessionStorage.stat2=1
        }
    })
    if(localStorage.uid==undefined||localStorage.uid=='undefined')return;
    $.ajax({
        url:$ip+'activeLog/webActive',
        data:{
            activeType:7,
            pageID:localStorage.canvasCode,
            uid:localStorage.uid
        },
        success:function(data){
            sessionStorage.stat2=1
        }
    })
}
 //与客户端交互
 function appCollaboration(msg) {
     var ua = window.navigator.userAgent.toLowerCase();
     try {
         if (/iphone|ipad|ipod/.test(ua)) {
             window.webkit.messageHandlers.appCollaboration.postMessage(msg);
         } else if (/android/.test(ua)) {
             window.yazhai.appCollaboration(msg);
         }
     } catch (e) {
     }
 }
 //处理时间倒计时的函数
 function timeDeal(e,time){
     var endTime=e;
     var newTime=time;
     var Remain=Math.floor((endTime-newTime)/1000);
    //  if(Remain<=0)window.location.reload();
     var day=Math.floor(Remain/86400);
     var hour=add0(Math.floor(Remain%86400/3600));
     if(hour>99)hour=99;
     var min=add0(Math.floor(Remain%3600/60));
     var sceond=add0(Math.floor(Remain%60));
     var timeArr=[day,hour,min,sceond];
     return timeArr;
 }
 function timeDeal2(e,time){
     var endTime=e;
     var newTime=time;
     var Remain=Math.floor((endTime-newTime)/1000);
     if(Remain<=0)Remain=0
     var bbb = location.href;
     if (bbb.indexOf("https://activity.ishuaji.cn/") > -1) {
        if(Remain<=0)window.location.reload();
     }
     var day=add0(Math.floor(Remain/86400));
     var hour=add0(Math.floor(Remain/3600));
     if(hour>99)hour=99;
     var min=add0(Math.floor(Remain%3600/60));
     var sceond=add0(Math.floor(Remain%100));
     var timeArr=[day,hour,min,sceond];
     return timeArr;
 }
 function getMyTime(){
     $.ajax({
         url:$ip+'activesys/getSysTimeStamp',
         async:false,
         success:function(data){
             myTime=data.timestamp
             return myTime
         }
     })
 }
 //时间戳转具体 年月日时分秒
 function timeGet(e){
     var time = new Date(Number(e));
     var y = time.getFullYear();
     var m = time.getMonth()+1;
     var d = time.getDate();
     var h = time.getHours();
     var mm = time.getMinutes();
     var s = time.getSeconds();
     var timeArr=[y,m,d,add0(h),add0(mm),s]
     return timeArr
 }
 function callFK(){
    var obj2 = {
        "cid": 4,
        "reqCode": new Date().getTime(),
        "data": {
            "msg": "请求客服",
        }
    }
    var obj = JSON.stringify(obj2);
    appCollaboration(obj)
}
 //一位数前面加0
 function add0(m) {
     return m < 10 ? '0' + m : m
 }
 function add00(m){
     if(m<10){
         return '00'+m
     }else if(m>10&&m<100){
         return '0'+m
     }else{
         return m
     }
 }
 function imgAdd(m){
     if(String(m).length > 5) return m;
     return (Array(5).join(0) + m).slice(-5);
 }
 //一万以上省略
 function addw(e){
     if(e>=100000000){
         return Math.floor((e/100000000).toFixed(2)*10)/10+'亿';
     }
     else if(e>=10000){
         return Math.floor((e/10000).toFixed(2)*10)/10+'万';
     }else{
         return Math.ceil(e);
     }
 }
 function loadImageGo(name,sNum,eNum) {
    var imgList = [];
    var num = sNum;
    loadImage()
    function loadImage() {
        var img = new Image();
        img.addEventListener("load", loadHandler);
        img.src = "images/" + name + "/1_" + imgAdd(num) + ".png";
    }
    function loadHandler() {
        imgList.push(this.cloneNode());
        num++;
        if (num > eNum) { return; }
        this.src = "images/" + name + "/1_" + imgAdd(num)  + ".png";
    }
}  
function loadImageGo3(name,sNum,eNum) {
    var imgList = [];
    var num = sNum;
    loadImage()
    function loadImage() {
        var img = new Image();
        img.addEventListener("load", loadHandler);
        img.src = "images/" + name + "/(" + num + ").png";
    }
    function loadHandler() {
        imgList.push(this.cloneNode());
        num++;
        if (num > eNum) { return; }
        this.src = "images/" + name + "/(" + num + ").png";
    }
}   
 function addDoc(e){
     if(e%1==0){
         return e+'.0';
     }else return e
 }

 function scrollTo(element,speed) {
     if(!speed){
         speed = 300;
     }
     if(!element){
         $("html,body").animate({scrollTop:0},speed);
     }else{
         if(element.length>0){
             $("html,body").animate({scrollTop:$(element).offset().top-70},speed);
         }
     }
 }
 
 //var betEnd = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate(), new Date().getHours(), 59, 59).getTime();