KoCByte

A Kingdoms of Camelot Tracker (Kocmon replacement)

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