Trainer chicken

Da CHicken Trainer

  1. // ==UserScript==
  2. // @name Trainer chicken
  3. // @namespace 44105a1740ef7cd0f25276868a623226
  4. // @author ~Patrick*3
  5. // @description Da CHicken Trainer
  6. // @homepage http://userscripts.org/scripts/show/156315
  7. // @include http://*.pokemon-vortex.com/map.php?map=*
  8. // @include http://*.pokemon-vortex.com/wildbattle.php*
  9. // @include http://*.pokemon-vortex.com/battle_select.php?type=member*
  10. // @include http://*.pokemon-vortex.com/battle.php*
  11. // @exclude http://*.pokemon-vortex.com/adv.php*
  12. // @require http://code.jquery.com/jquery-1.8.3.js
  13. // @run-at document-end
  14. // @grant GM_getValue
  15. // @grant GM_setValue
  16. // @version !3!
  17. // @licence Private Domain!
  18. // ==/UserScript==
  19. /*
  20. */
  21. (function() {
  22. //buttons some times show up in the ads located in an iframe
  23. //dont run in a frame
  24. if(unsafeWindow.self!=unsafeWindow.top) return(false);
  25. var dlh=document.location.href.toString();
  26. if(dlh.indexOf('battle.php?sidequest=')!=-1) return(false);
  27. var NewMapAfterBattles=50;
  28. var tbattles=GM_getValue('tbattles',0)
  29. var StartTime=pageLoad=Date.now();
  30. var battleId=133733;
  31. var PokemonList=[];
  32. var win;
  33. //how long to wait for the loading image before checking again for it
  34. //you can make it 100 but you will beat up the server and once they notice the server take a beating i guarantee this will stop working!
  35. //they already have a warning for battling to much to fast, the 'dont be greedy' warning. TAKE NOTICE!
  36. var playerBattleTimeout=0;
  37. var pm=GM_getValue('pm_list',0);
  38. var timeOuts={
  39. battleButton:0,
  40. moveAround:0,
  41. session:0,
  42. battleLoop:0
  43. }
  44. if(dlh.indexOf('battle_select.php?type=member')!=-1){
  45. setTimeout(bMember,0);
  46. return(false);
  47. }
  48. if(dlh.indexOf('/battle.php?bid=')!=-1){
  49. GM_setValue('new_session',true)
  50. if(pm>5) pm=0;
  51. GM_setValue('pm_list',pm+1);
  52. setTimeout(function(){
  53. battlePlayer();
  54. },0);
  55. return(false);
  56. }
  57. function bMember(){
  58. setTimeout(function(){
  59. document.location.href='http://'+getServerName()+'.pokemon-vortex.com/battle.php?bid='+battleId;
  60. },1000)
  61. }
  62. function battlePlayer(){
  63. clearTimeout(timeOuts.battleLoop);
  64. var iloading=isLoading();
  65. if(iloading==true){
  66. timeOuts.battleLoop=setTimeout(battlePlayer,playerBattleTimeout);//rndFrom(2000,3000));
  67. return(false);
  68. }
  69. if($('div#ajax > form > h3:eq(0)').html()=='Select your next Pok'+String.fromCharCode(233)+'mon to battle:'){
  70. //the first screen
  71. bPlayer();//since it's an ajax call, set the loop to start again
  72. var pm=GM_getValue('pm_list',0);
  73. if(pm>5) pm=0;
  74. pm=0;// set to which of your 6 pokemon to use (0-5)
  75. //GM_setValue('pm_list',pm+1); //if you uncomment, it will use one new pokemon for each battle.
  76. $('td#y_p > table > tbody > tr > td > input')[pm].checked=true;
  77. $('div#ajax > form').submit();
  78. return(false);
  79. }
  80. try{
  81. if($('div#ajax > form:eq(1) > h2').html().toString().toLowerCase().indexOf('select an attack')!=-1){
  82. //second screen and if your pokemon did not win with the first attack
  83. bPlayer();
  84. $('#attack2').attr('checked', true);
  85. //$('#attack'+rndFrom(1,4)).attr('checked', true);
  86. $('div#ajax > form:eq(1)').submit();
  87. return(false);
  88. }
  89. }catch(e){}
  90. if($('div#ajax > form > h2').html().toString().toLowerCase().indexOf('you won the battle')!=-1){
  91. //you won, battle is over
  92. setTimeout(function(){
  93. GM_log('PageLoadElapsedTime = '+(Date.now()-pageLoad) +' @ '+ctime(Date.now()))
  94. GM_setValue('new_session',true)
  95. document.location.reload();
  96. //document.location.href='http://sigma.pokemon-vortex.com/battle_select.php?type=member'
  97. },5000)
  98. return(false);
  99. }
  100. if($('div#ajax > form > h2').html().toString().toLowerCase().indexOf('you lost the battle')!=-1){
  101. //you lost, battle is over
  102. return(false);
  103. }
  104. bPlayer();
  105. }
  106. function bPlayer(){
  107. //new_session is watched by the parent window. if this page hangs,
  108. //the parent window will never see it and attempt to reload the child window.
  109. GM_setValue('new_session',true)
  110. timeOuts.battleLoop=setTimeout(battlePlayer,playerBattleTimeout);
  111. }
  112. if(window.name!='pbattle') {
  113. //because it has a name, they can check if a name exist, and if so, they could just log you out.
  114. //switch to just battle on the map.
  115. //win=window.open('http://'+getServerName()+'.pokemon-vortex.com/map.php?map='+rndFrom(1,25),'pbattle');
  116. win=window.open('http://'+getServerName()+'.pokemon-vortex.com/battle.php?bid='+battleId,'pbattle');
  117. $('div#scrollContent').html('<b>Leave this window open, <br>it administrates the session timeout and window loading errors of the new window</b>'.toUpperCase());
  118. windowsessionTimeout();
  119. return(false);
  120. }
  121. function windowsessionTimeout(){
  122. clearTimeout(timeOuts.session);
  123. if(GM_getValue('new_session',false)==true){
  124. GM_setValue('new_session',false)
  125. StartTime=Date.now();
  126. }
  127. GM_log('Session ElapsedTime='+(Date.now()-StartTime))
  128. var windlh=win.document.location.href.toString();
  129. if(parseFloat(StartTime+50000)<Date.now()) {
  130. GM_setValue('new_session',false);
  131. StartTime=Date.now();
  132. if(windlh.indexOf('/battle.php?bid=')!=-1){
  133. win.location.href='http://'+getServerName()+'.pokemon-vortex.com/battle.php?bid='+battleID;
  134. }else{
  135. win.location.href='http://'+getServerName()+'.pokemon-vortex.com/map.php?map='+rndFrom(1,25);
  136. }
  137. }
  138. timeOuts.session=setTimeout(windowsessionTimeout,0);
  139. }
  140. GM_setValue('new_session',true)
  141. if(tbattles>NewMapAfterBattles){
  142. GM_setValue('tbattles',0)
  143. newMap();
  144. return(false);
  145. }
  146. $(window).unload(function() {
  147. clearTimeout(timeOuts.session);
  148. clearTimeout(timeOuts.battleButton)
  149. clearTimeout(timeOuts.moveAround);
  150. clearTimeout(timeOuts.battleLoop);
  151. });
  152. var direction={
  153. moves:0,
  154. randDir:0, //0=up 1=upright 2=right 3=downright 4=down 5=downleft 6=left 7=leftup
  155. up:function(){
  156. if(!$("img[src*='arrowupno.gif']").length > 0){
  157. $("img[src*='arrowup.gif']").click();
  158. return(true);
  159. }
  160. direction.setDir();
  161. return(false);
  162. },
  163. upright:function(){
  164. if(!$("img[src*='arrowrightupno.gif']").length > 0){
  165. $("img[src*='arrowrightup.gif']").click();
  166. return(true);
  167. }
  168. direction.setDir();
  169. return(false);
  170. },
  171. right:function(){
  172. if(!$("img[src*='arrowrightno.gif']").length > 0){
  173. $("img[src*='arrowright.gif']").click();
  174. return(true);
  175. }
  176. direction.setDir();
  177. return(false);
  178. },
  179. downright:function(){
  180. if(!$("img[src*='arrowrightdownno.gif']").length > 0){
  181. $("img[src*='arrowrightdown.gif']").click();
  182. return(true);
  183. }
  184. direction.setDir();
  185. return(false);
  186. },
  187. down:function(){
  188. if(!$("img[src*='arrowdownno.gif']").length > 0){
  189. $("img[src*='arrowdown.gif']").click();
  190. return(true);
  191. }
  192. direction.setDir();
  193. return(false);
  194. },
  195. downleft:function(){
  196. if(!$("img[src*='arrowleftdownno.gif']").length > 0){
  197. $("img[src*='arrowleftdown.gif']").click();
  198. return(true);
  199. }
  200. direction.setDir();
  201. return(false);
  202. },
  203. left:function(){
  204. if(!$("img[src*='arrowleftno.gif']").length > 0){
  205. $("img[src*='arrowleft.gif']").click();
  206. return(true);
  207. }
  208. direction.setDir();
  209. return(false);
  210. },
  211. leftup:function(){
  212. if(!$("img[src*='arrowleftupno.gif']").length > 0){
  213. $("img[src*='arrowleftup.gif']").click();
  214. return(true);
  215. }
  216. direction.setDir();
  217. return(false);
  218. },
  219. setDir:function(){
  220. chooseDirection();
  221. moveMe();
  222. }
  223. }
  224. direction.setDir();
  225. createButtons();
  226. isWildBattle(true);
  227. function chooseDirection(){
  228. var t=0;
  229. var up=!$("img[src*='arrowupno.gif']").length;
  230. var upright=!$("img[src*='arrowrightupno.gif']").length;
  231. var right=!$("img[src*='arrowrightno.gif']").length;
  232. var downright=!$("img[src*='arrowrightdownno.gif']").length;
  233. var down=!$("img[src*='arrowdownno.gif']").length;
  234. var downleft=!$("img[src*='arrowleftdownno.gif']").length;
  235. var left=!$("img[src*='arrowleftno.gif']").length;
  236. var leftup=!$("img[src*='arrowleftupno.gif']").length;
  237. var ad= new Array();
  238. if(up) {ad[t]=0;t++;}
  239. if(upright) {ad[t]=1;t++;}
  240. if(right) {ad[t]=2;t++;}
  241. if(downright) {ad[t]=3;t++;}
  242. if(down) {ad[t]=4;t++;}
  243. if(downleft) {ad[t]=5;t++;}
  244. if(left) {ad[t]=6;t++;}
  245. if(leftup) {ad[t]=7;t++;}
  246. direction.randDir=ad[rndFrom(0,ad.length-1)];//choose from available directions only
  247. GM_log('Directions:'+JSON.stringify(ad)+'- Dir set:'+direction.randDir);
  248. }
  249. function doBattleLoop(){
  250. clearTimeout(timeOuts.battleLoop);
  251. var iloading=isLoading();
  252. if(iloading==true){
  253. timeOuts.battleLoop=setTimeout(doBattleLoop,10000);//rndFrom(2000,3000));
  254. return(false);
  255. }
  256. if($('div#ajax > form#battleForm > div.errorMsg').length){
  257. if($('div#ajax > form > div.errorMsg').html()!=undefined){
  258. if($('div#ajax > form > div.errorMsg').html().toString().indexOf('It seems as though you have already completed this battle')!=-1){
  259. newMap();
  260. return(false);
  261. }
  262. }
  263. }
  264. if($('div#ajax > div.errorMsg').length){
  265. if($('div#ajax > div.errorMsg').html()!=undefined){
  266. if($('div#ajax > div.errorMsg').html().toString().indexOf('It seems as though you have already completed this battle')!=-1){
  267. newMap();
  268. return(false);
  269. }
  270. }
  271. }
  272. if($('div#ajax > form#battleForm > h2').html()=='Your Pok'+String.fromCharCode(233)+'mon Team:'.toString()){
  273. setTimeout(function(){
  274. $("form#battleForm").submit();
  275. isWildBattle();
  276. },150)
  277. return(false);
  278. }
  279. if($('div#ajax > form#battleForm > h2').html()=='Choose an attack'){
  280. $('#attack'+rndFrom(1,4)).attr('checked', true);
  281. //$('#attack4').attr('checked', true);
  282. isWildBattle();
  283. $("form#battleForm").submit();
  284. return(false);
  285. }
  286. if($('div#ajax > form#battleForm > h2').html()=='Attack results'){
  287. isWildBattle();
  288. $("form#battleForm").submit();
  289. return(false);
  290. }
  291. if($('div#ajax > p:eq(1) > a:eq(0)').html()=='Return to the Map'){
  292. clearTimeout(timeOuts.session);
  293. setTimeout(function(){
  294. GM_setValue('new_session',true)
  295. $('div#ajax > p:eq(1) > a:eq(0)').get(0).click();
  296. },6000)
  297. return(false);
  298. }
  299. //when the 'You have already completed a battle within the last 10 seconds. This is in effect to prevent cheating of any kind.' error shows up
  300. if($('div#ajax > p:eq(0) > a:eq(0)').html()=='Return to the Map'){
  301. clearTimeout(timeOuts.session);
  302. setTimeout(function(){
  303. GM_setValue('new_session',true)
  304. $('div#ajax > p:eq(0) > a:eq(0)').get(0).click();
  305. },6000)
  306. return(false);
  307. }
  308. }
  309. function isLoading(){
  310. var ml=$('div#mapLoading').length; //map
  311. var bl=$('div#loading').length; //battle
  312. if(bl!=0) {
  313. bl=$('div#loading').css('visibility');
  314. if(bl=='hidden'){
  315. return(false);
  316. }else{
  317. return(true);
  318. }
  319. }
  320. if(ml!=0) {
  321. ml=$('div#mapLoading').css('visibility');
  322. if(ml=='hidden'){
  323. return(false);
  324. }else{
  325. return(true);
  326. }
  327. }
  328. return(true);
  329. }
  330. function isWildBattle(){
  331. //checks for wildbattle.php
  332. var enabled=GM_getValue('battle_enabled',false);
  333. if(enabled){
  334. if(dlh.indexOf('wildbattle')!=-1){
  335. GM_setValue('new_session',true)
  336. timeOuts.battleLoop=setTimeout(doBattleLoop,50);
  337. }
  338. }
  339. }
  340. function moveMe(){
  341. clearTimeout(timeOuts.moveAround);
  342. var en=GM_getValue('move_enabled',true)
  343. if(en==false) {
  344. clearTimeout(timeOuts.session);
  345. return(false);
  346. }
  347. var t=250;
  348. var iloading=isLoading;
  349. if(iloading==true){
  350. timeOuts.moveAround=setTimeout(moveMe,t);
  351. return(false);
  352. }
  353. direction.moves++;
  354. var lm=direction.randDir;
  355. doMove();
  356. if(lm!=direction.randDir) doMove();
  357. if(direction.moves>100) {
  358. //it has not found any pokemon to battle
  359. clearTimeout(timeOuts.session);
  360. clearTimeout(timeOuts.battleButton);
  361. newMap();
  362. return(false);
  363. }
  364. timeOuts.battleButton=setTimeout(findBattleBTN,t);
  365. }
  366. function findBattleBTN(){
  367. if(dlh.indexOf('wildbattle')!=-1) return(false);
  368. var t=250;
  369. clearTimeout(timeOuts.battleButton);
  370. clearTimeout(timeOuts.moveAround);
  371. var iloading=isLoading();
  372. if(iloading==true){
  373. timeOuts.battleButton=setTimeout(findBattleBTN,t);
  374. return(false);
  375. }
  376. if($('div#pkmnappearomega > form > p > input:eq(1)').length){
  377. //clearTimeout(timeOuts.session);
  378. var h=$('div#pkmnappearomega > form').html().toLowerCase();
  379. if((h.indexOf('unown')==-1)){
  380. savePokemon();
  381. var h=$('div#alert').html();
  382. if(h.length>2) {
  383. newMap();
  384. return(false);
  385. }
  386. setTimeout(function(){
  387. GM_setValue('new_session',true)
  388. $('div#pkmnappearomega > form')[0].submit();
  389. },500);
  390. //timeOuts.moveAround=setTimeout(moveMe,175);
  391. return(false);
  392. }else{
  393. timeOuts.moveAround=setTimeout(moveMe,t);
  394. }
  395. }else{
  396. timeOuts.moveAround=setTimeout(moveMe,t);
  397. }
  398. }
  399. function savePokemon(){
  400. //dont save just return;
  401. return;
  402. var tbattles=GM_getValue('tbattles',0);
  403. tbattles++;
  404. GM_setValue('tbattles',tbattles);
  405. var image=$('div#pkmnappearomega > form > center > img').attr('src');
  406. var pokemon;
  407. var st='';
  408. if($('div#pkmnappearomega > form > center > p > img').length){
  409. //when you own it, grab whats in the strong tag
  410. st=' > strong'
  411. }
  412. pokemon=$('div#pkmnappearomega > form > center > p ' +st).html().replace(' appeared','').toString().trim();
  413. var map=dlh.split('=');
  414. map=map[1];
  415. var p=new Object();
  416. p.i=image.replace('http://static.pokemon-vortex.com/images/pokemon/','')
  417. p.n=pokemon.trim();
  418. p.m=map;
  419. p.c=0;
  420. var ls=GM_getValue('plist','[]')
  421. try{
  422. PokemonList=JSON.parse(ls);
  423. }catch(e){}
  424. if(!pexist(pokemon.trim())) {
  425. PokemonList.push(p);
  426. GM_setValue('plist',JSON.stringify(PokemonList));
  427. }
  428. GM_log(ctime(Date.now()) + ' = ' +PokemonList.length);
  429. }
  430. function doMove(){
  431. if(direction.randDir==0) direction.up();
  432. if(direction.randDir==1) direction.upright();
  433. if(direction.randDir==2) direction.right();
  434. if(direction.randDir==3) direction.downright();
  435. if(direction.randDir==4) direction.down();
  436. if(direction.randDir==5) direction.downleft();
  437. if(direction.randDir==6) direction.left();
  438. if(direction.randDir==7) direction.leftup();
  439. }
  440. function createButtons(){
  441. var enabled=GM_getValue('move_enabled',false);
  442. var btn=document.createElement('input');
  443. btn.value='Auto-move Enabled';
  444. btn.id='DAFDS';
  445. btn.type='button';
  446. btn.style.cssText='position:fixed;top:5px;left:5px;';
  447. if(!enabled) btn.value='Auto-move Disabled';
  448. btn.addEventListener('click', function (e) {
  449. var isenabled=GM_getValue('move_enabled',false);
  450. if(!isenabled){
  451. doEnableMove();
  452. }else{
  453. doDisableMove();
  454. }
  455. },false);
  456. document.body.appendChild(btn);
  457. if(enabled)doEnableMove();
  458. enabled=GM_getValue('battle_enabled',false)
  459. btn=document.createElement('input');
  460. btn.value='Auto-battle Enabled'
  461. btn.id='DDDDERE'
  462. btn.type='button';
  463. btn.style.cssText='position:fixed;top:35px;left:5px;';
  464. if(!enabled) btn.value='Auto-battle Disabled';
  465. btn.addEventListener('click', function (e) {
  466. var isenabled=GM_getValue('battle_enabled',false);
  467. if(!isenabled){
  468. doEnableBattle();
  469. }else{
  470. doDisableBattle();
  471. }
  472. },false);
  473. document.body.appendChild(btn);
  474. }
  475. function sessionTimeout(){
  476. clearTimeout(timeOuts.battleButton);
  477. clearTimeout(timeOuts.moveAround);
  478. clearTimeout(timeOuts.session);
  479. if(dlh.indexOf('wildbattle.php')!=-1) return(false);
  480. timeOuts.session=setTimeout(sessionTimeout,0);
  481. if(dlh.indexOf('wildbattle.php')==-1) timeOuts.battleButton=setTimeout(findBattleBTN,75);
  482. }
  483. function doDisableBattle(){
  484. GM_setValue('battle_enabled',false);
  485. $('#DDDDERE').attr('value','Auto-battle Disabled')
  486. clearTimeout(timeOuts.battleLoop);
  487. }
  488. function doEnableBattle(){
  489. GM_setValue('battle_enabled',true);
  490. $('#DDDDERE').attr('value','Auto-battle Enabled')
  491. if(dlh.indexOf('wildbattle')!=-1){
  492. timeOuts.battleLoop=setTimeout(doBattleLoop,rndFrom(1000,1250))
  493. }
  494. }
  495. function doDisableMove(){
  496. GM_setValue('move_enabled',false);
  497. clearTimeout(timeOuts.battleButton);
  498. clearTimeout(timeOuts.moveAround);
  499. clearTimeout(timeOuts.session);
  500. $('#DAFDS').attr('value','Auto-move Disabled')
  501. }
  502. function doEnableMove(){
  503. StartTime=Date.now()
  504. //sessionTimeout();
  505. GM_setValue('move_enabled',true);
  506. $('#DAFDS').attr('value','Auto-move Enabled')
  507. if(dlh.indexOf('wildbattle.php')==-1) timeOuts.battleButton=setTimeout(findBattleBTN,75);
  508. }
  509. function rndFrom(from,to){
  510. return Math.floor(Math.random()*(to-from+1)+from);
  511. }
  512. function newMap(){
  513. var map=dlh.split('=');
  514. map=map[1];
  515. var nmap=rndFrom(1,25)
  516. while (nmap==map) {
  517. nmap=rndFrom(1,25)
  518. }
  519. setTimeout(function(){
  520. document.location.href='http://'+getServerName()+'.pokemon-vortex.com/map.php?map='+nmap;
  521. },2000);
  522. }
  523. function ctime(d) {
  524. if (d==0) return ('Not Set');
  525. var time=new Date(d);
  526. var hr=time.getHours();
  527. var min=time.getMinutes();
  528. var sec=time.getSeconds();
  529. var mon=time.getMonth()+1;
  530. var day=time.getDate();
  531. var msec=time.getMilliseconds();
  532. var ampm=' PM ';
  533. if (hr < 12) {
  534. ampm=' AM ';
  535. }
  536. if (hr > 12) {
  537. hr -=12;
  538. }
  539. if (hr==0) {
  540. hr=12;
  541. }
  542. if (hr < 10) {
  543. hr=' '+hr;
  544. }
  545. if (min < 10) {
  546. min='0'+min;
  547. }
  548. if (sec < 10) {
  549. sec='0'+sec;
  550. }
  551. var ct=mon+'/'+day+' '+hr+':'+min+':'+sec+ampm;
  552. if (ct.indexOf('NaN')!=-1) ct=d;
  553. return (ct)
  554. }
  555. function getServerName(){
  556. var urlParms=document.location.href.toString().split('.');
  557. var server=urlParms[0].replace('http://','');
  558. return(server);
  559. }
  560. function pexist(n){
  561. if(PokemonList==null) return(false);
  562. for(var i=0;i<PokemonList.length;i++){
  563. if(PokemonList[i].n==n){
  564. GM_log("Pokemon - " +n+ " Exists!")
  565. return(true);
  566. }
  567. }
  568. GM_log("Pokemon - " +n+ " Does Not Exists!")
  569. return(false);
  570. }
  571. function iwindowOpen(){
  572. return;
  573. var win=window.open('http://'+getServerName()+'.pokemon-vortex.com/map.php?map='+rndFrom(1,25));
  574. $('div#scrollContent').html('<b>Leave this window open, <br>it administrates the session timeout and window loading errors of the new window</b>'.toUpperCase());
  575. windowsessionTimeout();
  576. return(false);
  577. }
  578. })();