function loadScript(url, callback) {
  var script = document.createElement("script");
  script.type = "text/javascript";
  if (script.readyState) {
    //IE
    script.onreadystatechange = function () {
      if (script.readyState == "loaded" || script.readyState == "complete") {
        script.onreadystatechange = null;
        if (callback) callback();
      }
    };
  } else {
    //Others
    script.onload = function () {
      if (callback) callback();
    };
  }
  script.src = url;
  var d = document.documentElement || document.body;
  d.appendChild(script);
}

var addEvent = (function () {
  if (document.addEventListener) {
    return function (e, type, fn) {
      e.addEventListener(type, fn, false);
    };
  } else {
    return function (e, type, fn) {
      e.attachEvent("on" + type, function () {
        return fn.call(e, window.event);
      });
    };
  }
})();
function GetQueryString(name) {
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  var r = window.location.search.substr(1).match(reg);
  if (r != null) {
    return unescape(r[2]);
  }
  return null;
}
var storageGoback = false;
// var openidArr = [
//   "oCO1wv6FAc1ZT4VkJY4tsqtzbOMs",
//   "oBHNyw5R7HFrPjRYgCgyMG6HKTeM",
//   "owanlso48zwT0RvoapODaKJLPMws",
// ];

var gobackF = function () {
  window.history.go(-1);
  setTimeout(function () {
    //gostory();
    location.href = "http://pvp.qq.com/story201904/index.html#/index";
  }, 300);
};
function gostory() {
  goback.style.backgroundImage =
    "url(https://game.gtimg.cn/images/yxzj/story201904/gohome.png)";
  goback.addEventListener(
    "click",
    function () {
      location.href = "http://pvp.qq.com/story201904/index.html#/index";
    },
    false
  );
}
//返回按钮添加事件
var goback = document.getElementById("btn-goback");
// if(goback){
//     goback.addEventListener("click",gobackF,false);
// }
function ingameGoBack() {
  document.body.classList.remove("iphonex");
  setTimeout(function () {
    document.body.classList.remove("iphonex");
  }, 300);
  gobackF = function () {
    // if(localStorage.openid=="owanlso48zwT0RvoapODaKJLPMws"){
    //     alert(storageGoback);
    // }
    if (history.length == 1 || storageGoback) {
      customBrowserInterface.closeWebview();
    } else {
      storageGoback = true;
      window.history.go(-1);
    }
  };
  if (!goback) {
    goback = document.createElement("div");
    goback.id = "btn-goback";
    goback.style =
      "position:absolute;display:none;width:14.842vmax;height:4.498vmax;top:0.4vmax;left:0; background:url(//game.gtimg.cn/images/yxzj/ingame/v2/index/back.png) no-repeat;background-size:100% auto;z-index:9999;transform:translateZ(0)";
    //width:1.85rem;height:.79rem
    //.cssText
    //    var wrapDom=document.getElementById("wrap");
    //    if(wrapDom){
    //     wrapDom.appendChild(goback);
    //    }else{
    document.body.appendChild(goback);
    setTimeout(function () {
      document.querySelector("#btn-goback").style.display = "block";
    }, 1000);

    //}
    //goback.onclick=gobackF;
  }
  goback.addEventListener("click", gobackF, false);
  goback.addEventListener(
    "touchstart",
    function (event) {
      event.stopPropagation();
    },
    false
  );
  goback.addEventListener(
    "touchmove",
    function (event) {
      event.stopPropagation();
    },
    false
  );
  goback.addEventListener(
    "touchend",
    function (event) {
      event.stopPropagation();
    },
    false
  );
  var mainNav = document.getElementById("mainNav");
  if (mainNav) {
    mainNav.style.paddingTop = "0.75rem";
  }
}
if (navigator.userAgent.indexOf("TIEM Ingame Browser/") != -1) {
  if (typeof customBrowserInterface == "object") {
    ingameGoBack();
  } else {
    loadScript(
      "https://ossweb-img.qq.com/htdocs/images/js/ingame_sdk/browser_adapt.js",
      function () {
        //localStorage.openid=="owanlso48zwT0RvoapODaKJLPMws"||
        ingameGoBack();
      }
    );
  }
} else {
  if (goback) {
    goback.addEventListener("click", gobackF, false);
  }
}
if (localStorage.getItem("audioPlay") == "abc") {
  if (history.length == 1 && goback) {
    gostory();
  }
}
//分享
function shareF(title, desc, imgurl, actName) {
  // loadScript("https://ossweb-img.qq.com/images/js/TGMobileShare/TGMobileShare.min.js", function () {
  //     TGMobileShare({
  //         shareTitle: title, //不设置或设置为空时，页面有title，则调取title
  //         shareDesc: desc, //不设置或设置为空时，页面有Description，则调取Description
  //         shareImgUrl: imgurl, //分享图片尺寸200*200，且填写绝对路径
  //         actName: tcssObj.siteType //点击流命名，用于统计分享量，专题一般采用目录名称如a20151029demo
  //     });
  // });
  if (typeof mobileCommonShare == "object") {
    mobileCommonShare.init({
      title: title, //不设置或设置为空时，页面有title，则调取title
      desc: desc, //不设置时，页面有Description，则调取Description
      imgUrl: imgurl,
      //分享图片尺寸200*200，大小控制在10k左右，且填写绝对路径以https://开头
      actName: actName || tcssObj.siteType, //点击流命名，用于统计分享量，专题一般采用目录名称如a20151029demo,不设置或设置为空时,调取setSite.siteType
    });
  } else {
    loadScript(
      "https://ossweb-img.qq.com/images/js/commom/mobileCommonShare.js",
      function () {
        mobileCommonShare.init({
          title: title, //不设置或设置为空时，页面有title，则调取title
          desc: desc, //不设置时，页面有Description，则调取Description
          imgUrl: imgurl,
          //分享图片尺寸200*200，大小控制在10k左右，且填写绝对路径以https://开头
          actName: actName || tcssObj.siteType, //点击流命名，用于统计分享量，专题一般采用目录名称如a20151029demo,不设置或设置为空时,调取setSite.siteType
        });
      }
    );
  }
}

