tph_sgext.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. // SilenGames HTML5 Extension
  2. // Author: Vitaliy Sidorov
  3. // Copyright: SilenGames 2014
  4. function sg_nug_score(name, num) {
  5. try {
  6. var score = new NugPlayScore().init();
  7. score.setValue(num);
  8. nugPlay.api().submitScore(score, name);
  9. } catch(e) {}
  10. };
  11. function sg_nug_achi(name) {
  12. try {
  13. nugPlay.api().achieve(name);
  14. } catch(e) {}
  15. };
  16. function sg_nug_load() {
  17. try {
  18. nugPlay.gameLoaded();
  19. } catch(e) {}
  20. };
  21. function sg_nug_start() {
  22. try {
  23. nugPlay.newGame();
  24. } catch(e) {}
  25. };
  26. function sg_nug_end() {
  27. try {
  28. nugPlay.endGame();
  29. } catch(e) {}
  30. };
  31. function sg_nug_quit() {
  32. try {
  33. nugPlay.quitGame();
  34. } catch(e) {}
  35. };
  36. function sg_kong_stat(name, num) {
  37. try {
  38. parent.kongregate.stats.submit(name, num);
  39. } catch(e) {}
  40. };
  41. function sg_buon_start() {
  42. try {
  43. startSession();
  44. } catch (e) {}
  45. }
  46. function sg_buon_end(num) {
  47. try {
  48. endSession({score:num});
  49. } catch (e) {}
  50. }
  51. function sg_iwin_ad() {
  52. try {
  53. iConsole.ads.show({type: 'interstitial'});
  54. } catch(e) {};
  55. }
  56. function sg_iwin_score(num) {
  57. try {
  58. iConsole.game.postHighScore({score: num});
  59. } catch(e) {};
  60. }
  61. function sg_spil_score(num) {
  62. try {
  63. if (sg_spilapi_obj) {
  64. sg_spilapi_obj.Score.submit(num);
  65. }
  66. } catch(e) {};
  67. }
  68. function sg_spil_award(num) {
  69. try {
  70. if (sg_spilapi_obj) {
  71. var award = {award:'award'+num};
  72. sg_spilapi_obj.Award.submit(award);
  73. }
  74. } catch(e) {};
  75. }
  76. function sg_spil_ad() {
  77. try {
  78. if (sg_spilapi_obj) {
  79. sg_spilapi_obj.GameBreak.request(gml_Script_gmcallback_focusoff, gml_Script_gmcallback_focuson);
  80. }
  81. } catch(e) {
  82. gml_Script_gmcallback_focuson();
  83. };
  84. }
  85. function sg_spil_start() {
  86. try {
  87. return CHEATMODE;
  88. } catch(e) {
  89. return 0;
  90. };
  91. }
  92. function sg_spil_splash() {
  93. try {
  94. if (sg_spilapi_obj) {
  95. sg_spilapi_obj.Branding.displaySplashScreen(gml_Script_gmcallback_splashend);
  96. }
  97. } catch(e) {
  98. gml_Script_gmcallback_splashend();
  99. };
  100. }
  101. function sg_fgl_init() {
  102. function wrap(f) { return function(e) {
  103. var o = document.activeElement;
  104. if (!o || o == document.body || o.tagName == "CANVAS") f.call(this, e);
  105. }; };
  106. window.onkeydown = wrap(window.onkeydown);
  107. window.onkeyup = wrap(window.onkeyup);
  108. }
  109. function sg_fgl_achi(nam) {
  110. try {
  111. // if (!fgl.hasAchievement(nam)) {
  112. // fgl.grantAchievement(nam);
  113. // }
  114. } catch(e) {};
  115. }
  116. function sg_fgl_ad() {
  117. try {
  118. // fgl.showAd();
  119. } catch(e) {};
  120. }
  121. function sg_fgl_more_ok() {
  122. try {
  123. // if (fgl.crossPromotionEnabled) {
  124. // return true;
  125. // } else {
  126. // return false ;
  127. // }
  128. } catch(e) {
  129. return false;
  130. };
  131. }
  132. function sg_fgl_more() {
  133. try {
  134. // fgl.showMoreGames();
  135. } catch(e) {};
  136. }
  137. function sg_fgl_prem_ok() {
  138. try {
  139. // if (fgl.unlockEnabled) {
  140. // return true;
  141. // } else {
  142. // return false;
  143. // }
  144. } catch(e) {
  145. return false;
  146. };
  147. }
  148. function sg_fgl_prem() {
  149. try {
  150. // fgl.inApp.initiateUnlockFunction(
  151. // function(){
  152. // gml_Script_gmcallback_fgl_iap_ok();
  153. // },
  154. // function(){}
  155. // );
  156. } catch(e) {};
  157. }
  158. function sg_fgl_isprem() {
  159. try {
  160. // if (fgl.isPremium()) {
  161. // return true;
  162. // } else {
  163. // return false;
  164. // }
  165. } catch(e) {
  166. return false;
  167. };
  168. }
  169. function sg_fgl_spon_ok() {
  170. try {
  171. // if (fgl.brandingEnabled) {
  172. // return true;
  173. // } else {
  174. // return false;
  175. // }
  176. } catch(e) {
  177. return false;
  178. };
  179. }
  180. function sg_fgl_spon_create() {
  181. try {
  182. if (window.sg_fgl_spon_obj == undefined) {
  183. sg_fgl_spon_obj = document.createElement('img');
  184. sg_fgl_spon_obj.src = "";//fgl.getBrandingLogo();
  185. sg_fgl_spon_obj.onclick = "";//fgl.handleBrandingClick;
  186. sg_fgl_spon_obj.setAttribute('style','display: none; position: absolute; left: 0px; top: 0px; width: 0px; height: 0px; z-index: 5; border: 0px');
  187. document.body.appendChild(sg_fgl_spon_obj);
  188. return true;
  189. } else {
  190. return false;
  191. }
  192. } catch(e) {
  193. return false;
  194. };
  195. }
  196. function sg_fgl_score_send(num) {
  197. try {
  198. //fgl.submitScore(num);
  199. } catch(e) {};
  200. }
  201. function sg_fgl_score_show() {
  202. try {
  203. //fgl.displayScoreboard();
  204. } catch(e) {};
  205. }
  206. function sg_banner_create(siz) {
  207. try {
  208. if (window.bancont != undefined) {
  209. sg_banner_delete();
  210. }
  211. bancont = document.createElement("iframe");
  212. bancont.id = "sg-banner-cont";
  213. bancont.height = siz;
  214. bancont.marginHeight = "0";
  215. bancont.marginWidth = "0";
  216. bancont.srcdoc = '<script type="text/javascript" src=""></script>';
  217. document.body.insertBefore(bancont, document.body.firstChild);
  218. } catch(e) {};
  219. }
  220. function sg_banner_delete() {
  221. try {
  222. if (window.bancont != undefined) {
  223. document.body.removeChild(bancont);
  224. bancont = undefined;
  225. }
  226. } catch(e) {};
  227. }
  228. function sg_lead_create() {
  229. try {
  230. if (window.adscreen == undefined) {
  231. adcont = undefined;
  232. adscreen = document.createElement("div");
  233. adscreen.id = "sg-ad-screen";
  234. adtext = document.createElement("div");
  235. adtext.id = "sg-ad-text";
  236. adtext.innerHTML = "Advertisment";
  237. adbut = document.createElement("img");
  238. adbut.id = "sg-ad-but";
  239. adbut.src = "silengames/adbut.png";
  240. adbut.onclick = gml_Script_gmcallback_adclose;
  241. adbut.width = "30";
  242. adbut.height = "30";
  243. adbut.border = "0";
  244. adbut.alt = "Close";
  245. adscreen.appendChild(adtext);
  246. adscreen.appendChild(adbut);
  247. document.body.insertBefore(adscreen, document.body.firstChild);
  248. }
  249. } catch(e) {};
  250. }
  251. function sg_lead_show(siz) {
  252. try {
  253. if (window.adscreen != undefined) {
  254. adscreen.setAttribute('style','display: block');
  255. adbut.width = siz;
  256. adbut.height = siz;
  257. if (window.adcont == undefined) {
  258. adcont = document.createElement("iframe");
  259. adcont.srcdoc = '<script type="text/javascript" src="http://ad.leadboltmobile.net/show_app_ad.js?section_id=568879653"></script>';
  260. adcont.id = "sg-ad-cont";
  261. adscreen.appendChild(adcont);
  262. }
  263. }
  264. } catch(e) {};
  265. }
  266. function sg_lead_close() {
  267. try {
  268. if (window.adscreen != undefined) {
  269. adscreen.setAttribute('style','display: none');
  270. if (window.adcont != undefined) {
  271. adscreen.removeChild(adcont);
  272. adcont = undefined;
  273. }
  274. }
  275. } catch(e) {};
  276. }
  277. function sg_clay_share(txt) {
  278. try {
  279. Clay('client.share.any', {text: txt});
  280. } catch(e) {};
  281. }
  282. sg_guid = "";
  283. function sg_init(guid) {
  284. try {
  285. sg_guid = guid;
  286. if (window.loadingobj != undefined) {
  287. document.body.removeChild(loadingobj);
  288. }
  289. if (window.loadbarbackobj != undefined) {
  290. document.body.removeChild(loadbarbackobj);
  291. }
  292. if (window.loadintervalid != undefined) {
  293. clearInterval(loadintervalid);
  294. }
  295. if (window.loadingtextobj != undefined) {
  296. document.body.removeChild(loadingtextobj);
  297. }
  298. if (window.sg_spil_spon_obj != undefined) {
  299. sg_spil_spon_obj.setAttribute('style','display: none');
  300. }
  301. //sg_banner_delete();
  302. } catch(e) {};
  303. }
  304. function sg_canvas_resize(xpos, ypos, xsiz, ysiz) {
  305. canvasobj.setAttribute('style','position: absolute; left: '+xpos+'px; top: '+ypos+'px; width: '+xsiz+'px; height: '+ysiz+'px');
  306. }
  307. function sg_brand_set(type) {
  308. try {
  309. switch (type) {
  310. case "claycross": return claycrossbar;
  311. case "fgllogo": return sg_fgl_spon_obj;
  312. case "spillogo": return sg_spil_spon_obj;
  313. case "spilmore": return sg_spil_more_obj;
  314. case "spilcross": return sg_spil_cross_obj;
  315. default: return undefined;
  316. }
  317. } catch(e) {
  318. return undefined;
  319. };
  320. }
  321. function sg_brand_show(type,xpos,ypos,xsiz,ysiz) {
  322. try {
  323. var curobj = sg_brand_set(type);
  324. if (curobj != null && curobj != undefined) {
  325. if (type == "claycross") {
  326. curobj.setAttribute('style','display: block');
  327. } else {
  328. curobj.setAttribute('style','display: block; position: absolute; left: '+xpos+'px; top: '+ypos+'px; width:'+xsiz+'px; height:'+ysiz+'px; z-index: 5; border: 0px');
  329. }
  330. }
  331. } catch(e) {};
  332. }
  333. function sg_brand_hide(type) {
  334. try {
  335. var curobj = sg_brand_set(type);
  336. if (curobj != null && curobj != undefined) {
  337. curobj.setAttribute('style','display: none');
  338. }
  339. } catch(e) {};
  340. }
  341. sg_url_obj = [];
  342. sg_url_count = 0;
  343. function sg_url_add(url,blnk) {
  344. var oLink=document.createElement("a");
  345. oLink.setAttribute('href', url);
  346. if (blnk) {
  347. oLink.setAttribute('target', '_blank');
  348. }
  349. document.body.appendChild(oLink);
  350. var oDiv=document.createElement("div");
  351. oDiv.setAttribute('style','display: block; position: absolute; z-index: 5; border: 0px');
  352. oDiv.setAttribute("id", "sgurlobj"+sg_url_count);
  353. oDiv.style.left = "0px";
  354. oDiv.style.top = "0px";
  355. oDiv.style.width = "0px";
  356. oDiv.style.height = "0px";
  357. oDiv.style.cursor = "default";
  358. oDiv.style.backgroundColor = "rgba(0, 0, 0, 0)";
  359. oLink.appendChild(oDiv);
  360. sg_url_obj[sg_url_count] = oDiv;
  361. return sg_url_count++;
  362. }
  363. function sg_url_delete(num) {
  364. var obj = sg_url_obj[num];
  365. if (obj) {
  366. document.body.removeChild(obj.parentNode);
  367. sg_url_obj[num] = undefined;
  368. }
  369. }
  370. function sg_url_change(num, xpos, ypos, xsiz, ysiz) {
  371. var obj = sg_url_obj[num];
  372. if (obj) {
  373. obj.style.left = xpos + "px";
  374. obj.style.top = ypos + "px";
  375. obj.style.width = xsiz + "px";
  376. obj.style.height = ysiz + "px";
  377. }
  378. }
  379. function sg_get(url) {
  380. if (window.XMLHttpRequest) {
  381. xmlObject = new XMLHttpRequest();
  382. } else {
  383. xmlObject = new ActiveXObject("Microsoft.XMLHTTP");
  384. }
  385. xmlObject.open("GET",url,0);
  386. xmlObject.send(null);
  387. return xmlObject.responseText;
  388. }
  389. sg_focus = 1;
  390. sg_visible_type = "";
  391. sg_visible_event = "";
  392. try {
  393. if (typeof document.hidden !== "undefined") {
  394. sg_visible_type = "hidden";
  395. sg_visible_event = "visibilitychange";
  396. } else if (typeof document.webkitHidden !== "undefined") {
  397. sg_visible_type = "webkitHidden";
  398. sg_visible_event = "webkitvisibilitychange";
  399. } else if (typeof document.msHidden !== "undefined") {
  400. sg_visible_type = "msHidden";
  401. sg_visible_event = "msvisibilitychange";
  402. } else if (typeof document.mozHidden !== "undefined") {
  403. sg_visible_type = "mozHidden";
  404. sg_visible_event = "mozvisibilitychange";
  405. }
  406. } catch(e) {};
  407. if (sg_visible_event != "") {
  408. document.addEventListener(sg_visible_event, sg_get_visibility, false);
  409. }
  410. window.addEventListener("focus",sg_focus_on, false);
  411. window.addEventListener("blur",sg_focus_off, false);
  412. function sg_focus_on() {
  413. try {
  414. if (sg_focus == 0) {
  415. sg_focus = 1;
  416. gml_Script_gmcallback_focuson();
  417. }
  418. } catch(e) {};
  419. }
  420. function sg_focus_off() {
  421. try {
  422. if (sg_focus == 1) {
  423. sg_focus = 0;
  424. gml_Script_gmcallback_focusoff();
  425. }
  426. } catch(e) {};
  427. }
  428. function sg_get_visibility() {
  429. try {
  430. if (document[sg_visible_type] == 1) {
  431. sg_focus_off();
  432. } else if (document[sg_visible_type] == 0) {
  433. sg_focus_on();
  434. }
  435. } catch(e) {};
  436. }
  437. function sg_get_language() {
  438. try {
  439. var lang = window.navigator.userLanguage || window.navigator.language;
  440. return lang.substring(0,2).toLowerCase();
  441. } catch(e) {
  442. return "en";
  443. };
  444. }
  445. sg_unlock_audio = null;
  446. sg_play_audio = null;
  447. sg_is_winphone = false;
  448. function sg_unlock_music(num, win) {
  449. sg_unlock_audio = document.getElementsByTagName('audio')[num];
  450. if (win) {
  451. sg_is_winphone = true;
  452. }
  453. }
  454. function sg_play_music() {
  455. try {
  456. if (sg_play_audio != null) {
  457. sg_stop_music();
  458. }
  459. sg_play_audio = sg_unlock_audio;
  460. sg_play_audio.loop = true;
  461. sg_play_audio.addEventListener("ended", sg_play_music, false);
  462. if (sg_is_winphone) {
  463. sg_play_audio.play();
  464. } else {
  465. window.addEventListener("touchend", sg_unlock_music_event, false);
  466. }
  467. } catch(e) {};
  468. }
  469. function sg_unlock_music_event() {
  470. try {
  471. sg_play_audio.play();
  472. window.removeEventListener("touchend", sg_unlock_music_event, false);
  473. sg_is_winphone = true;
  474. } catch(e) {};
  475. }
  476. function sg_stop_music() {
  477. try {
  478. sg_play_audio.pause();
  479. sg_play_audio.removeEventListener("ended", sg_play_music, false);
  480. } catch(e) {};
  481. }
  482. function sg_unlock_webaudio() {
  483. try {
  484. window.addEventListener("touchstart", sg_unlock_webaudio_event, false);
  485. } catch(e) {};
  486. }
  487. function sg_unlock_webaudio_event(event) {
  488. try {
  489. var buffer = g_WebAudioContext.createBuffer(1, 1, 22050);
  490. var source = g_WebAudioContext.createBufferSource();
  491. source.buffer = buffer;
  492. source.connect(g_WebAudioContext.destination);
  493. source.noteOn(0);
  494. window.removeEventListener("touchstart", sg_unlock_webaudio_event, false);
  495. } catch(e) {};
  496. }
  497. function sg_no_bar() {
  498. if(!window.location.hash)
  499. {
  500. var divh = document.getElementById('gm4html5_div_id').style.height;
  501. if (divh < (window.outerHeight + 200))
  502. {
  503. document.getElementById('gm4html5_div_id').style.height = (window.outerHeight + 200) + 'px';
  504. }
  505. setTimeout ( function(){ window.scrollTo(0,1); },50);
  506. }
  507. }
  508. function sg_ios7_fix() {
  509. window.addEventListener('scroll', function () {
  510. if (document.activeElement === document.body && window.scrollY > 0) {
  511. document.body.scrollTop = 0;
  512. }
  513. }, true);
  514. }
  515. function test_browser_storage() {
  516. try {
  517. return 'localStorage' in window && window['localStorage'] !== null;
  518. } catch (e) {
  519. return false;
  520. }
  521. }
  522. sg_save_ok = test_browser_storage();
  523. function sg_save(name, numb) {
  524. try {
  525. var key = sg_guid + name;
  526. if (sg_save_ok) {
  527. window.localStorage.setItem(key, numb);
  528. } else {
  529. var date = new Date;
  530. date.setDate(date.getDate() + 999);
  531. document.cookie = key +"="+ numb +"; path=/; expires="+ date.toUTCString();
  532. }
  533. } catch(e) {};
  534. }
  535. function sg_load(name, def) {
  536. try {
  537. var key = sg_guid + name;
  538. if (sg_save_ok) {
  539. var done = window.localStorage.getItem(key);
  540. } else {
  541. var matches = document.cookie.match(new RegExp(
  542. "(?:^|; )" + key.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
  543. ))
  544. var done = matches ? decodeURIComponent(matches[1]) : undefined;
  545. }
  546. if (done!=null && done!="") {
  547. return parseInt(done);
  548. } else {
  549. return def;
  550. }
  551. } catch(e) {
  552. return def;
  553. };
  554. }
  555. function sg_orient(ok) {
  556. try {
  557. if (ok) {
  558. orientobj.setAttribute('style','display: block');
  559. } else {
  560. orientobj.setAttribute('style','display: none');
  561. }
  562. } catch(e) {};
  563. }
  564. function sg_test_orient() {
  565. try {
  566. if (!viewporter || !viewporter.ACTIVE) {
  567. alert(0)
  568. return false;
  569. } else {
  570. alert(1)
  571. return true;
  572. }
  573. } catch(e) {
  574. alert("not try")
  575. return true;
  576. };
  577. }
  578. sg_load_perc = 0;
  579. function sg_loadingbar(_graphics, _width, _height, _total, _current, _loadingscreen) {
  580. if (typeof(window.innerWidth)=='number') {
  581. browser_width = window.innerWidth;
  582. browser_height = window.innerHeight;
  583. } else if (document.documentElement&&document.documentElement.clientWidth) {
  584. browser_width = document.documentElement.clientWidth;
  585. browser_height = document.documentElement.clientHeight;
  586. } else if (document.body&&document.body.clientWidth) {
  587. browser_width = document.body.clientWidth;
  588. browser_height = document.body.clientHeight;
  589. }
  590. multi = (browser_height / splash_h);
  591. var new_width = (splash_w * multi);
  592. var load_perc = _current/_total*100;
  593. if (load_perc < 100) {
  594. if (sg_load_perc < load_perc) {
  595. sg_load_perc+=1;
  596. }
  597. } else {
  598. sg_load_perc = 100;
  599. }
  600. var perc = bar_img_w/100*sg_load_perc;
  601. var bar_x = (browser_width-new_width)/2+bar_img_x*multi;
  602. var bar_y = bar_img_y*multi;
  603. var bar_w = bar_img_w*multi;
  604. var bar_w2 = perc*multi;
  605. var bar_h = bar_img_h*multi;
  606. if (loadbarbackobj) {
  607. loadbarbackobj.setAttribute('style','left: '+bar_x+'px; top: '+bar_y+'px; width:'+bar_w+'px; height:'+bar_h+'px; background-size: '+(bar_img_w*multi)+'px');
  608. }
  609. if (loadbarobj) {
  610. loadbarobj.setAttribute('style','left: '+bar_x+'px; top: '+bar_y+'px; width:'+bar_w2+'px; height:'+bar_h+'px; background-size: '+(bar_img_w*multi)+'px');
  611. }
  612. }
  613. //create banner
  614. /*
  615. browser_width = splash_w;
  616. browser_height = splash_h;
  617. if (typeof(window.innerWidth)=='number') {
  618. browser_width = window.innerWidth;
  619. browser_height = window.innerHeight;
  620. } else if (document.documentElement&&document.documentElement.clientWidth) {
  621. browser_width = document.documentElement.clientWidth;
  622. browser_height = document.documentElement.clientHeight;
  623. } else if (document.body&&document.body.clientWidth) {
  624. browser_width = document.body.clientWidth;
  625. browser_height = document.body.clientHeight;
  626. }
  627. multi = (browser_height / splash_h);
  628. bancont = undefined;
  629. sg_banner_create(Math.round(70*multi).toString());
  630. */