KoCByte

A Kingdoms of Camelot Tracker (Kocmon replacement)

当前为 2016-06-23 提交的版本,查看 最新版本

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