KoCByte

A Kingdoms of Camelot Tracker (Kocmon replacement)

当前为 2016-05-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name KoCByte
  3. // @version 2
  4. // @description A Kingdoms of Camelot Tracker (Kocmon replacement)
  5. // @namespace kocbyte.com
  6. // @icon http://www.gravatar.com/avatar/f93cdced9c9b863a7d9e4b9988886015
  7. // @include *.kocbyte.com/*
  8. // @include *.kingdomsofcamelot.com/fb/e2/src/main_src.php*
  9. // @grant unsafeWindow
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // @grant GM_deleteValue
  13. // @grant GM_xmlhttpRequest
  14. // @grant GM_openInTab
  15. // @grant GM_log
  16. // @grant GM_listValues
  17. // @grant GM_addStyle
  18. // @grant GM_registerMenuCommand
  19. // @require http://code.jquery.com/jquery-latest.min.js
  20. // ==/UserScript==
  21.  
  22. //============================================================================
  23.  
  24. var uW = unsafeWindow;
  25. var Tabs = {};
  26. var mainPop;
  27. var kbPopUpTopClass = 'kbPopTop';
  28.  
  29. var Options = {
  30. kbWinIsOpen: false,
  31. kbTrackOpen: true,
  32. currentTab: 'Mod',
  33. debug: true,
  34. };
  35.  
  36. var aj2 = function(c, d, b, a){
  37. if(c.match(/fetchMapTiles/)){
  38. if(Options.debug){
  39. kb.debug(d);
  40. }
  41. }
  42. if (d.ctrl && d.ctrl == "Tracking"){
  43. return;
  44. //disable - don't send on the message
  45. }else{
  46. uW.AjaxCall.gAjaxRequest(c, d, b, a, "post");
  47. }
  48. };
  49.  
  50. var kb = {
  51. uid: 0,
  52. name: '',
  53. domain: 0,
  54. allianceId: 0,
  55. allianceName: '',
  56. misted: 0,
  57. cities: [],
  58. domains: [],
  59. seed: null,
  60. target: {
  61. x: 0,
  62. y: 0
  63. },
  64. authedSites: null,
  65. currentUrl: document.location.toString(),
  66. currentWebFolder: document.location.host+document.location.pathname.replace(/\\/g, '/').replace(/\/[^\/]*\/?$/, '')+'/',
  67. removedMixPanel: false,
  68. site: 'https://www.kocbyte.com/',
  69. url: 'https://www.kocbyte.com/ajax/listener.php',
  70. storagePrefix: 'KoCByte_',
  71. citiesSaved: '',
  72. citiesLastSent: 0,
  73. sendInfoDelay: 1000*60*60*6,
  74. updateCheckDelay: 1000*60*60*24,
  75. scriptId: 19269,
  76. scriptVer: 1,
  77. sendTimer: null,
  78. updateTimer: null,
  79. taskTimer: null,
  80. data: {
  81. alliances: [],
  82. alli: [],
  83. players: [],
  84. },
  85. generateRandomNumber: function(min, max){
  86. if(min >= max){
  87. return null;
  88. }else{
  89. return Math.round(min+((max-min)*Math.random()));
  90. }
  91. },
  92. createUrl: function(page){
  93. return 'https://www'+(uW.g_server)+'.kingdomsofcamelot.com/fb/e2/src/'+page;
  94. },
  95. createAjaxUrl: function(page){
  96. return 'https://www'+(uW.g_server)+'.kingdomsofcamelot.com/fb/e2/src/ajax/'+page+'.php';
  97. },
  98. getAjaxParams: function(){
  99. if(uW && uW.g_ajaxparams){
  100. return JSON.parse(JSON.stringify(uW.g_ajaxparams));
  101. }
  102. },
  103. setValueObject: function(k, v){
  104. v = JSON.stringify(v);
  105. GM_setValue(k, v);
  106. },
  107. getValueObject: function(k, dv){
  108. var v = GM_getValue(k, dv);
  109. if(!v || v === undefined){
  110. return null;
  111. }
  112. v = JSON.parse(v);
  113. if(!v){
  114. if(!dv){
  115. v = null;
  116. }
  117. else{
  118. v = dv;
  119. }
  120. }
  121. return v;
  122. },
  123. setValue: function(k, v){
  124. GM_setValue(k, v);
  125. },
  126. getValue: function(k, dv){
  127. return(GM_getValue(k, dv));
  128. },
  129. deleteValue: function(k){
  130. GM_deleteValue(k);
  131. },
  132. getDomains: function(force){
  133. if(uW.g_ajaxparams){
  134. var now = new Date().getTime()*1;
  135. var wait = 86400000;//1 day
  136. var k = kb.storagePrefix+'getDomains_lastcheck';
  137. var lastsent = kb.getValue(k,0);
  138. if(force || 1*lastsent+wait < now){
  139. var args = {};
  140. args.v2 = true;
  141. var json = kb.sendToKabam(args,'myServers',null,true);
  142. if(json && json.selectableServers && json.selectableServers.servers){
  143. var domains = [];
  144. for(var i in json.selectableServers.servers){
  145. var d = json.selectableServers.servers[i].serverId;
  146. domains.push(1*d);
  147. }
  148. domains.sort();
  149. kb.log('getDomains();');
  150. kb.setValue(''+k,''+now);
  151. return domains;
  152. }
  153. }else{
  154. var playerdomains=kb.getValue('domains');
  155. if(!playerdomains){
  156. playerdomains = [];
  157. playerdomains.push(1*kb.domain);
  158. return playerdomains;
  159. }else{
  160. return JSON.parse(''+playerdomains);
  161. }
  162. }
  163. }
  164. },
  165. getSavedInfo: function(){
  166. return(kb.getValue('ajaxparams', null));
  167. },
  168. getSavedServerId: function(){
  169. return(kb.getValue('sid'));
  170. },
  171. getCurrentCityId: function(){
  172. if(uW && uW.currentcityid){
  173. return JSON.parse(JSON.stringify(uW.currentcityid));
  174. }
  175. },
  176. getCities: function(){
  177. var seed = kb.getSeed();
  178. if(seed && seed.cities){
  179. return JSON.parse(JSON.stringify(seed.cities));
  180. }
  181. },
  182. gameInfoSave: function(){
  183. if(uW && uW.seed){
  184. kb.setValue('domain', kb.domain);
  185. kb.setValue('uid', kb.uid);
  186. kb.setValue('name', kb.name);
  187. kb.setValue('allianceId', kb.allianceId);
  188. kb.setValue('allianceName', kb.allianceName);
  189. kb.setValue('misted', kb.misted);
  190. kb.setValueObject('cities', kb.cities);
  191. kb.setValueObject('domains', kb.domains);
  192.  
  193. var current = null;
  194. var saved = null;
  195. var tmp = null;
  196. var thekey = '';
  197. //seed
  198. tmp = [];
  199. for(var i in kb.seed){
  200. thekey = kb.storagePrefix+'SEED_'+i;
  201. kb.setValueObject(thekey,kb.seed[i]);
  202. tmp.push(i);
  203. //console.log(kb.getValueObject(thekey));
  204. }
  205. kb.setValueObject(kb.storagePrefix+'SEEDKEYS',tmp);
  206. //cities
  207. current = kb.getValueObject('cities');
  208. thekey = kb.storagePrefix+'CITIES';
  209. saved = kb.getValueObject(thekey);
  210. if(current != saved){
  211. kb.setValueObject( kb.storagePrefix+'CITIES',current);
  212. }
  213. kb.setValueObject('acctIds', kb.acctIds);
  214. }
  215. },
  216. gameInfoLoad: function(){
  217. if(uW && uW.seed){
  218. kb.uid = kb.getUserId();
  219. kb.name = kb.getUserName();
  220. kb.domain = kb.getServerId();
  221. kb.domains = kb.getDomains();
  222. kb.allianceId = kb.getPlayerAllianceId();
  223. kb.allianceName = kb.getPlayerAllianceName();
  224. kb.misted = kb.getPlayerMist();
  225. kb.cities = kb.getCities();
  226. kb.authedSites = kb.authorizedWebsiteGet();
  227. kb.storagePrefix = kb.uid+'_'+kb.domain+'_';
  228. kb.seed = kb.getSeed();
  229. kb.acctIds = kb.getSavedUserIds(kb.uid);
  230. }else{
  231. kb.uid = kb.getValue('uid');
  232. kb.name = kb.getValue('name');
  233. kb.domain = kb.getValue('domain');
  234. kb.domains = kb.getValueObject('domains');
  235. kb.allianceId = kb.getValue('allianceId');
  236. kb.allianceName = kb.getValue('allianceName');
  237. kb.misted = kb.getValue('misted');
  238. kb.cities = kb.getValueObject('cities');
  239. kb.authedSites = kb.authorizedWebsiteGet();
  240. kb.storagePrefix = kb.uid+'_'+kb.domain+'_';
  241.  
  242. //the seed is too large to store as one string so we have to reassemble
  243. kb.seed = {};
  244. kb.seedKEYS = kb.getValueObject(kb.storagePrefix+'SEEDKEYS');
  245. if(kb.seedKEYS){
  246. var prefix = kb.storagePrefix+'SEED_';
  247. var k='';
  248. for(var i in kb.seedKEYS){
  249. k = kb.seedKEYS[i];
  250. kb.seed[k] = JSON.parse(kb.getValue(prefix+k));
  251. }
  252. }
  253. kb.acctIds = kb.getSavedUserIds();
  254. }
  255. },
  256. getServerId: function(){
  257. if(uW && uW.g_server){
  258. return (1*uW.g_server);
  259. }
  260. },
  261. getSavedUserIds: function(uid){
  262. var uids = kb.getValueObject('acctIds',[uid]);
  263. if(uid){
  264. if(!$.inArray(uid,uids)){
  265. uids.push(uid);
  266. }
  267. }
  268. return uids;
  269. },
  270. getUserId: function(){
  271. if(uW && uW.g_ajaxparams && uW.g_ajaxparams.tvuid){
  272. return JSON.parse(JSON.stringify(uW.g_ajaxparams.tvuid));
  273. }
  274. },
  275. getUserName: function(){
  276. if(uW && uW.seed && uW.seed.player && uW.seed.player.name){
  277. return JSON.parse(JSON.stringify(uW.seed.player.name));
  278. }
  279. },
  280. getSeed: function(){
  281. if(uW && uW.seed){
  282. return JSON.parse(JSON.stringify(uW.seed));
  283. }
  284. },
  285. getPlayerAllianceId: function(){
  286. if(uW && uW.seed && uW.seed.allianceDiplomacies && uW.seed.allianceDiplomacies.allianceId){
  287. return JSON.parse(JSON.stringify(uW.seed.allianceDiplomacies.allianceId));
  288. }
  289. return 0;
  290. },
  291. getPlayerAllianceName: function(){
  292. if(uW && uW.seed && uW.seed.allianceDiplomacies && uW.seed.allianceDiplomacies.allianceName){
  293. return JSON.parse(JSON.stringify(uW.seed.allianceDiplomacies.allianceName));
  294. }
  295. return '';
  296. },
  297. getPlayerMist: function(){
  298. var result=0;
  299. if(uW && uW.seed && uW.seed.playerEffects && uW.seed.playerEffects.fogExpire){
  300. result = uW.seed.playerEffects.fogExpire;
  301. var timestamp = Math.floor(new Date().getTime()/1000);
  302. if(timestamp > result){
  303. result=0;
  304. }
  305. }
  306. return JSON.parse(JSON.stringify(result));
  307. },
  308. sendToKB: function(type,payload,callback){
  309. var url = kb.url;
  310. var obj = {
  311. domain: kb.domain,
  312. uid: kb.uid,
  313. cities: kb.cities,
  314. allianceName: encodeURIComponent(kb.allianceName),
  315. userName: encodeURIComponent(kb.name),
  316. data: payload,
  317. };
  318. if(Options.debug){
  319. kb.debug(obj);
  320. }
  321. kb.log('Sending...');
  322. var args='mode=info&data='+encodeURIComponent(JSON.stringify(obj));
  323. GM_xmlhttpRequest({
  324. "method": 'POST',
  325. "url": url,
  326. "data": args,
  327. "headers": {
  328. "Content-type" : "application/x-www-form-urlencoded"
  329. },
  330. "onreadystatechange": function(r) {
  331. },
  332. "onload": function(result) {
  333. if(result && result.status!=200 && Options.debug){
  334. var s='';
  335. s=s+"\n"+'url='+url;
  336. s=s+"\n"+'data='+JSON.stringify(obj);
  337. if(result.status){s=s+"\n"+'status:'+result.status;}
  338. if(result.statusText){s=s+"\n"+'statusText'+result.statusText;}
  339. if(result.responseHeaders){s=s+"\n"+'responseHeaders'+result.responseHeaders;}
  340. if(result.responseText){s=s+"\n"+'responseText'+result.responseText;}
  341. if(result.readyState){s=s+"\n"+'readyState'+result.readyState;}
  342. kb.debug(s);
  343. }
  344. if(result && result.status == 200){
  345. kb.log('Send done!');
  346. if(Options.debug){
  347. kb.debug('Send done!');
  348. }
  349. }
  350. if(callback) {
  351. callback(result);
  352. }
  353. }
  354. });
  355. },
  356. sendToKabam: function(args,page,callback){
  357. var async = false;
  358. var data = JSON.parse(JSON.stringify(uW.g_ajaxparams));
  359. for(var i in args){
  360. data[i] = args[i];
  361. }
  362. var url = kb.createAjaxUrl(page);
  363. var str = '';
  364. for(var k in data){
  365. str = str+'&'+k+'='+data[k];
  366. }
  367. str = str.substr(1);
  368. if(callback){
  369. async = true;
  370. }
  371. if(Options.debug){
  372. kb.debug(str);
  373. }
  374. var result = null;
  375. $.ajax({
  376. 'type': "POST",
  377. 'url': url,
  378. 'data': str,
  379. 'async': async,
  380. 'success': function(r){
  381. if(callback){
  382. callback(r);
  383. }else{
  384. if(typeof r === 'object'){
  385. result = JSON.parse(r);
  386. }else if(typeof r === 'string'){
  387. var hasCode = (/function\(/m.exec(r));
  388. if(hasCode){ return; }
  389. r.trim();
  390. if(r.charAt(0) == '"'){
  391. fNQ = r.indexOf('"') + 1;
  392. lNQ = r.lastIndexOf('"');
  393. r = r.substring(fNQ, lNQ);
  394. r = r.trim();
  395. }
  396. result = JSON.parse(r);
  397. }
  398. if(!result){
  399. result = r;
  400. }
  401. }
  402. }
  403. });
  404. return result;
  405. },
  406. saveInfo: function(){
  407. var info = JSON.stringify(kb.getCurrentInfo());
  408. if(info){
  409. var sid = kb.getServerId();
  410. kb.setValue('ajaxparams',info);
  411. kb.setValue('sid',sid);
  412. }
  413. },
  414. sendInfo: function(force){
  415. if(uW.g_ajaxparams && uW.g_server){
  416. kb.log('checking if time to send');
  417. var now = new Date().getTime();
  418. var k = kb.storagePrefix+'lastsent_ajaxparams';
  419. var lastsent = kb.getValue(k,0);
  420. if(force || 1*lastsent+kb.sendInfoDelay<now){
  421. var savedkey = kb.storagePrefix+'saved_ajaxparams';
  422. var saved = JSON.parse(kb.getValue(savedkey,null));
  423. var json = kb.getAjaxParams();
  424. if(force || saved != json){
  425. kb.setValue(k,''+now+'');
  426. kb.setValue(savedkey,''+JSON.stringify(json));
  427. kb.log('sending: basic');
  428. kb.sendToKB('basic', json);
  429. }
  430. }
  431. }
  432. },
  433. showTime: function(timestamp,version){
  434. var now = null;
  435. if(timestamp){
  436. now = new Date(timestamp);
  437. }else{
  438. now = new Date();
  439. }
  440. var hours = now.getHours();
  441. var minutes = now.getMinutes();
  442. var seconds = now.getSeconds();
  443. var timeValue = "" + ((hours >12) ? hours -12 :hours);
  444. if (timeValue == "0") timeValue = 12;
  445. timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
  446. timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
  447. timeValue += (hours >= 12) ? " PM" : " AM";
  448. return timeValue;
  449. },
  450. log: function(msg){
  451. var type = $.type(msg);
  452. if(type == 'string'){
  453. msg.replace(/</gi,"&lt;");
  454. msg.replace(/>/gi,"&gt;");
  455. }else{
  456. msg = JSON.stringify(msg,null,"\t");
  457. msg = msg.replace(/</gi,'&lt;');
  458. msg = msg.replace(/>/gi,'&gt;');
  459. }
  460. var consoleStr = 'KoCByte: '+kb.domain+' @ '+kb.showTime()+': '+msg;
  461. uW.console.log(consoleStr);
  462. var elem = $('#'+kb.elemPrefix+'-log-result');
  463. var html = '';
  464. if(type == 'string'){
  465. html = '<div>'+kb.showTime()+' '+msg+'</div>';
  466. }else{
  467. html = '<pre>'+kb.showTime()+"\n"+msg+'</pre>';
  468. }
  469. var n = elem.children().length;
  470. if(n > 10){
  471. elem.children(':last').remove();
  472. }
  473. elem.prepend(html);
  474. },
  475. debug: function(msg){
  476. var type = $.type(msg);
  477. if(type == 'string'){
  478. msg.replace(/</gi,"&lt;");
  479. msg.replace(/>/gi,"&gt;");
  480. }else{
  481. msg = JSON.stringify(msg,null,"\t");
  482. msg = msg.replace(/</gi,'&lt;');
  483. msg = msg.replace(/>/gi,'&gt;');
  484. }
  485. var consoleStr = 'KoCByte: '+kb.domain+' @ '+kb.showTime()+': '+msg;
  486. uW.console.log(consoleStr);
  487. var elem = $('#'+kb.elemPrefix+'-log-result');
  488. if(type == 'string'){
  489. html = '<div>'+kb.showTime()+' '+msg+'</div>';
  490. }else{
  491. html = '<pre>'+kb.showTime()+"\n"+msg+'</pre>';
  492. }
  493. var n = elem.children().length;
  494. if(n > 10){
  495. elem.children(':last').remove();
  496. }
  497. elem.prepend(html);
  498. },
  499. authorizedWebsiteGet: function(){
  500. var websites = JSON.parse(''+kb.getValue('authedSites',null));
  501. if(!websites){
  502. websites = ['www.kocbyte.com'];
  503. }
  504. if($.inArray($(websites),'www.kocbyte.com') != -1){
  505. websites.push('www.kocbyte.com');
  506. }
  507. return websites;
  508. },
  509. authorizedWebsiteAdd: function(url){
  510. var websites = JSON.parse(''+kb.getValue('authedSites',null));
  511. if(!websites){
  512. websites = ['www.kocbyte.com'];
  513. }
  514. if($.inArray($(websites),url) > -1){
  515. websites.push(url);
  516. var sites = websites.filter(function(elem, pos) {
  517. return websites.indexOf(elem) == pos;
  518. });
  519. kb.setValue('authedSites',''+JSON.stringify(sites));
  520. return true;
  521. }else{
  522. return false;
  523. }
  524. },
  525. getStyles: function(){
  526. var styles = 'a.ptButton20 {color:#ffff80}';
  527. styles = styles + '.large-pull-1,.large-pull-10,.large-pull-11,.large-pull-2,.large-pull-3,.large-pull-4,.large-pull-5,.large-pull-6,.large-pull-7,.large-pull-8,.large-pull-9,.large-push-1,.large-push-10,.large-push-11,.large-push-2,.large-push-3,.large-push-4,.large-push-5,.large-push-7,.large-push-8,.large-push-9{position:relative}';
  528. styles = styles + '.row{max-width:75rem;margin-left:auto;margin-right:auto}';
  529. styles = styles + '.row .row,.row.expanded{max-width:none}';
  530. styles = styles + '.row::after,.row::before{content:" ";display:table}';
  531. styles = styles + '.row::after{clear:both}';
  532. styles = styles + '.row.collapse>.column,.row.collapse>.columns{padding-left:0;padding-right:0}';
  533. styles = styles + '.row .row{margin-left:-.625rem;margin-right:-.625rem}';
  534. styles = styles + '.row .row.collapse{margin-left:0;margin-right:0}';
  535. styles = styles + '.row.expanded .row{margin-left:auto;margin-right:auto}';
  536. styles = styles + '.column,.columns{width:100%;float:left;padding-left:.625rem;padding-right:.625rem}';
  537. styles = styles + '.column:last-child:not(:first-child),.columns:last-child:not(:first-child){float:right}';
  538. styles = styles + '.column.end:last-child:last-child,.end.columns:last-child:last-child{float:left}';
  539. styles = styles + '.column.row.row,.row.row.columns{float:none}';
  540. styles = styles + '.row .column.row.row,.row .row.row.columns{padding-left:0;padding-right:0;margin-left:0;margin-right:0}';
  541. styles = styles + '.large-1{width:8.33333%}';
  542. styles = styles + '.large-push-1{left:8.33333%}';
  543. styles = styles + '.large-pull-1{left:-8.33333%}';
  544. styles = styles + '.large-offset-0{margin-left:0}';
  545. styles = styles + '.large-2{width:16.66667%}';
  546. styles = styles + '.large-push-2{left:16.66667%}';
  547. styles = styles + '.large-pull-2{left:-16.66667%}';
  548. styles = styles + '.large-offset-1{margin-left:8.33333%}';
  549. styles = styles + '.large-3{width:25%}';
  550. styles = styles + '.large-push-3{left:25%}';
  551. styles = styles + '.large-pull-3{left:-25%}';
  552. styles = styles + '.large-offset-2{margin-left:16.66667%}';
  553. styles = styles + '.large-4{width:33.33333%}';
  554. styles = styles + '.large-push-4{left:33.33333%}';
  555. styles = styles + '.large-pull-4{left:-33.33333%}';
  556. styles = styles + '.large-offset-3{margin-left:25%}';
  557. styles = styles + '.large-5{width:41.66667%}';
  558. styles = styles + '.large-push-5{left:41.66667%}';
  559. styles = styles + '.large-pull-5{left:-41.66667%}';
  560. styles = styles + '.large-offset-4{margin-left:33.33333%}';
  561. styles = styles + '.large-6{width:50%}';
  562. styles = styles + '.large-push-6{position:relative;left:50%}';
  563. styles = styles + '.large-pull-6{left:-50%}';
  564. styles = styles + '.large-offset-5{margin-left:41.66667%}';
  565. styles = styles + '.large-7{width:58.33333%}';
  566. styles = styles + '.large-push-7{left:58.33333%}';
  567. styles = styles + '.large-pull-7{left:-58.33333%}';
  568. styles = styles + '.large-offset-6{margin-left:50%}';
  569. styles = styles + '.large-8{width:66.66667%}';
  570. styles = styles + '.large-push-8{left:66.66667%}';
  571. styles = styles + '.large-pull-8{left:-66.66667%}';
  572. styles = styles + '.large-offset-7{margin-left:58.33333%}';
  573. styles = styles + '.large-9{width:75%}';
  574. styles = styles + '.large-push-9{left:75%}';
  575. styles = styles + '.large-pull-9{left:-75%}';
  576. styles = styles + '.large-offset-8{margin-left:66.66667%}';
  577. styles = styles + '.large-10{width:83.33333%}';
  578. styles = styles + '.large-push-10{left:83.33333%}';
  579. styles = styles + '.large-pull-10{left:-83.33333%}';
  580. styles = styles + '.large-offset-9{margin-left:75%}';
  581. styles = styles + '.large-11{width:91.66667%}';
  582. styles = styles + '.large-push-11{left:91.66667%}';
  583. styles = styles + '.large-pull-11{left:-91.66667%}';
  584. styles = styles + '.large-offset-10{margin-left:83.33333%}';
  585. styles = styles + '.large-12{width:100%}';
  586. styles = styles + '.large-offset-11{margin-left:91.66667%}';
  587. styles = styles + '.large-up-1>.column,.large-up-1>.columns{width:100%;float:left}';
  588. styles = styles + '.large-up-1>.column:nth-of-type(1n),.large-up-1>.columns:nth-of-type(1n){clear:none}';
  589. styles = styles + '.large-up-1>.column:nth-of-type(1n+1),.large-up-1>.columns:nth-of-type(1n+1){clear:both}';
  590. styles = styles + '.large-up-1>.column:last-child,.large-up-1>.columns:last-child{float:left}';
  591. styles = styles + '.large-up-2>.column,.large-up-2>.columns{width:50%;float:left}';
  592. styles = styles + '.large-up-2>.column:nth-of-type(1n),.large-up-2>.columns:nth-of-type(1n){clear:none}';
  593. styles = styles + '.large-up-2>.column:nth-of-type(2n+1),.large-up-2>.columns:nth-of-type(2n+1){clear:both}';
  594. styles = styles + '.large-up-2>.column:last-child,.large-up-2>.columns:last-child{float:left}';
  595. styles = styles + '.large-up-3>.column,.large-up-3>.columns{width:33.33333%;float:left}';
  596. styles = styles + '.large-up-3>.column:nth-of-type(1n),.large-up-3>.columns:nth-of-type(1n){clear:none}';
  597. styles = styles + '.large-up-3>.column:nth-of-type(3n+1),.large-up-3>.columns:nth-of-type(3n+1){clear:both}';
  598. styles = styles + '.large-up-3>.column:last-child,.large-up-3>.columns:last-child{float:left}';
  599. styles = styles + '.large-up-4>.column,.large-up-4>.columns{width:25%;float:left}';
  600. styles = styles + '.large-up-4>.column:nth-of-type(1n),.large-up-4>.columns:nth-of-type(1n){clear:none}';
  601. styles = styles + '.large-up-4>.column:nth-of-type(4n+1),.large-up-4>.columns:nth-of-type(4n+1){clear:both}';
  602. styles = styles + '.large-up-4>.column:last-child,.large-up-4>.columns:last-child{float:left}';
  603. styles = styles + '.large-up-5>.column,.large-up-5>.columns{width:20%;float:left}';
  604. styles = styles + '.large-up-5>.column:nth-of-type(1n),.large-up-5>.columns:nth-of-type(1n){clear:none}';
  605. styles = styles + '.large-up-5>.column:nth-of-type(5n+1),.large-up-5>.columns:nth-of-type(5n+1){clear:both}';
  606. styles = styles + '.large-up-5>.column:last-child,.large-up-5>.columns:last-child{float:left}';
  607. styles = styles + '.large-up-6>.column,.large-up-6>.columns{width:16.66667%;float:left}';
  608. styles = styles + '.large-up-6>.column:nth-of-type(1n),.large-up-6>.columns:nth-of-type(1n){clear:none}';
  609. styles = styles + '.large-up-6>.column:nth-of-type(6n+1),.large-up-6>.columns:nth-of-type(6n+1){clear:both}';
  610. styles = styles + '.large-up-6>.column:last-child,.large-up-6>.columns:last-child{float:left}';
  611. styles = styles + '.large-up-7>.column,.large-up-7>.columns{width:14.28571%;float:left}';
  612. styles = styles + '.large-up-7>.column:nth-of-type(1n),.large-up-7>.columns:nth-of-type(1n){clear:none}';
  613. styles = styles + '.large-up-7>.column:nth-of-type(7n+1),.large-up-7>.columns:nth-of-type(7n+1){clear:both}';
  614. styles = styles + '.large-up-7>.column:last-child,.large-up-7>.columns:last-child{float:left}';
  615. styles = styles + '.large-up-8>.column,.large-up-8>.columns{width:12.5%;float:left}';
  616. styles = styles + '.large-up-8>.column:nth-of-type(1n),.large-up-8>.columns:nth-of-type(1n){clear:none}';
  617. styles = styles + '.clearfix::after,.large-up-8>.column:nth-of-type(8n+1),.large-up-8>.columns:nth-of-type(8n+1){clear:both}';
  618. styles = styles + '.large-up-8>.column:last-child,.large-up-8>.columns:last-child{float:left}';
  619. styles = styles + '.large-collapse>.column,.large-collapse>.columns{padding-left:0;padding-right:0}';
  620. styles = styles + '.large-collapse .row{margin-left:0;margin-right:0}';
  621. styles = styles + '.large-uncollapse>.column,.large-uncollapse>.columns{padding-left:.9375rem;padding-right:.9375rem}';
  622. styles = styles + '.large-centered{float:none;margin-left:auto;margin-right:auto}';
  623. styles = styles + '.large-pull-0,.large-push-0,.large-uncentered{position:static;margin-left:0;margin-right:0;float:left}';
  624. styles = styles + '.text-left{text-align:left}';
  625. styles = styles + '.text-right{text-align:right}';
  626. styles = styles + '.text-center{text-align:center}';
  627. styles = styles + '.text-justify{text-align:justify}';
  628. styles = styles + '.hide{display:none!important}';
  629. styles = styles + '.invisible{visibility:hidden}';
  630. styles = styles + '.float-left{float:left!important}';
  631. styles = styles + '.float-right{float:right!important}';
  632. styles = styles + '.float-center{display:block;margin-left:auto;margin-right:auto}';
  633. styles = styles + '.clearfix::after,.clearfix::before{content:"";display:table}';
  634. styles = styles + ' table.kbMainTab { empty-cells: show; margin-left: 5px; margin-top: 4px; padding: 1px; padding-left:5px;}';
  635. styles = styles + ' table.kbMainTab tr td a {color:inherit }';
  636. styles = styles + ' table.kbMainTab tr td {height:60%; empty-cells:show; padding: 0px 4px 0px 4px; margin-top:5px; white-space:nowrap; border: 1px solid; border-style: none none solid none; -moz-border-radius:5px; }';
  637. styles = styles + ' table.kbMainTab tr td.spacer {padding: 0px 0px;}';
  638. styles = styles + ' table.kbMainTab tr td.notSel { color: #ffffff; font-size: 12px; font-weight:bold; -moz-border-radius: 10px; -moz-box-shadow: 0px 1px 3px #357544; text-shadow: -1px 1px 3px #666666; border: solid #615461 1px; background: -moz-linear-gradient(top, #6ff28e, #196b2c);}';
  639. styles = styles + ' table.kbMainTab tr td.sel { color: #000000; font-size: 12px; font-weight:bold; -moz-border-radius: 10px; -moz-box-shadow: 0px 1px 3px #357544; text-shadow: -1px 1px 3px #CECECE; border: solid #615461 1px; background: -moz-linear-gradient(top, #6ff28e, #196b2c);}';
  640. styles = styles + ' table.kbMainTab tr td:hover { color: #191919; font-size: 12px; font-weight:bold; text-shadow: -1px 1px 3px #CECECE; background: -moz-linear-gradient(top, #43cc7e, #20a129)}';
  641. styles = styles + ' tr.kbPopTop td { background-color:transparent; border:none; height: 21px; padding:0px;}';
  642. styles = styles + ' tr.kbretry_kbPopTop td { background-color:#a00; color:#fff; border:none; height: 21px; padding:0px; }';
  643. styles = styles + ' tr.kbMainPopTop td { background-color:#ded; border:none; height: 42px; width:80%; padding:0px; }';
  644. styles = styles + ' tr.kbretry_kbMainPopTop td { background-color:#a00; color:#fff; border:none; height: 42px; padding:0px; }';
  645. styles = styles + ' .kbPopMain { border:1px solid #000000; -moz-box-shadow:inset 0px 0px 10px #6a6a6a; -moz-border-radius-bottomright: 20px; -moz-border-radius-bottomleft: 20px;}';
  646. styles = styles + ' .kbPopup {border:5px ridge #666; opacity:'+(parseFloat(Options.Opacity)<'0.5'?'0.5':Options.Opacity)+'; -moz-border-radius:25px; -moz-box-shadow: 1px 1px 5px #000000; z-index:999999;}';
  647. styles = styles + ' span.kbTextFriendly {color: #080}';
  648. styles = styles + ' span.kbTextHostile {color: #800}';
  649. styles = styles + ' .kbButCancel {background-color:#a00; font-weight:bold; color:#fff}';
  650. styles = styles + ' div.indent25 {padding-left:25px}';
  651. styles = styles + ' .kbdivHeader {transparent;height: 16px;border-bottom:0px solid #000000;font-weight:bold;font-size:11px;opacity:0.75;margin-left:0px;margin-right:0px;margin-top:1px;margin-bottom:0px;padding-top:4px;padding-right:10px;vertical-align:text-top;align:left;background-color:#335577;}';
  652. styles = styles + ' .kbdivLink {color:#000;text-decoration:none;}';
  653. styles = styles + ' .kbdivLink:Hover {color:#000;text-decoration:none;}';
  654. styles = styles + ' .kbdivLink:Active {color:#000;text-decoration:none;}';
  655. styles = styles + ' .kbdivHide {display:none}';
  656. return styles;
  657. },
  658. init: function(){
  659. var debugKey = kb.storagePrefix+'_debug';
  660. var debug = kb.getValue(debugKey, null);
  661. if(debug){
  662. Options.debug = true;
  663. }
  664. var styles = kb.getStyles();
  665. mainPop = new kbPopup (kb.elemPrefix, 40, 40, 725,600, function (){
  666. tabManager.hideTab();
  667. Options.kbWinIsOpen=false;
  668. });
  669. mainPop.autoHeight (true);
  670.  
  671. mainPop.getMainDiv().innerHTML = '<style>'+ styles +'</style>';
  672. AddMainTabLink('KoCByte', eventHideShow, null);
  673. tabManager.init(mainPop.getMainDiv());
  674. if(Options.kbWinIsOpen && Options.kbTrackOpen){
  675. mainPop.show(true);
  676. tabManager.showTab();
  677. }
  678. kb.log('Gathering game info');
  679. kb.gameInfoLoad();
  680. if(!kb.uid || !kb.domain){
  681. return;
  682. }
  683. kb.log('Saving game info');
  684. kb.gameInfoSave();
  685. setTimeout(function(){
  686. AutoUpdater.check();
  687. }, 5000);
  688. setTimeout(function(){
  689. kb.sendInfo(1);
  690. }, 15000);
  691. kb.sendTimer = window.setInterval(function(){
  692. kb.sendInfo(1);
  693. }, kb.sendInfoDelay);
  694. kb.updateTimer = window.setInterval(function(){
  695. AutoUpdater.check();
  696. }, kb.updateCheckDelay);
  697. kb.taskTimer = window.setInterval(function(){
  698. kb.doTask();
  699. },1000*1);
  700. },
  701. initSite: function(){
  702. $('.cityCoords').on('click', function(e){
  703. e.preventDefault();
  704. var x = $(this).attr('data-x');
  705. var y = $(this).attr('data-y');
  706. var d = $(this).attr('data-domain');
  707. kb.setValue('command', 'location|'+d+'|'+x+'|'+y);
  708. });
  709. },
  710. doTask: function(){
  711. var now = new Date().getTime();
  712. kb.setValue('lasttaskrun',''+now+'');
  713. kb.setValue('currentdomain',''+kb.getServerId()+'');
  714. var command = kb.getValue('command', '');
  715. if (command !== '') {
  716. kb.setValue('command','');
  717. kb.log('command=' + command);
  718. var x = 0;
  719. var y = 0;
  720. var cmd = command.split('|');
  721. var type = cmd[0];
  722. var domain = 1*cmd[1];
  723. switch(type){
  724. case 'location':
  725. if(domain == kb.domain){
  726. x = 1*cmd[2];
  727. y = 1*cmd[3];
  728. uW.console.log(x+','+y);
  729. uW.cm.formatModel.jumpTo(x, y);
  730. }else{
  731. kb.log('You\'re in the wrong domain to do this action!');
  732. }
  733. break;
  734. }
  735. }
  736. },
  737. };
  738.  
  739. var AutoUpdater = {
  740. id: 19269,
  741. URL: 'https://greasyfork.org/en/scripts/19269-kocbyte/code/KoCByte.user.js',
  742. name: 'KoCByte',
  743. homepage: 'https://greasyfork.org/en/scripts/19269-kocbyte',
  744. version: kb.scriptVer,
  745. call: function(response) { kb.log("Checking for "+this.name+" Update!");
  746. var _s = this;
  747. GM_xmlhttpRequest({
  748. method: 'GET',
  749. url: _s.URL,
  750. onload: function(xpr) {_s.compare(xpr,response);},
  751. onerror: function(xpr) {_s.compare({responseText:""},response);}
  752. });
  753. },
  754. compareVersion: function(remoteVer, localVer){
  755. var remote = parseInt(remoteVer);
  756. var local = parseInt(localVer);
  757. return ((remote > local) ? true : false);
  758. },
  759. compare: function(xpr,response) {
  760. this.xversion=(/@version\s*(.*?)\s*$/m.exec(xpr.responseText));
  761. if(this.xversion){
  762. this.xversion = this.xversion[1];
  763. }else{
  764. if(response){
  765. uW.Modal.showAlert('<div align="center">Unable to check for updates to '+this.name+'.<br>Please change the update options or visit the<br><a href="'+this.homepage+'" target="_blank">script homepage</a></div>');
  766. }
  767. kb.log("Unable to check for updates");
  768. return;
  769. }
  770. var updated = this.compareVersion(this.xversion, this.version);
  771. if (updated) {
  772. kb.log('New Version Available!');
  773. var body = '<BR><DIV align=center><FONT size=3><B>New version '+this.xversion+' is available!</b></font></div><BR>';
  774. if (this.xrelnotes){
  775. body+='<BR><div align="center" style="border:0;width:470px;height:120px;max-height:120px;overflow:auto"><b>New Features!</b><p>'+this.xrelnotes+'</p></div><BR>';
  776. }
  777. body+='<BR><DIV align=center><a class="gemButtonv2 green" id="doBotUpdate">Update</a></div>';
  778. this.ShowUpdate(body);
  779. }else{
  780. kb.log("No updates available");
  781. }
  782. },
  783. check: function() {
  784. var now = uW.unixtime();
  785. var lastCheck = 0;
  786. if (GM_getValue('updated_'+this.id, 0)) lastCheck = parseInt(GM_getValue('updated_'+this.id, 0));
  787. if (now > (lastCheck + 60*1)) this.call(false);
  788. },
  789. ShowUpdate: function (body) {
  790. var now = uW.unixtime();
  791. setUpdate = function(){
  792. GM_setValue('updated_'+AutoUpdater.id, now);
  793. };
  794. uW.cm.ModalManager.addMedium({
  795. title: this.name,
  796. body: body,
  797. closeNow: false,
  798. close: function (){
  799. setTimeout (function (){GM_setValue('updated_'+AutoUpdater.id, now);}, 0);
  800. uW.cm.ModalManager.closeAll();
  801. },
  802. "class": "Warning",
  803. curtain: false,
  804. width: 500,
  805. height: 700,
  806. left: 140,
  807. top: 140
  808. });
  809.  
  810. document.getElementById('doBotUpdate').addEventListener('click', this.doUpdate, false);
  811. },
  812. doUpdate: function () {
  813. uW.cm.ModalManager.closeAll();
  814. uW.cm.ModalManager.close();
  815. var now = uW.unixtime();
  816. GM_setValue('updated_'+AutoUpdater.id, now);
  817. GM_openInTab(AutoUpdater.URL);
  818. },
  819. };
  820.  
  821. var tabManager = {
  822. tabList : {}, // {name, obj, div}
  823. currentTab : null,
  824. init: function (mainDiv){
  825. var t = tabManager;
  826. var sorter = [];
  827. for(k in Tabs){
  828. if(!Tabs[k].tabDisabled){
  829. t.tabList[k] = {};
  830. t.tabList[k].name = k;
  831. t.tabList[k].obj = Tabs[k];
  832. if(Tabs[k].tabLabel != null)
  833. t.tabList[k].label = Tabs[k].tabLabel;
  834. else
  835. t.tabList[k].label = k;
  836. if(Tabs[k].tabOrder != null)
  837. sorter.push([Tabs[k].tabOrder, t.tabList[k]]);
  838. else
  839. sorter.push([1000, t.tabList[k]]);
  840. t.tabList[k].div = document.createElement('div');
  841. }
  842. }
  843.  
  844. sorter.sort (function (a,b){return a[0]-b[0]});
  845. var m = '<TABLE cellspacing=3 class=pbMainTab><TR>';
  846. for(var i=0; i<sorter.length; i++) {
  847. m += '<TD class=spacer></td><TD align=center class=notSel id=pbtc'+ sorter[i][1].name +' ><A><SPAN>'+ sorter[i][1].label +'</span></a></td>';
  848. //m += '<TD align=center class=notSel id=pbtc'+ sorter[i][1].name +' ><A><SPAN>'+ sorter[i][1].label +'</span></a></td>';
  849. if((i+1)%9 == 0) m+='</tr><TR>';
  850. }
  851. m+='</tr></table>';
  852. //m += '<TD class=spacer width=90% align=right>'+ Version +'&nbsp;</td></tr></table>';
  853. mainPop.getMainTopDiv().innerHTML = m;
  854. for(k in t.tabList){
  855. if(t.tabList[k].name == Options.currentTab)
  856. t.currentTab =t.tabList[k] ;
  857. document.getElementById('pbtc'+ k).addEventListener('click', this.e_clickedTab, false);
  858. var div = t.tabList[k].div;
  859. div.style.display = 'none';
  860. div.style.height = '100%';
  861. mainDiv.appendChild(div);
  862. try{
  863. t.tabList[k].obj.init(div);
  864. }catch(e){
  865. div.innerHTML = "INIT ERROR: "+ e;
  866. }
  867. }
  868. if(t.currentTab == null)
  869. t.currentTab = sorter[0][1];
  870. t.setTabStyle (document.getElementById ('pbtc'+ t.currentTab.name), true);
  871. t.currentTab.div.style.display = 'block';
  872. },
  873. hideTab : function (){
  874. var t = tabManager;
  875. t.currentTab.obj.hide();
  876. },
  877. showTab : function (){
  878. var t = tabManager;
  879. t.currentTab.obj.show();
  880. },
  881. setTabStyle : function (e, selected){
  882. if(selected){
  883. e.className = 'sel';
  884. }else{
  885. e.className = 'notSel';
  886. }
  887. },
  888. e_clickedTab : function (e){
  889. var t = tabManager;
  890. var newTab = t.tabList[e.target.parentNode.parentNode.id.substring(4)];
  891. if(t.currentTab.name != newTab.name){
  892. t.setTabStyle (document.getElementById ('pbtc'+ t.currentTab.name), false);
  893. t.setTabStyle (document.getElementById ('pbtc'+ newTab.name), true);
  894. t.currentTab.obj.hide ();
  895. t.currentTab.div.style.display = 'none';
  896. t.currentTab = newTab;
  897. newTab.div.style.display = 'block';
  898. Options.currentTab = newTab.name;
  899. }
  900. newTab.obj.show();
  901. },
  902. };
  903.  
  904. var WinManager = {
  905. wins: {}, // prefix : kbPopup obj
  906. didHide: [],
  907. get: function(prefix){
  908. var t = WinManager;
  909. return t.wins[prefix];
  910. },
  911. add: function(prefix, pop){
  912. var t = WinManager;
  913. t.wins[prefix] = pop;
  914. if(uW.cpopupWins == null)
  915. uW.cpopupWins = {};
  916. uW.cpopupWins[prefix] = pop;
  917. },
  918. hideAll: function(){
  919. var t = WinManager;
  920. t.didHide = [];
  921. for(var k in t.wins){
  922. if(t.wins[k].isShown()){
  923. t.didHide.push (t.wins[k]);
  924. t.wins[k].show (false);
  925. }
  926. }
  927. },
  928. restoreAll: function(){
  929. var t = WinManager;
  930. for(var i=0; i<t.didHide.length; i++)
  931. t.didHide[i].show(true);
  932. },
  933. delete: function(prefix){
  934. var t = WinManager;
  935. delete t.wins[prefix];
  936. delete uW.cpopupWins[prefix];
  937. }
  938. };
  939.  
  940. // creates a 'popup' div
  941. // prefix must be a unique (short) name for the popup window
  942. function kbPopup(prefix, x, y, width, height, onClose) {
  943. var pop = WinManager.get(prefix);
  944. if(pop){
  945. pop.show (false);
  946. return pop;
  947. }
  948. this.BASE_ZINDEX = 111111;
  949. // protos ...
  950. this.show = show;
  951. this.toggleHide = toggleHide;
  952. this.getTopDiv = getTopDiv;
  953. this.getMainTopDiv = getMainTopDiv;
  954. this.getMainDiv = getMainDiv;
  955. this.getJQMainDiv = getJQMainDiv;
  956. this.getLayer = getLayer;
  957. this.setLayer = setLayer;
  958. this.getLocation = getLocation;
  959. this.setLocation = setLocation;
  960. this.focusMe = focusMe;
  961. this.isShown = isShown;
  962. this.unfocusMe = unfocusMe;
  963. this.centerMe = centerMe;
  964. this.destroy = destroy;
  965. this.autoHeight = autoHeight;
  966. // object vars ...
  967. this.div = document.createElement('div');
  968. this.prefix = prefix;
  969. this.onClose = onClose;
  970. var t = this;
  971. this.div.className = 'kbPopup '+ prefix +'_kbPopup';
  972. this.div.id = prefix +'_outer';
  973. this.div.style.background = "#fff";
  974. this.div.style.zIndex = this.BASE_ZINDEX;
  975. this.div.style.display = 'none';
  976. this.div.style.width = width + 'px';
  977. this.div.style.height = height + 'px';
  978. this.div.style.maxHeight = height + 'px';
  979. this.div.style.overflowY = 'show';
  980. this.div.style.position = "absolute";
  981. this.div.style.top = y +'px';
  982. this.div.style.left = x + 'px';
  983. var topClass = '';
  984. if(kbPopUpTopClass==null)
  985. topClass = 'kbPopupTop '+ prefix +'_kbPopupTop';
  986. else
  987. topClass = kbPopUpTopClass +' '+ prefix +'_'+ kbPopUpTopClass;
  988. var m = '<table cellspacing=0 width=100% ><tr id="'+ prefix +'_bar" class="'+ topClass +'"><td width=99% valign=bottom><SPAN id="'+ prefix +'_top"></span></td>';
  989. m = m + '<td id='+ prefix +'_X align=right valign=middle onmouseover="this.style.cursor=\'pointer\'" style="color:#fff; background:#333; font-weight:bold; font-size:14px; padding:0px 5px; -moz-border-radius-topright: 20px;">x</td></tr>';
  990. m = m + '</table><table cellspacing=0 width=100% ><tr><td height=100% valign=top class="kbPopMain '+ prefix +'_kbPopMain" colspan=2 id="'+ prefix +'_main"></td></tr></table>';
  991. document.body.appendChild(this.div);
  992. this.div.innerHTML = m;
  993. document.getElementById(prefix+'_X').addEventListener ('click', e_XClose, false);
  994. this.div.addEventListener('mousedown', e_divClicked, false);
  995. WinManager.add(prefix, this);
  996. function e_divClicked(){
  997. t.focusMe();
  998. }
  999. function e_XClose(){
  1000. t.show(false);
  1001. if (t.onClose != null)
  1002. t.onClose();
  1003. }
  1004. function autoHeight(onoff){
  1005. if(onoff)
  1006. t.div.style.height = '';
  1007. else
  1008. t.div.style.height = t.div.style.maxHeight;
  1009. }
  1010. function focusMe(){
  1011. t.setLayer(5);
  1012. for(var k in uW.cpopupWins){
  1013. if(k != t.prefix)
  1014. uW.cpopupWins[k].unfocusMe();
  1015. }
  1016. }
  1017. function unfocusMe(){
  1018. t.setLayer(-5);
  1019. }
  1020. function getLocation(){
  1021. return {x: parseInt(this.div.style.left), y: parseInt(this.div.style.top)};
  1022. }
  1023. function setLocation(loc){
  1024. t.div.style.left = loc.x +'px';
  1025. t.div.style.top = loc.y +'px';
  1026. }
  1027. function destroy(){
  1028. document.body.removeChild(t.div);
  1029. WinManager.delete (t.prefix);
  1030. }
  1031. function centerMe(parent){
  1032. var coords;
  1033. if(parent == null){
  1034. coords = getClientCoords(document.body);
  1035. }else
  1036. coords = getClientCoords(parent);
  1037. var x = ((coords.width - parseInt(t.div.style.width)) / 2) + coords.x;
  1038. var y = ((coords.height - parseInt(t.div.style.height)) / 2) + coords.y;
  1039. if(x<0)
  1040. x = 0;
  1041. if(y<0)
  1042. y = 0;
  1043. t.div.style.left = x +'px';
  1044. t.div.style.top = y +'px';
  1045. }
  1046. function setLayer(zi){
  1047. t.div.style.zIndex = ''+ (this.BASE_ZINDEX + zi);
  1048. }
  1049. function getLayer(){
  1050. return parseInt(t.div.style.zIndex) - this.BASE_ZINDEX;
  1051. }
  1052. function getTopDiv(){
  1053. return document.getElementById(this.prefix+'_top');
  1054. }
  1055. function getMainDiv(){
  1056. return document.getElementById(this.prefix+'_main');
  1057. }
  1058. function getJQMainDiv(){
  1059. return $('#'+this.prefix+'_main');
  1060. }
  1061. function getMainTopDiv(){
  1062. return document.getElementById(this.prefix+'_top');
  1063. }
  1064. function isShown (){
  1065. return t.div.style.display == 'block';
  1066. }
  1067. function show(tf){
  1068. if (tf){
  1069. t.div.style.display = 'block';
  1070. t.focusMe ();
  1071. } else {
  1072. t.div.style.display = 'none';
  1073. }
  1074. return tf;
  1075. }
  1076. function toggleHide(t){
  1077. if (t.div.style.display == 'block') {
  1078. return t.show (false);
  1079. } else {
  1080. return t.show (true);
  1081. }
  1082. }
  1083. }
  1084.  
  1085. function getClientCoords(e){
  1086. if (e==null)
  1087. return {x:null, y:null, width:null, height:null};
  1088. var ret = {x:0, y:0, width:e.clientWidth, height:e.clientHeight};
  1089. while (e.offsetParent != null){
  1090. ret.x += e.offsetLeft;
  1091. ret.y += e.offsetTop;
  1092. e = e.offsetParent;
  1093. }
  1094. return ret;
  1095. }
  1096.  
  1097. function eventHideShow(){
  1098. if(mainPop.toggleHide(mainPop)){
  1099. tabManager.showTab();
  1100. Options.kbWinIsOpen = true;
  1101. } else {
  1102. tabManager.hideTab();
  1103. Options.kbWinIsOpen = false;
  1104. }
  1105. }
  1106.  
  1107. function createButton(label,id){
  1108. var a=document.createElement('a');
  1109. a.className='button20';
  1110. a.id = id;
  1111. a.innerHTML='<span style="color: #ff6">'+ label +'</span>';
  1112. return a;
  1113. }
  1114.  
  1115. function AddMainTabLink(text, eventListener, mouseListener){
  1116. var a = createButton(text,'botbutton');
  1117. a.className='tab';
  1118. var tabs=document.getElementById('main_engagement_tabs');
  1119. if(!tabs){
  1120. tabs=document.getElementById('topnav_msg');
  1121. if(tabs)
  1122. tabs=tabs.parentNode;
  1123. }
  1124. if(tabs){
  1125. var e = tabs.parentNode;
  1126. var gmTabs = null;
  1127. for(var i=0; i<e.childNodes.length; i++){
  1128. var ee = e.childNodes[i];
  1129. if (ee.tagName && ee.tagName=='div' && ee.className=='tabs_engagement' && ee.id!='main_engagement_tabs'){
  1130. gmTabs = ee;
  1131. break;
  1132. }
  1133. }
  1134. if(gmTabs == null){
  1135. gmTabs = document.createElement('div');
  1136. gmTabs.className='tabs_engagement';
  1137. tabs.parentNode.insertBefore(gmTabs, tabs);
  1138. gmTabs.style.whiteSpace='nowrap';
  1139. gmTabs.style.width='735px';
  1140. gmTabs.lang = 'en_KB';
  1141. }
  1142. gmTabs.style.height='0%';
  1143. gmTabs.style.overflow='auto';
  1144. gmTabs.appendChild(a);
  1145. a.addEventListener('click',eventListener, false);
  1146. if(mouseListener != null)
  1147. a.addEventListener('mousedown',mouseListener, true);
  1148. return a;
  1149. }
  1150. return null;
  1151. }
  1152.  
  1153. Tabs.Website = {
  1154. tabOrder: 2,
  1155. tabDisabled: false,
  1156. tabLabel: 'Website',
  1157. myDiv: null,
  1158. timer: null,
  1159. init: function(div){
  1160. var t = Tabs.Website;
  1161. t.myDiv = div;
  1162. var str = '<div class="row">';
  1163. str = str + ' <div class="large-12 columns end text-center">';
  1164. str = str + ' <button id="'+kb.elemPrefix+'-website-visit"><span>Visit Site</span></button><br />';
  1165. str = str + ' <button id="'+kb.elemPrefix+'-website-updateinfo"><span>Send Info</span></button>';
  1166. str = str + ' </div>';
  1167. str = str + '</div>';
  1168. t.myDiv.innerHTML = str;
  1169. $('#'+kb.elemPrefix+'-website-updateinfo').click(function(){
  1170. kb.sendInfo(1);
  1171. });
  1172. $('#'+kb.elemPrefix+'-website-visit').click(function(){
  1173. GM_openInTab(kb.site);
  1174. });
  1175. },
  1176. hide: function(){ // called whenever the main window is hidden, or another tab is selected
  1177. var t = Tabs.Website;
  1178. },
  1179. show: function(){ // called whenever this tab is shown
  1180. var t = Tabs.Website;
  1181. },
  1182. };
  1183.  
  1184. Tabs.Log = {
  1185. tabOrder: 3,
  1186. tabDisabled: false,
  1187. tabLabel: 'Log',
  1188. myDiv: null,
  1189. timer: null,
  1190. init: function(div){
  1191. var t = Tabs.Log;
  1192. t.myDiv = div;
  1193. var str = '';
  1194. str = str + '<div class="row">';
  1195. str = str + ' <div class="large-12 columns">';
  1196. str = str + ' <pre id="'+kb.elemPrefix+'-log-result">Log text goes here</pre>';
  1197. str = str + ' </div>';
  1198. str = str + '</div>';
  1199. t.myDiv.innerHTML = str;
  1200. },
  1201. hide: function(){ // called whenever the main window is hidden, or another tab is selected
  1202. var t = Tabs.Log;
  1203. },
  1204. show: function(){ // called whenever this tab is shown
  1205. var t = Tabs.Log;
  1206. },
  1207. };
  1208.  
  1209. Tabs.Debug = {
  1210. tabOrder: 4,
  1211. tabDisabled: false,
  1212. tabLabel: 'Debug',
  1213. myDiv: null,
  1214. timer: null,
  1215. init: function(div){
  1216. var t = Tabs.Debug;
  1217. t.myDiv = div;
  1218. var str = '';
  1219. str = str + '<div class="row">';
  1220. str = str + ' <div class="large-12 columns">';
  1221. str = str + ' <pre id="'+kb.elemPrefix+'-debug-result">Debug text goes here</pre>';
  1222. str = str + ' </div>';
  1223. str = str + '</div>';
  1224. t.myDiv.innerHTML = str;
  1225. },
  1226. hide: function(){ // called whenever the main window is hidden, or another tab is selected
  1227. var t = Tabs.Debug;
  1228. },
  1229. show: function(){ // called whenever this tab is shown
  1230. var t = Tabs.debug;
  1231. },
  1232. };
  1233.  
  1234. Tabs.Mod = {
  1235. tabOrder: 1,
  1236. tabDisabled: false,
  1237. tabLabel: 'Mod',
  1238. myDiv: null,
  1239. timer: null,
  1240. init: function(div){ // called once, upon script startup
  1241. var t = Tabs.Mod;
  1242. t.myDiv = div;
  1243. var str = '';
  1244. str = str + '<div class="row">';
  1245. str = str + ' <div class="large-12 columns text-center">';
  1246. str = str + ' <button id="'+kb.elemPrefix+'-main-update">Update</button>&nbsp;v<span id="'+kb.elemPrefix+'-main-version">'+kb.scriptVer+'</span><br />';
  1247. str = str + ' <button id="'+kb.elemPrefix+'-main-debug"><span id="'+kb.elemPrefix+'-debug-toggle">Debug: '+((Options.debug) ? 'On' : 'Off')+'</span></button>';
  1248. str = str + ' </div>';
  1249. str = str + '</div>';
  1250. t.myDiv.innerHTML = str;
  1251. $('#'+kb.elemPrefix+'-main-update').click(function(){
  1252. AutoUpdater.check(false);
  1253. });
  1254. $('#'+kb.elemPrefix+'-main-debug').click(function(){
  1255. var debug = (Options.debug) ? false : true;
  1256. $('#'+kb.elemPrefix+'-debug-toggle').html('Debug: '+((debug) ? 'On' : 'Off'));
  1257. Options.debug = debug;
  1258. var debugKey = kb.storagePrefix+'_debug';
  1259. kb.setValue(debugKey, debug);
  1260. });
  1261. },
  1262. hide: function(){ // called whenever the main window is hidden, or another tab is selected
  1263. var t = Tabs.Mod;
  1264. },
  1265. show: function(){ // called whenever this tab is shown
  1266. var t = Tabs.Mod;
  1267. },
  1268. };
  1269.  
  1270. kb.elemPrefix = 'kb-'+kb.generateRandomNumber(0,65535);
  1271.  
  1272. if(uW.AjaxCall){
  1273. uW.AjaxCall.unwatch("gPostRequest");
  1274. uW.AjaxCall.gPostRequest = aj2;
  1275. }
  1276.  
  1277. if(kb.currentUrl.match('src/main_src.php')){
  1278. kb.init();
  1279. }else if(kb.currentUrl.match('apps.facebook.com/kingdomsofcamelot/')){
  1280. kb.init();
  1281. }else if(kb.currentUrl.match('www.kabam.com/games/kingdoms-of-camelot/play')){
  1282. kb.init();
  1283. }else if(kb.currentUrl.match('www.kocbyte.com')){
  1284. kb.initSite();
  1285. }