if ("undefined" == typeof tcssObj) {
  var tcssObj = {};
}
tcssObj.startTime = new Date().getTime();
tcssObj.ua = window.navigator.userAgent.toLowerCase();
tcssObj.browser = tcssObj.system = tcssObj.network = "other";
function tcssF(str) {
  tcssFiltr(tcssObj.tcssstr + str);
}
function tcssClick(str) {
  tcssFiltr(str);
}
function tcssUser(str) {
  tcssFiltr(tcssObj.webUser + str);
}
function tcssFiltr(str) {
  var len = 4 - str.split(".").length;
  for (var i = len; i > 0; i--) {
    str += "./";
  }
  pgvSendClick({ hottag: str });
}
function tcssStart() {
  var url = window.location.href;
  url = url.split("/");
  if ("object" == typeof setSite) {
    tcssObj.siteType = setSite.siteType;
    tcssObj.page = setSite.pageType;
    if (setSite.project != undefined && setSite.project != "") {
      tcssObj.project = setSite.project;
      tcssFiltr(
        "story." +
          setSite.project +
          "." +
          setSite.siteType +
          "." +
          setSite.pageType
      );
    } else {
      tcssObj.project = "other";
      tcssFiltr("story.other." + setSite.siteType + "." + setSite.pageType);
    }
  } else {
    console.log("NOT PTT");
    if (tcssObj.siteType == undefined) {
      for (var i = url.length - 1; i > -1; i--) {
        if (url[i].match(/a\d+[A-z]+/) == url[i]) {
          tcssObj.siteType = url[i];
        }
      }
    }
    if (tcssObj.page == undefined) {
      if (url[url.length - 1].indexOf(".htm") > -1) {
        tcssObj.page = url[url.length - 1].split(".")[0];
      } else {
        tcssObj.page = "index";
      }
    }
  }
  tcssObj.tcssstr = tcssObj.siteType + "." + tcssObj.page;
  tcssObj.webUser = tcssObj.siteType + ".user";

  tcssF(".web.pv");
  //浏览器
  if (tcssObj.ua.indexOf("msdk") > -1) {
    tcssObj.browser = "msdk";
  } else {
    if (tcssObj.ua.indexOf("micromessenger") > -1) {
      tcssObj.browser = "weixin";
    }
  }

  //平台
  if (/iphone|ipad|ipod/.test(tcssObj.ua)) {
    tcssObj.system = "ios";
  } else {
    if (/android|adr/.test(tcssObj.ua)) {
      tcssObj.system = "android";
    } else {
      tcssObj.system = "pc";
    }
  }

  //分辨率
  tcssObj.clientWidth =
    document.documentElement.clientWidth || document.body.clientWidth;
  tcssObj.clientHeight =
    document.documentElement.clientHeight || document.body.clientHeight;

  //页面停留时长
  tcssObj.staytime = 0;
  tcssObj.addtime = 1;
  function stayF() {
    setTimeout(function () {
      tcssObj.staytime += tcssObj.addtime;
      if (tcssObj.staytime > 9) {
        tcssObj.addtime = 5;
        if (tcssObj.staytime > 59) {
          tcssObj.addtime = 10;
        }
      }
      tcssF(".staytime." + tcssObj.staytime);
      if (tcssObj.staytime < 599) {
        stayF();
      }
    }, tcssObj.addtime * 1000);
  }
  // if (/\.qq\.com/.test(location.hostname)) {
  //     stayF();
  // }
  //页面加载时长
  addEvent(window, "load", function () {
    var loadtime = new Date();
    loadtime = Math.round((loadtime.getTime() - tcssObj.startTime) / 500) * 0.5;
    tcssF(".loadtime." + loadtime);
    tcssF(".loadtime_all.user");
    if (loadtime > 5) {
      tcssF(".loadtime_all.slowuser");
    }
  });
  //浏览器
  tcssUser(".browser." + tcssObj.browser);
  //平台
  tcssUser(".system." + tcssObj.system);
  //分辨率
  tcssUser(".resolution." + screen.width + "*" + screen.height);
  //访问时段
  tcssUser(".visit_time." + new Date().getHours());

  var tcssinfostr =
    "%c--------------------START------------------\n%cTcss\u63d0\u793a\n%c\u6848\u0020\u4F8B\u0020\u540d\uff1a%c" +
    tcssObj.siteType +
    "\n%c\u9875\u0020\u9762\u0020\u540d\uff1a%c" +
    tcssObj.page +
    "\n%c\u9879\u0020\u76EE\u0020\u540D\uff1a%c" +
    tcssObj.project +
    "\u0020\u0020//\u76AE\u80A4\u7AD9\u8BBE\u7F6Eskin" +
    "\n%c\u6d4f\u0020\u89c8\u0020\u5668\uff1a%c" +
    tcssObj.browser +
    "\n%c\u5e73\u3000\u3000\u53f0\uff1a%c" +
    tcssObj.system +
    "\n%c分 辨 率：%c" +
    tcssObj.clientWidth +
    "*" +
    tcssObj.clientHeight +
    "\n%c\u8bbf\u95ee\u65f6\u6bb5\uff1a%c" +
    new Date().getHours() +
    "\u70b9\n%c--------------------END--------------------";
  console.log(
    tcssinfostr,
    "color:#989a9d;",
    "font-size:20px;",
    "color:#000;",
    "color:green;",
    "color:#000;",
    "color:green;",
    "color:#000;",
    "color:green;",
    "color:#000;",
    "color:green;",
    "color:#000;",
    "color:green;",
    "color:#000;",
    "color:green;",
    "color:#000;",
    "color:green;",
    "color:#989a9d;"
  );
}

