gamelebi.js 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305
  1. var _czc = _czc || [];
  2. !function(a,b){"function"==typeof define&&(define.amd||define.cmd)?define(function(){return b(a)}):b(a,!0)}(this,function(a,b){function c(b,c,d){a.WeixinJSBridge?WeixinJSBridge.invoke(b,e(c),function(a){i(b,a,d)}):l(b,d)}function d(b,c,d){a.WeixinJSBridge?WeixinJSBridge.on(b,function(a){d&&d.trigger&&d.trigger(a),i(b,a,c)}):d?l(b,d):l(b,c)}function e(a){return a=a||{},a.appId=B.appId,a.verifyAppId=B.appId,a.verifySignType="sha1",a.verifyTimestamp=B.timestamp+"",a.verifyNonceStr=B.nonceStr,a.verifySignature=B.signature,a}function f(a,b){return{scope:b,signType:"sha1",timeStamp:a.timestamp+"",nonceStr:a.nonceStr,addrSign:a.addrSign}}function g(a){return{timeStamp:a.timestamp+"",nonceStr:a.nonceStr,"package":a.package,paySign:a.paySign,signType:"SHA1"}}function i(a,b,c){var d,e,f;switch(delete b.err_code,delete b.err_desc,delete b.err_detail,d=b.errMsg,d||(d=b.err_msg,delete b.err_msg,d=j(a,d,c),b.errMsg=d),c=c||{},c._complete&&(c._complete(b),delete c._complete),d=b.errMsg||"",B.debug&&!c.isInnerInvoke&&alert(JSON.stringify(b)),e=d.indexOf(":"),f=d.substring(e+1)){case"ok":c.success&&c.success(b);break;case"cancel":c.cancel&&c.cancel(b);break;default:c.fail&&c.fail(b)}c.complete&&c.complete(b)}function j(a,b){var d,e,f,g;if(b){switch(d=b.indexOf(":"),a){case q.config:e="config";break;case q.openProductSpecificView:e="openProductSpecificView";break;default:e=b.substring(0,d),e=e.replace(/_/g," "),e=e.replace(/\b\w+\b/g,function(a){return a.substring(0,1).toUpperCase()+a.substring(1)}),e=e.substring(0,1).toLowerCase()+e.substring(1),e=e.replace(/ /g,""),-1!=e.indexOf("Wcpay")&&(e=e.replace("Wcpay","WCPay")),f=r[e],f&&(e=f)}g=b.substring(d+1),"confirm"==g&&(g="ok"),-1!=g.indexOf("failed_")&&(g=g.substring(7)),-1!=g.indexOf("fail_")&&(g=g.substring(5)),g=g.replace(/_/g," "),g=g.toLowerCase(),("access denied"==g||"no permission to execute"==g)&&(g="permission denied"),"config"==e&&"function not exist"==g&&(g="ok"),b=e+":"+g}return b}function k(a){var b,c,d,e;if(a){for(b=0,c=a.length;c>b;++b)d=a[b],e=q[d],e&&(a[b]=e);return a}}function l(a,b){if(B.debug&&!b.isInnerInvoke){var c=r[a];c&&(a=c),b&&b._complete&&delete b._complete,console.log('"'+a+'",',b||"")}}function m(){if(!("6.0.2">y)){var b=new Image;A.appId=B.appId,A.initTime=z.initEndTime-z.initStartTime,A.preVerifyTime=z.preVerifyEndTime-z.preVerifyStartTime,E.getNetworkType({isInnerInvoke:!0,success:function(a){A.networkType=a.networkType;var c="https://open.weixin.qq.com/sdk/report?v="+A.version+"&o="+A.isPreVerifyOk+"&s="+A.systemType+"&c="+A.clientVersion+"&a="+A.appId+"&n="+A.networkType+"&i="+A.initTime+"&p="+A.preVerifyTime+"&u="+A.url;b.src=c}})}}function n(){return(new Date).getTime()}function o(b){v&&(a.WeixinJSBridge?b():s.addEventListener&&s.addEventListener("WeixinJSBridgeReady",b,!1))}function p(){E.invoke||(E.invoke=function(b,c,d){a.WeixinJSBridge&&WeixinJSBridge.invoke(b,e(c),d)},E.on=function(b,c){a.WeixinJSBridge&&WeixinJSBridge.on(b,c)})}var q,r,s,t,u,v,w,x,y,z,A,B,C,D,E;if(!a.jWeixin)return q={config:"preVerifyJSAPI",onMenuShareTimeline:"menu:share:timeline",onMenuShareAppMessage:"menu:share:appmessage",onMenuShareQQ:"menu:share:qq",onMenuShareWeibo:"menu:share:weiboApp",previewImage:"imagePreview",getLocation:"geoLocation",openProductSpecificView:"openProductViewWithPid",addCard:"batchAddCard",openCard:"batchViewCard",chooseWXPay:"getBrandWCPayRequest"},r=function(){var b,a={};for(b in q)a[q[b]]=b;return a}(),s=a.document,t=s.title,u=navigator.userAgent.toLowerCase(),v=-1!=u.indexOf("micromessenger"),w=-1!=u.indexOf("android"),x=-1!=u.indexOf("iphone")||-1!=u.indexOf("ipad"),y=function(){var a=u.match(/micromessenger\/(\d+\.\d+\.\d+)/)||u.match(/micromessenger\/(\d+\.\d+)/);return a?a[1]:""}(),z={initStartTime:n(),initEndTime:0,preVerifyStartTime:0,preVerifyEndTime:0},A={version:1,appId:"",initTime:0,preVerifyTime:0,networkType:"",isPreVerifyOk:1,systemType:x?1:w?2:-1,clientVersion:y,url:encodeURIComponent(location.href)},B={},C={_completes:[]},D={state:0,res:{}},o(function(){z.initEndTime=n()}),E={config:function(a){B=a,l("config",a),o(function(){c(q.config,{verifyJsApiList:k(B.jsApiList)},function(){C._complete=function(a){z.preVerifyEndTime=n(),D.state=1,D.res=a},C.success=function(){A.isPreVerifyOk=0},C.fail=function(a){C._fail?C._fail(a):D.state=-1};var a=C._completes;return a.push(function(){B.debug||m()}),C.complete=function(b){for(var c=0,d=a.length;d>c;++c)a[c](b);C._completes=[]},C}()),z.preVerifyStartTime=n()}),B.beta&&p()},ready:function(a){0!=D.state?a():(C._completes.push(a),!v&&B.debug&&a())},error:function(a){"6.0.2">y||(-1==D.state?a(D.res):C._fail=a)},checkJsApi:function(a){var b=function(a){var c,d,b=a.checkResult;for(c in b)d=r[c],d&&(b[d]=b[c],delete b[c]);return a};c("checkJsApi",{jsApiList:k(a.jsApiList)},function(){return a._complete=function(a){if(w){var c=a.checkResult;c&&(a.checkResult=JSON.parse(c))}a=b(a)},a}())},onMenuShareTimeline:function(a){d(q.onMenuShareTimeline,{complete:function(){c("shareTimeline",{title:a.title||t,desc:a.title||t,img_url:a.imgUrl,link:a.link||location.href},a)}},a)},onMenuShareAppMessage:function(a){d(q.onMenuShareAppMessage,{complete:function(){c("sendAppMessage",{title:a.title||t,desc:a.desc||"",link:a.link||location.href,img_url:a.imgUrl,type:a.type||"link",data_url:a.dataUrl||""},a)}},a)},onMenuShareQQ:function(a){d(q.onMenuShareQQ,{complete:function(){c("shareQQ",{title:a.title||t,desc:a.desc||"",img_url:a.imgUrl,link:a.link||location.href},a)}},a)},onMenuShareWeibo:function(a){d(q.onMenuShareWeibo,{complete:function(){c("shareWeiboApp",{title:a.title||t,desc:a.desc||"",img_url:a.imgUrl,link:a.link||location.href},a)}},a)},startRecord:function(a){c("startRecord",{},a)},stopRecord:function(a){c("stopRecord",{},a)},onVoiceRecordEnd:function(a){d("onVoiceRecordEnd",a)},playVoice:function(a){c("playVoice",{localId:a.localId},a)},pauseVoice:function(a){c("pauseVoice",{localId:a.localId},a)},stopVoice:function(a){c("stopVoice",{localId:a.localId},a)},onVoicePlayEnd:function(a){d("onVoicePlayEnd",a)},uploadVoice:function(a){c("uploadVoice",{localId:a.localId,isShowProgressTips:a.isShowProgressTips||1},a)},downloadVoice:function(a){c("downloadVoice",{serverId:a.serverId,isShowProgressTips:a.isShowProgressTips||1},a)},translateVoice:function(a){c("translateVoice",{localId:a.localId,isShowProgressTips:a.isShowProgressTips||1},a)},chooseImage:function(a){c("chooseImage",{scene:"1|2"},function(){return a._complete=function(a){if(w){var b=a.localIds;b&&(a.localIds=JSON.parse(b))}},a}())},previewImage:function(a){c(q.previewImage,{current:a.current,urls:a.urls},a)},uploadImage:function(a){c("uploadImage",{localId:a.localId,isShowProgressTips:a.isShowProgressTips||1},a)},downloadImage:function(a){c("downloadImage",{serverId:a.serverId,isShowProgressTips:a.isShowProgressTips||1},a)},getNetworkType:function(a){var b=function(a){var c,d,e,b=a.errMsg;if(a.errMsg="getNetworkType:ok",c=a.subtype,delete a.subtype,c)a.networkType=c;else switch(d=b.indexOf(":"),e=b.substring(d+1)){case"fail":case"permission denied":case"localparameters":a.errMsg="getNetworkType:fail";break;default:a.networkType=e}return a};c("getNetworkType",{},function(){return a._complete=function(a){a=b(a)},a}())},openLocation:function(a){c("openLocation",{latitude:a.latitude,longitude:a.longitude,name:a.name||"",address:a.address||"",scale:a.scale||28,infoUrl:a.infoUrl||""},a)},getLocation:function(a){c(q.getLocation,f(a,"jsapi_location"),a)},hideOptionMenu:function(a){c("hideOptionMenu",{},a)},showOptionMenu:function(a){c("showOptionMenu",{},a)},closeWindow:function(a){c("closeWindow",{immediate_close:a&&a.immediateClose||0},a)},hideMenuItems:function(a){c("hideMenuItems",{menuList:a.menuList},a)},showMenuItems:function(a){c("showMenuItems",{menuList:a.menuList},a)},hideAllNonBaseMenuItem:function(a){c("hideAllNonBaseMenuItem",{},a)},showAllNonBaseMenuItem:function(a){c("showAllNonBaseMenuItem",{},a)},scanQRCode:function(a){c("scanQRCode",{desc:a.desc,needResult:a.needResult||0,scanType:a.scanType||["qrCode","barCode"]},a)},openProductSpecificView:function(a){c(q.openProductSpecificView,{pid:a.productId,view_type:a.viewType||0},a)},addCard:function(a){var e,f,g,h,b=a.cardList,d=[];for(e=0,f=b.length;f>e;++e)g=b[e],h={card_id:g.cardId,card_ext:g.cardExt},d.push(h);c(q.addCard,{card_list:d},function(){return a._complete=function(a){var c,d,e,b=a.card_list;if(b){for(b=JSON.parse(b),c=0,d=b.length;d>c;++c)e=b[c],e.cardId=e.card_id,e.cardExt=e.card_ext,e.isSuccess=e.is_succ?!0:!1,delete e.card_id,delete e.card_ext,delete e.is_succ;a.cardList=b,delete a.card_list}},a}())},chooseCard:function(a){c("chooseCard",{app_id:B.appId,location_id:a.shopId||"",sign_type:"SHA1",card_id:a.cardId||"",card_type:a.cardType||"",card_sign:a.cardSign,time_stamp:a.timestamp+"",nonce_str:a.nonceStr},function(){return a._complete=function(a){a.cardList=a.choose_card_info,delete a.choose_card_info},a}())},openCard:function(a){var e,f,g,h,b=a.cardList,d=[];for(e=0,f=b.length;f>e;++e)g=b[e],h={card_id:g.cardId,code:g.code},d.push(h);c(q.openCard,{card_list:d},a)},chooseWXPay:function(a){c(q.chooseWXPay,g(a),a)}},b&&(a.wx=a.jWeixin=E),E});
  3. GameLeBi = function(gameid, cpid) {
  4. this.gameid = gameid || null;
  5. this.game = null;
  6. this.cpid = cpid || null;
  7. this.spid = null;
  8. this.source = null;
  9. this.animalid = null;
  10. this.fromid = null;
  11. this.fromuser = null;
  12. this.baseurl = "http://game.ikongzhong.cn";
  13. this.gameurl = null;
  14. this.homeurl = null;
  15. this.gzurl = null;
  16. this.moreurl = null;
  17. this.score = null;
  18. this.scoreName = null;
  19. this.shareDomain = null;
  20. this.shareDomains = ["dm15.net", "dm15.com"];
  21. this.shareData = {
  22. imgurl: "http://game.ikongzhong.cn/img/icon.png",
  23. link: this.baseurl,
  24. title: "乐比游戏",
  25. content: "乐比游戏"
  26. };
  27. this.app = null;
  28. this.user = null;
  29. this.isnewuser = false;
  30. this.event = null;
  31. this.pkuid = null;
  32. this.pklastuser = null;
  33. this.utils = new GameLeBiUtils(this);
  34. this.auth = new GameLeBiAuth(this);
  35. this.init()
  36. };
  37. GameLeBi.prototype.init = function() {
  38. this.spid = this.utils.getParameter("spid");
  39. this.source = this.utils.getParameter("source");
  40. this.animalid = this.utils.getParameter("animalid");
  41. this.fromid = this.utils.getParameter("id");
  42. this.isnewuser = (this.utils.getParameter("f") == "zf");
  43. this.homeurl = this.baseurl + "/" + (this.spid ? "?spid=" + this.spid: "");
  44. this.gzurl = this.baseurl + "/" + (this.spid ? "?spid=" + this.spid: "");
  45. this.moreurl = (this.isnewuser ? this.gzurl: this.homeurl);
  46. this.shareDomain = this.shareDomains[parseInt(Math.random() * this.shareDomains.length)];
  47. this.pkuid = this.utils.getParameter("pkuid");
  48. this.pklastuser = this.utils.getParameter("pklastuser");
  49. switch (this.utils.getAppType()) {
  50. case "wx":
  51. this.app = new GameLeBiWx(this);
  52. break;
  53. case "9g":
  54. this.app = new GameLeBiApp(this);
  55. break;
  56. case "uc":
  57. this.app = new GameLeBiUC(this);
  58. break;
  59. case "zhongsou":
  60. this.app = new GameLeBiZhongsou(this);
  61. break
  62. };
  63. if (this.gameid) this.initGame();
  64. };
  65. GameLeBi.prototype.initGame = function() {
  66. var _this = this;
  67. this.gameurl = "/?gameid=" + this.gameid + (this.spid ? "&spid=" + this.spid: "") + (localStorage.myuid ? "&id=" + localStorage.myuid: "") + "&f=zf" + "&domain=" + this.shareDomain;
  68. this.shareData.imgurl = "http://game.ikongzhong.cn/" + this.gameid + "/icon.png";
  69. this.shareData.link = "http://" + parseInt(Math.random()*100000) + "." + this.gameid + "." + this.shareDomain + "/" + this.gameid;
  70. this.utils.loading();
  71. if (!this.spid || this.spid == "uc" || this.spid == "9g") {
  72. this.ui = new GameLeBiUI(this)
  73. };
  74. if (this.utils.getAppType() == "9g" && this.utils.isIOS()) {
  75. setTimeout(function() {
  76. window.location = "appcall::setbackurl::" + _this.baseurl + "/app/games.html?r=" + Math.random()
  77. },
  78. 1000)
  79. };
  80. this.connect();
  81. setTimeout(function() {
  82. _this.getEventToday()
  83. },
  84. 1000);
  85. setTimeout(function() {
  86. _this.utils.showAd()
  87. },
  88. 2000);
  89. if (this.utils.getAppType() == "wx" || this.utils.getAppType() == "9g") {
  90. setTimeout(function() {
  91. _this.bonus()
  92. },
  93. 3000)
  94. };
  95. _czc.push(["_setCustomVar", "用户", (this.isnewuser ? "新用户": "老用户"), 1]);
  96. _czc.push(["_setCustomVar", "gameid", this.gameid, 1]);
  97. _czc.push(["_setCustomVar", "spid", this.spid, 1]);
  98. if (this.utils.getAppType() == "wx") {
  99. _czc.push(["_setCustomVar", "wx_ver", this.app.version, 1])
  100. }
  101. };
  102. GameLeBi.prototype.connect = function() {
  103. if (localStorage.accessToken) {
  104. var url = "http://game.ikongzhong.cn/connect2?gameid=" + this.gameid + "&access_token=" + localStorage.accessToken + (this.spid ? "&spid=" + this.spid: "") + (this.fromid ? "&uid=" + this.fromid: "");
  105. var _this = this;
  106. this.utils.ajax(url,
  107. function(data) {
  108. if (data.errcode) {
  109. _this.auth.clear();
  110. _this.user = null
  111. } else {
  112. localStorage.myuid = data.uid;
  113. _this.user = _this.utils.extend(_this.user, data.user);
  114. _this.game = data.game;
  115. }
  116. })
  117. } else {
  118. var url = "http://game.ikongzhong.cn/connect3.php?gameid=" + this.gameid + (this.spid ? "&spid=" + this.spid: "") + (this.utils.getParameter("f") == "zf" ? "&f=zf": "");
  119. var _this = this;
  120. this.utils.ajax(url,
  121. function(data) {
  122. _this.game = data.game;
  123. })
  124. }
  125. };
  126. GameLeBi.prototype.bonus = function() {
  127. if (!this.isTest()) return;
  128. if (localStorage.myuid && !gamelebi.user) {
  129. localStorage.bonusTipCount = localStorage.bonusTipCount || 0;
  130. if (localStorage.bonusTipCount && localStorage.bonusTipCount < 3) {
  131. var _this = this;
  132. this.auth.getFromUser(function() {
  133. var fromNickname = "";
  134. if (_this.fromuser) fromNickname = _this.fromuser.nickname;
  135. _this.utils.dialog({
  136. title: "乐比游戏",
  137. content: "您的朋友" + fromNickname + "帮你赢得了一元话费,是否立即领取?",
  138. buttons: [{
  139. label: "去领取",
  140. click: function() {
  141. window.location = _this.baseurl + "/bonus/new.html"
  142. }
  143. },
  144. {
  145. label: "放弃",
  146. click: null
  147. }]
  148. });
  149. localStorage.bonusTipCount++
  150. })
  151. }
  152. }
  153. };
  154. GameLeBi.prototype.getGameInfo = function(gameid, callback) {
  155. this.utils.ajax("http://game.ikongzhong.cn/gameinfo?gameid=" + gameid, callback)
  156. };
  157. GameLeBi.prototype.getEventUrl = function() {
  158. return this.baseurl + "/app/event.html?r=" + Math.random()
  159. };
  160. GameLeBi.prototype.getEventToday = function(callback) {
  161. var url = "http://game.ikongzhong.cn/getevent?gameid=" + this.gameid + (localStorage.myuid ? "&uid=" + localStorage.myuid: "");
  162. var _this = this;
  163. this.utils.ajax(url,
  164. function(data) {
  165. if (data.user) _this.user = _this.utils.extend(_this.user, data.user);
  166. if (data.game) _this.game = data.game;
  167. if (data.event) _this.event = data.event;
  168. if (_this.user && (_this.spid == null || _this.spid == "uc")) {
  169. _this.isnewuser = false;
  170. _this.moreurl = _this.homeurl
  171. };
  172. callback && callback.apply(_this)
  173. })
  174. };
  175. GameLeBi.prototype.setShareData = function(shareData) {
  176. if (shareData) this.shareData = this.utils.extend(this.shareData, shareData);
  177. if (this.app && this.app.setShareData) this.app.setShareData()
  178. };
  179. GameLeBi.prototype.share = function() {
  180. this.app && this.app.share()
  181. };
  182. GameLeBi.prototype.shareLog = function(options, callback) {
  183. var url = "http://game.ikongzhong.cn/gameshare";
  184. if (options.gameid) url = this.utils.setParameter(url, "gameid", options.gameid);
  185. if (options.spid) url = this.utils.setParameter(url, "spid", options.spid);
  186. if (options.id) url = this.utils.setParameter(url, "id", options.id);
  187. if (options.source) url = this.utils.setParameter(url, "source", options.source);
  188. if (options.type) url = this.utils.setParameter(url, "type", options.type);
  189. if (options.domain) url = this.utils.setParameter(url, "domain", options.domain);
  190. this.utils.ajax(url,
  191. function(data) {
  192. callback && callback.apply(null)
  193. })
  194. };
  195. GameLeBi.prototype.shareFlow = function() {
  196. var _this = this;
  197. if (this.isnewuser && this.spid && this.spid != "9g" && this.spid != "uc" && this.spid != "zhongsou" && this.spid != "51h5") {
  198. this.app.shareOK = function() {
  199. window.location = _this.moreurl
  200. };
  201. this.utils.shareTip();
  202. return
  203. };
  204. if (this.source == "zoo") {
  205. this.app.shareOK = function() {
  206. window.location = _this.baseurl + "/zoo/second.html?animalid=" + _this.animalid
  207. };
  208. this.utils.shareTip();
  209. return
  210. };
  211. if (this.event) {
  212. if (this.event.gameid == this.gameid) {
  213. this.app.shareOK = function() {
  214. if (!_this.isSubmitted || _this.isSubmitted && _this.score != _this.autoScore) {
  215. _this.submit(function() {
  216. window.location = _this.getEventUrl()
  217. })
  218. } else {
  219. window.location = _this.getEventUrl()
  220. }
  221. };
  222. this.utils.shareTip()
  223. } else {
  224. this.app.shareOK = function() {
  225. window.location = _this.getEventUrl()
  226. };
  227. this.utils.shareTip()
  228. }
  229. } else {
  230. this.app.shareOK = function() {
  231. window.location = _this.moreurl
  232. };
  233. this.utils.shareTip()
  234. }
  235. };
  236. GameLeBi.prototype.autoSubmit = function() {
  237. var _this = this;
  238. if (localStorage.myuid && this.score != null && this.score > 0) {
  239. if (!this.isSubmitted || this.isSubmitted && (this.gameOrder == "asc" && this.score < this.rankScore || this.gameOrder == "desc" && this.score > this.rankScore)) {
  240. this.submit(function(data) {
  241. if (data.success) {
  242. _this.isSubmitted = true;
  243. _this.gameOrder = data.order;
  244. _this.rankScore = data.refreshRankScore || data.lastRankScore == -1 ? _this.score: data.lastRankScore;
  245. _this.autoScore = _this.score
  246. }
  247. })
  248. }
  249. }
  250. };
  251. GameLeBi.prototype.submit = function(callback) {
  252. if (!localStorage.myuid) {
  253. return
  254. };
  255. if (this.score == null || isNaN(this.score)) {
  256. return
  257. };
  258. var pkuid = (this.fromid && this.fromid != localStorage.myuid ? this.fromid: "");
  259. var notice = "";
  260. if (pkuid && !this.notice) {
  261. notice = "y";
  262. this.notice = true
  263. };
  264. var pklastuser = (this.pklastuser ? "y": "");
  265. var a = [this.gameid, localStorage.myuid, this.score, encodeURIComponent(this.scoreName), encodeURIComponent(this.shareData.title), pkuid, notice, pklastuser];
  266. var data = Base64.encode(this.utils.encrypt("gamelebicom2014123", a.join("|")));
  267. var url = "http://game.ikongzhong.cn/submit?data=" + data;
  268. var _this = this;
  269. this.utils.ajax(url,
  270. function(data) {
  271. if (data.success) {
  272. _this.utils.debug(data);
  273. callback && callback.call(null, data)
  274. } else {
  275. _this.utils.debug("提交失败")
  276. }
  277. })
  278. };
  279. GameLeBi.prototype.isTest = function() {
  280. return (this.utils.getParameter("istest") == "y" || localStorage.myuid == "b1Atb251RGNNZktTeTRCdXp3NDFCMkpoNzR0OA==" || localStorage.myuid == "b1Atb251T1ZmS0VubEhKSXdxTi1NQ3NuV2xvZw==" || localStorage.myuid == "b1Atb251R0xBLVRldGNjcGxGZmNLWlhsOXZ0bw==" || localStorage.myuid == "b1Atb251Qi1MbllvTkRTVjduc0c3eGlQUnlQNA==" || localStorage.myuid == "b1Atb251RHpoRmtpa2M2YjhGbF9sUDRzQ28wTQ==" || localStorage.myuid == "b1Atb251SzlpMHV6eXBZLTlmTkIwUm9VWl9NWQ==" || localStorage.myuid == "b1Atb251UG8tVnNWbDM3UVFvaUI4M2hJbUQyTQ==")
  281. };
  282. GameLeBiAuth = function(gamelebi) {
  283. this.gamelebi = gamelebi
  284. };
  285. GameLeBiAuth.prototype.check = function(options) {
  286. var defaults = {
  287. level: "id",
  288. redirect: location.href,
  289. success: null,
  290. fail: null
  291. };
  292. options = this.gamelebi.utils.extend(defaults, options);
  293. if (this.checkError()) {
  294. options.fail && options.fail.apply(null);
  295. return
  296. };
  297. if (this.checkOKLoad(options, 10)) {
  298. options.success && options.success.apply(null);
  299. return
  300. };
  301. if (options.level == "id" && !localStorage.accessToken) {
  302. this.checkTask(options)
  303. } else if (options.level == "user" && !localStorage.token) {
  304. this.checkTask(options)
  305. } else {
  306. var url = "http://game.ikongzhong.cn/check";
  307. if (options.level == "id") url += "?access_token=" + localStorage.accessToken;
  308. if (options.level == "user") url += "?token=" + localStorage.token;
  309. var _this = this;
  310. this.gamelebi.utils.ajax(url,
  311. function(data) {
  312. if (data && data.success) {
  313. _this.checkOkSave(options, data);
  314. options.success && options.success.apply(null)
  315. } else {
  316. _this.clear();
  317. _this.checkTask(options)
  318. }
  319. })
  320. }
  321. };
  322. GameLeBiAuth.prototype.checkError = function() {
  323. if (sessionStorage.errcode && sessionStorage.errmsg) {
  324. this.gamelebi.utils.debug("errcode = " + sessionStorage.errcode + ", errmsg = " + sessionStorage.errmsg);
  325. sessionStorage.removeItem("errcode");
  326. sessionStorage.removeItem("errmsg");
  327. this.clear();
  328. return true
  329. };
  330. return false
  331. };
  332. GameLeBiAuth.prototype.clear = function() {
  333. localStorage.removeItem("accessToken");
  334. localStorage.removeItem("token");
  335. localStorage.removeItem("myuid");
  336. localStorage.removeItem("unionid")
  337. };
  338. GameLeBiAuth.prototype.checkOkSave = function(options, data) {
  339. this.clear();
  340. if (data.accessToken) localStorage.accessToken = data.accessToken;
  341. if (data.token) localStorage.token = data.token;
  342. if (data.myuid) localStorage.myuid = data.myuid;
  343. if (data.unionid) localStorage.unionid = data.unionid;
  344. var key = "check_" + options.level + "_ok_time";
  345. sessionStorage[key] = new Date().getTime()
  346. };
  347. GameLeBiAuth.prototype.checkOKLoad = function(options, sec) {
  348. var key = "check_" + options.level + "_ok_time";
  349. if (sessionStorage[key]) {
  350. var checkTime = sessionStorage[key];
  351. sessionStorage.removeItem(key);
  352. if (checkTime && (new Date().getTime() - checkTime) <= sec * 1000) return true
  353. };
  354. return false
  355. };
  356. GameLeBiAuth.prototype.checkTask = function(options) {
  357. switch (options.level) {
  358. case "id":
  359. if (this.gamelebi.utils.getAppType() == "wx") {
  360. this.loginWx(options.redirect)
  361. } else {
  362. options.fail && options.fail.apply(null)
  363. };
  364. break;
  365. case "user":
  366. if (this.gamelebi.utils.getAppType() == "wx") {
  367. if (!localStorage.accessToken) {
  368. this.loginWx(options.redirect)
  369. } else {
  370. this.registerWx(options.redirect)
  371. }
  372. } else {
  373. this.loginForm(options.redirect)
  374. };
  375. break
  376. }
  377. };
  378. GameLeBiAuth.prototype.getUser = function(callback) {
  379. if (!localStorage.token) {
  380. callback && callback.call(null, null)
  381. } else {
  382. var _this = this;
  383. var url = "http://game.ikongzhong.cn/getuser?token=" + localStorage.token;
  384. this.gamelebi.utils.ajax(url,
  385. function(data) {
  386. if (data.errcode) {
  387. localStorage.removeItem("token");
  388. _this.gamelebi.user = null;
  389. callback && callback.call(null, null)
  390. } else {
  391. _this.gamelebi.user = _this.gamelebi.utils.extend(_this.gamelebi.user, data);
  392. callback && callback.call(null, data)
  393. }
  394. })
  395. }
  396. };
  397. GameLeBiAuth.prototype.getFromUser = function() {
  398. var id = this.gamelebi.fromid;
  399. var callback = null;
  400. switch (arguments.length) {
  401. case 1:
  402. if (typeof arguments[0] == "string") id = arguments[0];
  403. if (typeof arguments[0] == "function") callback = arguments[0];
  404. break;
  405. case 2:
  406. id = arguments[0];
  407. callback = arguments[1];
  408. break
  409. };
  410. if (id) {
  411. var _this = this;
  412. var url = "http://game.ikongzhong.cn/getuser?id=" + id;
  413. this.gamelebi.utils.ajax(url,
  414. function(data) {
  415. var user = null;
  416. if (data.errcode) {
  417. _this.gamelebi.utils.debug(data.errmsg)
  418. } else {
  419. user = data;
  420. _this.gamelebi.fromuser = user
  421. };
  422. callback && callback.call(null, user)
  423. })
  424. } else {
  425. callback && callback.call(null, null)
  426. }
  427. };
  428. GameLeBiAuth.prototype.loginWx = function(redirect) {
  429. var trans = this.gamelebi.baseurl + "/auth/trans.app.html?origin=" + encodeURIComponent(redirect);
  430. var url = "http://game.ikongzhong.cn/check?fromurl=" + encodeURIComponent(trans);
  431. window.location = url
  432. };
  433. GameLeBiAuth.prototype.registerWx = function(redirect) {
  434. var trans = this.gamelebi.baseurl + "/auth/trans.app.html?origin=" + encodeURIComponent(redirect);
  435. var success = "http://game.ikongzhong.cn/check?fromurl=" + encodeURIComponent(trans);
  436. var fail = this.gamelebi.baseurl + "/app/games.html";
  437. var url = "http://game.ikongzhong.cn/getuser?success=" + encodeURIComponent(success) + "&fail=" + encodeURIComponent(fail);
  438. window.location = url
  439. };
  440. GameLeBiAuth.prototype.loginForm = function(redirect) {
  441. var url = this.gamelebi.baseurl + "/app/login.html?bckurl=" + encodeURIComponent(redirect);
  442. window.location = url
  443. };
  444. GameLeBiAuth.prototype.saveLink = function(callback) {
  445. var id = this.gamelebi.fromid;
  446. if (id && localStorage.accessToken && id != localStorage.myuid) {
  447. var url = "http://game.ikongzhong.cn/link?access_token=" + localStorage.accessToken + "&id=" + id;
  448. var _this = this;
  449. this.gamelebi.utils.ajax(url,
  450. function(data) {
  451. var result = 0;
  452. if (data.error) {
  453. _this.gamelebi.utils.debug(data);
  454. result = -1
  455. } else {
  456. result = data.linkResult
  457. };
  458. callback && callback.call(null, result)
  459. })
  460. } else {
  461. callback && callback.call(null, -1)
  462. }
  463. };
  464. GameLeBiUI = function(gamelebi) {
  465. this.gamelebi = gamelebi;
  466. this.start = new GameLeBiUIStart(gamelebi);
  467. };
  468. GameLeBiUIStart = function(gamelebi) {
  469. this.gamelebi = gamelebi;
  470. var a = document.createElement("a");
  471. a.id = "gamelebi9gstart";
  472. a.className = "gamelebi9gstart";
  473. var _this = this;
  474. a.addEventListener("touchstart",
  475. function(event) {
  476. localStorage.hasClick9gStart = true;
  477. _this.gamelebi.ui.menu.show();
  478. event.preventDefault()
  479. });
  480. document.getElementsByTagName("body")[0].appendChild(a);
  481. };
  482. GameLeBiUtils = function(gamelebi) {
  483. this.gamelebi = gamelebi
  484. };
  485. GameLeBiUtils.prototype.extend = function(target, options) {
  486. if (target == undefined || target == null) {
  487. return options
  488. } else {
  489. if (options) {
  490. for (name in options) {
  491. target[name] = options[name]
  492. }
  493. };
  494. return target
  495. }
  496. };
  497. GameLeBiUtils.prototype.isIOS = function() {
  498. return /iPhone|iPod|iPad|Mac/ig.test(navigator.userAgent)
  499. };
  500. GameLeBiUtils.prototype.isAndroid = function() {
  501. return /android|linux/i.test(navigator.userAgent)
  502. };
  503. GameLeBiUtils.prototype.getAppType = function() {
  504. var ua = navigator.userAgent;
  505. if (/micromessenger/ig.test(ua)) {
  506. return "wx"
  507. } else if (/gamelebi/ig.test(ua)) {
  508. return "9g"
  509. } else if (/ucbrowser/ig.test(ua)) {
  510. return "uc"
  511. } else if (/souyue/ig.test(ua)) {
  512. return "zhongsou"
  513. } else {
  514. return "other"
  515. }
  516. };
  517. GameLeBiUtils.prototype.getAppVersion = function() {
  518. var result = null;
  519. var version = null;
  520. var ua = navigator.userAgent;
  521. switch (this.getAppType()) {
  522. case "wx":
  523. result = ua.match(/MicroMessenger\/([^\s]+)/i);
  524. if (result) version = result[1];
  525. break;
  526. case "9g":
  527. result = ua.match(/Game9g\s([^\s]+)/i);
  528. if (result) version = result[1];
  529. break;
  530. case "uc":
  531. result = ua.match(/UCBrowser\/([^\s]+)/i);
  532. if (result) version = result[1];
  533. break;
  534. case "zhongsou":
  535. result = ua.match(/souyue\/([^\s]+)/i);
  536. if (result) version = result[1];
  537. break
  538. };
  539. return version
  540. };
  541. GameLeBiUtils.prototype.compareVersion = function(version1, version2) {
  542. var r1 = version1.match(/(\d+)(?!\d)/ig);
  543. var r2 = version2.match(/(\d+)(?!\d)/ig);
  544. var result = true;
  545. for (var i = 0; i < 99; i++) {
  546. if (r2.length < i + 1) {
  547. result = true;
  548. break
  549. };
  550. var n1 = parseInt(r1[i]);
  551. var n2 = parseInt(r2[i]);
  552. if (n1 != n2) {
  553. result = (n1 > n2);
  554. break
  555. }
  556. };
  557. return result
  558. };
  559. GameLeBiUtils.prototype.getUrl = function() {
  560. if (location.origin && location.pathname) {
  561. return location.origin + location.pathname
  562. } else {
  563. return location.href.match(/[^?#]+/i)[0]
  564. }
  565. };
  566. GameLeBiUtils.prototype.getFullUrl = function() {
  567. return location.href.match(/[^#;]+/i)[0]
  568. };
  569. GameLeBiUtils.prototype.getPath = function() {
  570. if (location.pathname) {
  571. return location.pathname
  572. } else {
  573. return location.href.match(/(?:http|https):\/\/[^\/]+([^?#;]+)/i)[1]
  574. }
  575. };
  576. GameLeBiUtils.prototype.getQueryString = function() {
  577. return location.search
  578. };
  579. GameLeBiUtils.prototype.getParameter = function(name) {
  580. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  581. var r = window.location.search.substr(1).match(reg);
  582. if (r != null) return r[2];
  583. return null
  584. };
  585. GameLeBiUtils.prototype.setParameter = function(url, name, value) {
  586. url = url.replace(/(#.*)/ig, "");
  587. var reg = new RegExp("([\?&])" + name + "=([^&]*)(?=&|$)", "i");
  588. if (reg.test(url)) {
  589. return url.replace(reg, "$1" + name + "=" + value)
  590. } else {
  591. return url + (url.indexOf("?") == -1 ? "?": "&") + name + "=" + value
  592. }
  593. };
  594. GameLeBiUtils.prototype.removeParameter = function(url, name) {
  595. url = url.replace(/(#.*)/ig, "");
  596. var reg = new RegExp("([\?&])" + name + "=([^&]*)(?=&|$)", "i");
  597. if (reg.test(url)) {
  598. url = url.replace(reg, "");
  599. if (url.indexOf("?") == -1) url = url.replace("&", "?")
  600. };
  601. return url
  602. };
  603. GameLeBiUtils.prototype.getHead64 = function(headimgurl) {
  604. if (!headimgurl) return "http://game.ikongzhong.cn/default.png";
  605. if (headimgurl.indexOf("/0") != -1) {
  606. headimgurl = headimgurl.substr(0, headimgurl.length - 2) + "/64"
  607. };
  608. return headimgurl
  609. };
  610. GameLeBiUtils.prototype.getHead132 = function(headimgurl) {
  611. if (!headimgurl) return "http://game.ikongzhong.cn/default.png";
  612. if (headimgurl.indexOf("/0") != -1) {
  613. headimgurl = headimgurl.substr(0, headimgurl.length - 2) + "/132"
  614. };
  615. return headimgurl
  616. };
  617. GameLeBiUtils.prototype.now = function() {
  618. var dt = new Date();
  619. dt.setMilliseconds(0);
  620. return dt.getTime() / 1000
  621. };
  622. GameLeBiUtils.prototype.today = function() {
  623. var dt = new Date();
  624. dt.setHours(0, 0, 0, 0);
  625. return dt.getTime() / 1000
  626. };
  627. GameLeBiUtils.prototype.formatDate = function() {
  628. var date = arguments[0];
  629. var format = arguments[1] || "yyyy-MM-dd HH:mm:ss";
  630. if (typeof date == "number") {
  631. date = new Date(date * 1000)
  632. };
  633. var paddNum = function(num) {
  634. num += "";
  635. return num.replace(/^(\d)$/, "0$1")
  636. };
  637. var config = {
  638. yyyy: date.getFullYear(),
  639. yy: date.getFullYear().toString().substring(2),
  640. M: date.getMonth() + 1,
  641. MM: paddNum(date.getMonth() + 1),
  642. d: date.getDate(),
  643. dd: paddNum(date.getDate()),
  644. HH: paddNum(date.getHours()),
  645. mm: paddNum(date.getMinutes()),
  646. ss: paddNum(date.getSeconds())
  647. };
  648. return format.replace(/([a-z])(\1)*/ig,
  649. function(m) {
  650. return config[m]
  651. })
  652. };
  653. GameLeBiUtils.prototype.getRandomInt = function(min, max) {
  654. return parseInt((Math.random() * (max - min + 1)) + min)
  655. };
  656. GameLeBiUtils.prototype.getRandomString = function(len) {
  657. var base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
  658. var str = "";
  659. for (var i = 0; i < len; i++) {
  660. var n = this.getRandomInt(1, base.length) - 1;
  661. str += base.substr(n, 1)
  662. };
  663. return str
  664. };
  665. GameLeBiUtils.prototype.shareConfirm = function(content, callback) {
  666. this.gamelebi.autoSubmit();
  667. if (this.gamelebi.spid == "zhongsou") {
  668. if (this.gamelebi.shareData.title.indexOf("搜悦游戏") == -1) this.gamelebi.shareData.title += "[搜悦游戏]";
  669. if (this.gamelebi.shareData.content.indexOf("搜悦游戏") == -1) this.gamelebi.shareData.content += "[搜悦游戏]"
  670. };
  671. var _this = this;
  672. setTimeout(function() {
  673. if (_this.getAppType() == "wx" || _this.getAppType() == "9g") {
  674. callback && callback.apply(null)
  675. } else {
  676. if (_this.gamelebi.app) {
  677. if (confirm(content)) {
  678. callback && callback.apply(null)
  679. }
  680. }
  681. }
  682. },
  683. 500)
  684. };
  685. //GameLeBiUtils.prototype.shareTip = function() {
  686. // if (document.getElementById("gamelebishareevent")) return;
  687. // var imgShare = document.createElement("img");
  688. // imgShare.id = "gamelebishareevent";
  689. // imgShare.src = "http://game.9g.com/img/sharetoevent.png";
  690. // imgShare.className = "gamelebishareevent";
  691. // document.getElementsByTagName("body")[0].appendChild(imgShare);
  692. // var mask = document.createElement("div");
  693. // mask.className = "gamelebisharemask";
  694. // document.getElementsByTagName("body")[0].appendChild(mask);
  695. // mask.addEventListener("touchstart",
  696. // function() {
  697. // document.getElementsByTagName("body")[0].removeChild(mask);
  698. // document.getElementsByTagName("body")[0].removeChild(imgShare);
  699. // })
  700. //};
  701. GameLeBiUtils.prototype.dialog = function(options) {
  702. new GameLeBiUtilsDialog(this.gamelebi, options).open()
  703. };
  704. GameLeBiUtilsDialog = function(gamelebi, options) {
  705. this.gamelebi = gamelebi;
  706. var defaults = {
  707. title: "乐比游戏",
  708. content: "",
  709. buttons: [],
  710. buttonOK: null,
  711. buttonCancel: null
  712. };
  713. this.options = this.gamelebi.utils.extend(defaults, options);
  714. this.init()
  715. };
  716. GameLeBiUtilsDialog.prototype.init = function() {
  717. if (this.options.buttonOK) {
  718. this.options.buttons.push(this.gamelebi.utils.extend({
  719. label: "确定",
  720. color: "#FFFFFF",
  721. bgcolor: "#FF0000",
  722. click: null
  723. },
  724. this.options.buttonOK))
  725. };
  726. if (this.options.buttonCancel) {
  727. this.options.buttons.push(this.gamelebi.utils.extend({
  728. label: "取消",
  729. color: "#FFFFFF",
  730. bgcolor: "#888888",
  731. click: null
  732. },
  733. this.options.buttonCancel))
  734. }
  735. };
  736. GameLeBiUtilsDialog.prototype.open = function() {
  737. if (document.getElementById("gamelebidialog")) return;
  738. var div = document.createElement("div");
  739. div.id = "gamelebidialog";
  740. div.className = "gamelebidialog";
  741. div.innerHTML = "<header><h2>" + this.options.title + "</h2></header><section>" + this.options.content.replace(/\n/g, "<br/>") + "</section><footer></footer>";
  742. var _this = this;
  743. for (var i = 0; i < this.options.buttons.length; i++) { (function(btn) {
  744. var a = document.createElement("a");
  745. a.innerHTML = btn.label;
  746. if (btn.color) a.style.color = btn.color;
  747. if (btn.bgcolor) a.style.backgroundColor = btn.bgcolor;
  748. a.addEventListener("touchstart", _this.close);
  749. a.addEventListener("touchstart",
  750. function(e) {
  751. btn.click && btn.click.apply(_this.gamelebi);
  752. e.preventDefault()
  753. });
  754. div.getElementsByTagName("footer")[0].appendChild(a)
  755. })(this.options.buttons[i])
  756. };
  757. document.getElementsByTagName("body")[0].appendChild(div);
  758. var mask = document.createElement("div");
  759. mask.id = "gamelebimask";
  760. mask.className = "gamelebimask";
  761. document.getElementsByTagName("body")[0].appendChild(mask)
  762. };
  763. GameLeBiUtilsDialog.prototype.close = function(e) {
  764. var div = document.getElementById("gamelebidialog");
  765. if (div) document.getElementsByTagName("body")[0].removeChild(div);
  766. var mask = document.getElementById("gamelebimask");
  767. if (mask) document.getElementsByTagName("body")[0].removeChild(mask);
  768. e.preventDefault()
  769. };
  770. GameLeBiUtils.prototype.ajax = function(url, success) {
  771. url = this.gamelebi.utils.setParameter(url, "_", Math.random());
  772. new GameLeBiUtilsAjax(this.gamelebi, "GET", url, null, "json", success)
  773. };
  774. GameLeBiUtils.prototype.jsonp = function(url, data, jsonparam, success) {
  775. url = this.gamelebi.utils.setParameter(url, "_", Math.random());
  776. new GameLeBiUtilsJsonp(url, data, jsonparam, success).request()
  777. };
  778. GameLeBiUtilsAjax = function(gamelebi, method, url, data, type, success) {
  779. this.gamelebi = gamelebi;
  780. this.xmlhttp = null;
  781. if (window.XMLHttpRequest) {
  782. this.xmlhttp = new XMLHttpRequest()
  783. } else {
  784. this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
  785. };
  786. this.type = type;
  787. this.success = success;
  788. this.xmlhttp.open(method, url, true);
  789. var _this = this;
  790. this.xmlhttp.onreadystatechange = function() {
  791. _this.callback.apply(_this)
  792. };
  793. this.xmlhttp.send(data)
  794. };
  795. GameLeBiUtilsAjax.prototype.callback = function() {
  796. if (this.xmlhttp.readyState == 4 && this.xmlhttp.status == 200) {
  797. var data = null;
  798. switch (this.type) {
  799. case "text":
  800. data = this.xmlhttp.responseText;
  801. break;
  802. case "json":
  803. try {
  804. data = JSON.parse(this.xmlhttp.responseText)
  805. } catch(e) {
  806. data = this.xmlhttp.responseText
  807. };
  808. break
  809. };
  810. this.success && this.success.call(this.xmlhttp, data)
  811. }
  812. };
  813. GameLeBiUtilsJsonp = function(url, data, jsonparam, success, timeout) {
  814. var finish = false;
  815. var theHead = document.getElementsByTagName("head")[0] || document.documentElement;
  816. var scriptControll = document.createElement("script");
  817. var jsonpcallback = "jsonpcallback" + (Math.random() + "").substring(2);
  818. var collect = function() {
  819. if (theHead != null) {
  820. theHead.removeChild(scriptControll);
  821. try {
  822. delete window[jsonpcallback]
  823. } catch(ex) {};
  824. theHead = null
  825. }
  826. };
  827. var init = function() {
  828. scriptControll.charset = "utf-8";
  829. theHead.insertBefore(scriptControll, theHead.firstChild);
  830. window[jsonpcallback] = function(responseData) {
  831. finish = true;
  832. success(responseData)
  833. };
  834. jsonparam = jsonparam || "callback";
  835. if (url.indexOf("?") > 0) {
  836. url = url + "&" + jsonparam + "=" + jsonpcallback
  837. } else {
  838. url = url + "?" + jsonparam + "=" + jsonpcallback
  839. };
  840. if (typeof data == "object" && data != null) {
  841. for (var p in data) {
  842. url = url + "&" + p + "=" + escape(data[p])
  843. }
  844. }
  845. };
  846. var timer = function() {
  847. if (typeof window[jsonpcallback] == "function") {
  848. collect()
  849. };
  850. if (typeof timeout == "function" && finish == false) {
  851. timeout()
  852. }
  853. };
  854. this.request = function() {
  855. init();
  856. scriptControll.src = url;
  857. window.setTimeout(timer, 10000)
  858. }
  859. };
  860. GameLeBiUtils.prototype.loading = function() {
  861. var div = document.createElement("div");
  862. div.id = "gamelebiloading";
  863. div.className = "gamelebiloading";
  864. if (this.gamelebi.cpid) {
  865. div.innerHTML = "正在加载中请稍后。。。" + this.gamelebi.gameid + "正在加载中请稍后。。。' />"
  866. } else {
  867. div.innerHTML = "正在加载中请稍后。。。"
  868. };
  869. document.getElementsByTagName("body")[0].appendChild(div);
  870. var interval = (this.getAppType() == "9g" ? 1000 : 3000);
  871. setTimeout(function() {
  872. document.getElementsByTagName("body")[0].removeChild(div);
  873. var a = document.getElementById("gamelebi9gstart");
  874. if (a) {
  875. a.className = "gamelebi9gstart bounceInLeft";
  876. var afinish = function() {
  877. a.className = "gamelebi9gstart pulse infinite";
  878. var img = document.getElementById("gamelebi9gstarttip");
  879. if (img) {
  880. img.className = "gamelebi9gstarttip bounceInRight";
  881. var imgfinish = function() {
  882. setTimeout(function() {
  883. img.className = "gamelebi9gstarttip bounceOutLeft"
  884. },
  885. 1000)
  886. };
  887. img.addEventListener("animationend", imgfinish);
  888. img.addEventListener("webkitAnimationEnd", imgfinish)
  889. }
  890. };
  891. a.addEventListener("animationend", afinish);
  892. a.addEventListener("webkitAnimationEnd", afinish)
  893. }
  894. },
  895. interval)
  896. };
  897. GameLeBiUtils.prototype.showAd = function() {
  898. if (this.gamelebi.spid == "uc" && this.getAppType() != "uc") {
  899. var url = "http://wx.9g.com/pm/get.jsp?spid=" + this.gamelebi.spid;
  900. this.ajax(url,
  901. function(data) {
  902. if (data.ad) {
  903. var img = document.createElement("img");
  904. img.id = "gamelebiad";
  905. img.src = data.ad.imgurl;
  906. img.className = "gamelebiad";
  907. img.addEventListener("touchstart",
  908. function() {
  909. window.location = "http://wx.9g.com/pm/click.jsp?id=" + data.ad.id
  910. });
  911. document.getElementsByTagName("body")[0].appendChild(img)
  912. }
  913. })
  914. };
  915. if (this.gamelebi.spid == "zhongsou" && this.getAppType() != "zhongsou") {
  916. var isZhousouInstalled = (this.getParameter("isappinstalled") == "1");
  917. var url = "http://wx.9g.com/pm/get.jsp?spid=" + this.gamelebi.spid;
  918. var _this = this;
  919. this.ajax(url,
  920. function(data) {
  921. if (data.ad) {
  922. var img = document.createElement("img");
  923. img.id = "gamelebiadbottom";
  924. img.className = "gamelebiadbottom";
  925. img.src = data.ad.imgurl;
  926. img.addEventListener("touchstart",
  927. function() {
  928. if (isZhousouInstalled) {
  929. if (_this.getAppType() == "wx") {
  930. var tip = document.createElement("img");
  931. tip.id = "gamelebizhongsoutip";
  932. tip.className = "gamelebizhongsoutip";
  933. tip.src = "http://game.ikongzhong.cn/img/" + (_this.isIOS() ? "zhongsou_share_ios.png": "zhongsou_share_android.png");
  934. document.getElementsByTagName("body")[0].appendChild(tip)
  935. } else {
  936. window.location = "wx360a9785675a8653://"
  937. }
  938. } else {
  939. window.location = "http://wx.9g.com/pm/click.jsp?id=" + data.ad.id
  940. }
  941. });
  942. document.getElementsByTagName("body")[0].appendChild(img)
  943. }
  944. })
  945. }
  946. };
  947. GameLeBiUtils.prototype.debug = function(obj) {
  948. if (this.gamelebi.isTest()) {
  949. alert("[DEBUG]\n" + this.describe(obj))
  950. }
  951. };
  952. GameLeBiUtils.prototype.describe = function(obj, tab) {
  953. tab = tab || "";
  954. var content = "";
  955. if (typeof obj == "object" && obj != null) {
  956. for (var item in obj) {
  957. if (typeof obj[item] == "object" && obj[item] != null) content += tab + item + " = \n" + tab + "(\n" + this.describe(obj[item], tab + " ") + tab + ")\n";
  958. else content += tab + item + " = " + obj[item] + "\n"
  959. }
  960. } else {
  961. content += tab + obj
  962. };
  963. return content
  964. };
  965. GameLeBiUtils.prototype.encrypt = function(key, word) {
  966. var iv = CryptoJS.enc.Utf8.parse(key);
  967. var srcs = CryptoJS.enc.Utf8.parse(word);
  968. var encrypted = CryptoJS.AES.encrypt(srcs, CryptoJS.enc.Utf8.parse(key), {
  969. iv: iv,
  970. mode: CryptoJS.mode.CBC
  971. });
  972. return encrypted.toString()
  973. };
  974. GameLeBiUtils.prototype.track = function() {
  975. var action = null;
  976. var value = null;
  977. var memo = null;
  978. var callback = null;
  979. switch (arguments.length) {
  980. case 1:
  981. action = arguments[0];
  982. break;
  983. case 2:
  984. action = arguments[0];
  985. if (!isNaN(arguments[1])) value = arguments[1];
  986. if (typeof arguments[1] == "function") callback = arguments[1];
  987. break;
  988. case 3:
  989. action = arguments[0];
  990. value = arguments[1];
  991. if (typeof arguments[2] == "string") memo = arguments[2];
  992. if (typeof arguments[2] == "function") callback = arguments[2];
  993. break;
  994. case 4:
  995. action = arguments[0];
  996. value = arguments[1];
  997. memo = arguments[2];
  998. callback = arguments[3];
  999. break
  1000. };
  1001. if (action == null) {
  1002. this.debug("track ERROR: 要求 action");
  1003. return
  1004. };
  1005. var url = "http://wx.9g.com/open/track?action=" + encodeURIComponent(action);
  1006. if (value != null) url = this.setParameter(url, "value", value);
  1007. if (memo != null) url = this.setParameter(url, "memo", encodeURIComponent(memo));
  1008. if (this.gamelebi.gameid) url = this.setParameter(url, "gameid", this.gamelebi.gameid);
  1009. if (localStorage.myuid) url = this.setParameter(url, "uid", localStorage.myuid);
  1010. this.ajax(url,
  1011. function(data) {
  1012. if (data.success) {
  1013. callback && callback.apply(null)
  1014. }
  1015. })
  1016. };
  1017. // 统计代码
  1018. GameLeBiUtils.prototype.tongji = function() {
  1019. // baidu
  1020. var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
  1021. document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F88406a9ce88af98b00c43c01033bb66d' type='text/javascript'%3E%3C/script%3E"));
  1022. // cnzz
  1023. var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");
  1024. document.write(unescape("%3Cspan id='cnzz_stat_icon_1253174262'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s5.cnzz.com/stat.php%3Fid%3D1253174262' type='text/javascript'%3E%3C/script%3E"));
  1025. }
  1026. // 广告
  1027. GameLeBiUtils.prototype.guanggao = function() {
  1028. var test = new adwojs({
  1029. eid:'spns', //节点id
  1030. eid:'spnx', //节点id
  1031. aid: '6e27bc61c672409cb4815629d2b92596', //android安卓PID
  1032. pid: '992e4e24c74c4daea962c845307ba446', //iOS PID
  1033. bt: false,
  1034. af:true, //是否自动适合ipad平板广告,默认值为true。
  1035. width: 320, //广告图片宽度(除320外,还有720宽度,用于ipad中显示)
  1036. height:50 //广告图片高度(除50外,还有110高度,用于ipad中显示)
  1037. });
  1038. test.send();
  1039. }
  1040. document.write(unescape("%3Cscript src='http://static.adwo.com/jssdk/jssdk.min.js' charset='utf-8' type='text/javascript'%3E%3C/script%3E"));
  1041. GameLeBiWx = function(gamelebi) {
  1042. this.gamelebi = gamelebi;
  1043. this.version = null;
  1044. this.ready = false;
  1045. this.shareOK = null;
  1046. this.shareCancel = null;
  1047. this.init()
  1048. };
  1049. GameLeBiWx.prototype.init = function() {
  1050. this.version = this.gamelebi.utils.getAppVersion();
  1051. this.initJsApi()
  1052. };
  1053. GameLeBiWx.prototype.isVersionOver = function(version) {
  1054. return this.gamelebi.utils.compareVersion(this.version, version)
  1055. };
  1056. GameLeBiWx.prototype.initWeixinJSBridge = function() {
  1057. var _this = this;
  1058. document.addEventListener("WeixinJSBridgeReady",
  1059. function onBridgeReady() {
  1060. WeixinJSBridge.on("menu:share:appmessage",
  1061. function(argv) {
  1062. WeixinJSBridge.invoke("sendAppMessage", {
  1063. "img_url": _this.gamelebi.shareData.imgurl,
  1064. "link": _this.gamelebi.shareData.link,
  1065. "desc": _this.gamelebi.shareData.content,
  1066. "title": _this.gamelebi.shareData.title
  1067. },
  1068. function(res) {
  1069. if (res.err_msg == "send_app_msg:cancel") {
  1070. _this.shareCancelHandler()
  1071. } else {
  1072. _this.shareOKHandler()
  1073. }
  1074. })
  1075. });
  1076. WeixinJSBridge.on("menu:share:timeline",
  1077. function(argv) {
  1078. WeixinJSBridge.invoke("shareTimeline", {
  1079. "img_url": _this.gamelebi.shareData.imgurl,
  1080. "img_width": "640",
  1081. "img_height": "640",
  1082. "link": _this.gamelebi.shareData.link,
  1083. "desc": _this.gamelebi.shareData.content,
  1084. "title": _this.gamelebi.shareData.title
  1085. },
  1086. function(res) {
  1087. if (res.err_msg == "share_timeline:cancel") {
  1088. _this.shareCancelHandler()
  1089. } else {
  1090. _this.shareOKHandler()
  1091. }
  1092. })
  1093. })
  1094. },
  1095. false)
  1096. };
  1097. GameLeBiWx.prototype.initJsApi = function() {
  1098. var timestamp = this.gamelebi.utils.now();
  1099. var noncestr = this.gamelebi.utils.getRandomString(16);
  1100. var url = this.gamelebi.utils.getFullUrl();
  1101. var ajaxUrl = "http://game.ikongzhong.cn/getjsapisignature/?noncestr=" + noncestr + "&timestamp=" + timestamp + "&url=" + encodeURIComponent(url);
  1102. var _this = this;
  1103. this.gamelebi.utils.ajax(ajaxUrl,
  1104. function(data) {
  1105. if (data.signature) {
  1106. var signature = data.signature;
  1107. wx.config({
  1108. debug: false,
  1109. appId: "wxe47ec7fcd82a07b0",
  1110. timestamp: timestamp,
  1111. nonceStr: noncestr,
  1112. signature: signature,
  1113. jsApiList: ["checkJsApi", "onMenuShareTimeline", "onMenuShareAppMessage", "onMenuShareQQ", "onMenuShareWeibo", "hideMenuItems", "showMenuItems", "hideAllNonBaseMenuItem", "showAllNonBaseMenuItem", "translateVoice", "startRecord", "stopRecord", "onRecordEnd", "playVoice", "pauseVoice", "stopVoice", "uploadVoice", "downloadVoice", "chooseImage", "previewImage", "uploadImage", "downloadImage", "getNetworkType", "openLocation", "getLocation", "hideOptionMenu", "showOptionMenu", "closeWindow", "scanQRCode", "chooseWXPay", "openProductSpecificView", "addCard", "chooseCard", "openCard"]
  1114. });
  1115. wx.ready(function() {
  1116. _this.ready = true;
  1117. _this.setShareData()
  1118. });
  1119. wx.error(function(res) {
  1120. _this.gamelebi.utils.debug(res)
  1121. })
  1122. }
  1123. })
  1124. };
  1125. GameLeBiWx.prototype.setShareData = function() {
  1126. var _this = this;
  1127. wx.onMenuShareTimeline({
  1128. title: this.gamelebi.shareData.title,
  1129. link: this.gamelebi.shareData.link,
  1130. imgUrl: this.gamelebi.shareData.imgurl,
  1131. success: function() {
  1132. var options = {
  1133. gameid: _this.gamelebi.gameid,
  1134. spid: _this.gamelebi.spid,
  1135. id: localStorage.myuid || null,
  1136. source: 1,
  1137. type: 1,
  1138. domain: (_this.gamelebi.shareData.link || "").indexOf(_this.gamelebi.shareDomain != -1) ? _this.gamelebi.shareDomain: null
  1139. };
  1140. _this.gamelebi.shareLog(options,
  1141. function() {
  1142. _this.shareOKHandler()
  1143. })
  1144. },
  1145. cancel: function() {
  1146. _this.shareCancelHandler()
  1147. }
  1148. });
  1149. wx.onMenuShareAppMessage({
  1150. title: this.gamelebi.shareData.title,
  1151. desc: this.gamelebi.shareData.content,
  1152. link: this.gamelebi.shareData.link,
  1153. imgUrl: this.gamelebi.shareData.imgurl,
  1154. type: "",
  1155. dataUrl: "",
  1156. success: function() {
  1157. var options = {
  1158. gameid: _this.gamelebi.gameid,
  1159. spid: _this.gamelebi.spid,
  1160. id: localStorage.myuid || null,
  1161. source: 2,
  1162. type: 1,
  1163. domain: (_this.gamelebi.shareData.link || "").indexOf(_this.gamelebi.shareDomain != -1) ? _this.gamelebi.shareDomain: null
  1164. };
  1165. _this.gamelebi.shareLog(options,
  1166. function() {
  1167. _this.shareOKHandler()
  1168. })
  1169. },
  1170. cancel: function() {
  1171. _this.shareCancelHandler()
  1172. }
  1173. })
  1174. };
  1175. GameLeBiWx.prototype.share = function() {
  1176. this.setShareData();
  1177. if (this.gamelebi.gameid) {
  1178. this.gamelebi.shareFlow()
  1179. }
  1180. };
  1181. GameLeBiWx.prototype.shareOKHandler = function() {
  1182. _czc.push(["_trackEvent", "分享", "成功"]);
  1183. this.shareOK && this.shareOK.apply(this.gamelebi);
  1184. };
  1185. GameLeBiWx.prototype.shareCancelHandler = function() {
  1186. this.shareCancel && this.shareCancel.apply(this.gamelebi);
  1187. };
  1188. GameLeBiApp = function(gamelebi) {
  1189. this.gamelebi = gamelebi;
  1190. this.version = null;
  1191. this.type = null;
  1192. this.shareOK = null;
  1193. this.shareCancel = null;
  1194. this.oldTitle = null;
  1195. this.init()
  1196. };
  1197. GameLeBiApp.prototype.init = function() {
  1198. this.version = this.gamelebi.utils.getAppVersion();
  1199. if (/uuid\sios/ig.test(navigator.userAgent)) this.type = "iOS";
  1200. if (/uuid\sandroid/ig.test(navigator.userAgent)) this.type = "Android";
  1201. var _this = this;
  1202. document.addEventListener("gamelebiWxShareOk",
  1203. function onBridgeReady() {
  1204. if (_this.oldTitle) document.title = _this.oldTitle;
  1205. _this.shareOK && _this.shareOK.apply(_this.gamelebi)
  1206. })
  1207. };
  1208. GameLeBiApp.prototype.isVersionOver = function(version) {
  1209. return this.gamelebi.utils.compareVersion(this.version, version)
  1210. };
  1211. GameLeBiApp.prototype.setShareData = function() {
  1212. if (this.type == "iOS") {
  1213. window.location = "appcall::setwxshare::" + this.gamelebi.shareData.link + "::" + this.gamelebi.shareData.title + "::" + this.gamelebi.shareData.content + "::" + this.gamelebi.shareData.imgurl
  1214. } else if (this.type == "Android") {
  1215. this.oldTitle = document.title;
  1216. var space = "9G............................................................|";
  1217. document.title = space + this.gamelebi.shareData.link + "|" + this.gamelebi.shareData.title + "|" + this.gamelebi.shareData.content + "|" + this.gamelebi.shareData.imgurl;
  1218. }
  1219. };
  1220. GameLeBiApp.prototype.share = function() {
  1221. this.setShareData();
  1222. if (this.gamelebi.gameid) {
  1223. this.gamelebi.shareFlow()
  1224. }
  1225. };
  1226. GameLeBiUC = function(gamelebi) {
  1227. this.gamelebi = gamelebi;
  1228. this.version = null;
  1229. window.uc_param_str = {};
  1230. this.init()
  1231. };
  1232. GameLeBiUC.prototype.init = function() {
  1233. this.version = this.gamelebi.utils.getAppVersion();
  1234. var url = "http://hao.uc.cn/getucparam.php";
  1235. var data = {
  1236. uc_param_str: "dnfrpfbivecpbtnt"
  1237. };
  1238. this.gamelebi.utils.jsonp(url, data, null,
  1239. function(data) {
  1240. window.uc_param_str = data
  1241. })
  1242. };
  1243. GameLeBiUC.prototype.isVersionOver = function(version) {
  1244. return this.gamelebi.utils.compareVersion(this.version, version)
  1245. };
  1246. GameLeBiUC.prototype.share = function() {
  1247. if (uc_param_str.fr === 'android' || uc_param_str.fr === 'iphone') {
  1248. if (uc_param_str.fr === 'android') {
  1249. try {
  1250. ucweb.startRequest("shell.page_share", [this.gamelebi.shareData.title, this.gamelebi.shareData.content, this.gamelebi.shareData.link, ''])
  1251. } catch(e) {
  1252. console.error(e.message)
  1253. }
  1254. } else {
  1255. if (this.isVersionOver("9.9.0.0")) {
  1256. this.createIconImage();
  1257. ucbrowser.web_share(this.gamelebi.shareData.title, this.gamelebi.shareData.content, this.gamelebi.shareData.link, '', '', '来自乐比游戏', 'gamelebiucicon')
  1258. } else {
  1259. location.href = "ext:web_share:"
  1260. }
  1261. }
  1262. } else {
  1263. this.gamelebi.utils.debug("其它分享接口")
  1264. }
  1265. };
  1266. GameLeBiUC.prototype.createIconImage = function() {
  1267. var img = document.getElementById("gamelebiucicon");
  1268. if (!img) {
  1269. img = document.createElement("img");
  1270. img.id = "gamelebiucicon";
  1271. if (this.gamelebi.gameid) img.src = "http://game.ikongzhong.cn/" + this.gamelebi.gameid + "/icon.png";
  1272. else img.src = "http://game.ikongzhong.cn/img/icon.png";
  1273. img.className = "gamelebiucicon";
  1274. document.getElementsByTagName("body")[0].appendChild(img)
  1275. }
  1276. };
  1277. GameLeBiZhongsou = function(gamelebi) {
  1278. this.gamelebi = gamelebi;
  1279. this.version = null;
  1280. this.type = null;
  1281. this.shareOK = null;
  1282. this.shareCancel = null;
  1283. this.init()
  1284. };
  1285. GameLeBiZhongsou.prototype.init = function() {
  1286. this.type = (navigator.userAgent.match(/(iPhone|iPod|iPad)/ig) ? "iOS": "Android")
  1287. };
  1288. GameLeBiZhongsou.prototype.share = function() {
  1289. var sharedData = {
  1290. category: "share",
  1291. title: this.gamelebi.shareData.title,
  1292. url: this.gamelebi.shareData.link,
  1293. image: this.gamelebi.shareData.imgurl,
  1294. description: this.gamelebi.shareData.content
  1295. };
  1296. if (this.type == "iOS") {
  1297. location.href = "souyue.onclick://" + encodeURIComponent(JSON.stringify(sharedData))
  1298. } else if (window.JavascriptInterface && JavascriptInterface.onJSClick) {
  1299. JavascriptInterface.onJSClick(JSON.stringify(sharedData))
  1300. }
  1301. };