if (
  /\.qq\.com/.test(location.hostname) &&
  typeof pgvMain == "function" &&
  typeof setSite == "object"
) {
  if (!window.Tcss.url) {
    pgvMain();
  }
  if (typeof pgvSendClickForPTT == "function") {
    pgvSendClick = pgvSendClickForPTT;
  }
} else {
  shareF = function () {};
  pgvSendClick = function (str) {
    //console.log(str.hottag);
  };
}
function PTTCallback() {
  tcssStart();
}
tcssStart();

// if(window.sessionStorage&&typeof(setSite) == "object"){
//     //当前页面是主站
//     if((setSite.siteType=="storyweb"&&setSite.pageType!="map")||setSite.siteType=="herostory"){
//         //当前页面是主站
//         if(sessionStorage.siteType){
//             if(sessionStorage.siteType=="story"||sessionStorage.siteType=="herostory"){
//                 //上一个页面是主站或是英雄
//                 tcssFiltr("storylink.story."+setSite.pageType+"."+sessionStorage.pageType);
//             }else{
//                 //上一个页面是皮肤站或是区域站或是其他站点
//                 tcssFiltr("storylink.other."+sessionStorage.siteType+"."+sessionStorage.pageType);
//             }
//         }else{
//             tcssFiltr("storylink.other.one");
//         }
//     }else{
//     //当前页面不是主站，但是上一个页面是主站
//         if(sessionStorage.siteType=="story"||sessionStorage.siteType=="herostory"){
//             tcssFiltr("storygo."+setSite.siteType+"."+setSite.pageType);
//         }
//     }

//     //为下一个页面做主站类型标记
//     sessionStorage.pageType=setSite.pageType;
//     if((setSite.siteType=="storyweb"&&setSite.pageType!="map")){
//         sessionStorage.siteType="story";
//     }else{
//         if(setSite.siteType=="herostory"){
//             sessionStorage.siteType="herostory";
//             sessionStorage.pageType="hero";
//         }else{
//             sessionStorage.siteType=setSite.siteType;
//         }
//     }
// }

/*  |xGv00|2ef64ef53887eff8c720bd85ad17c8bb */
