Guest User

Evidence of script used for macro'ing

a guest
Nov 4th, 2018
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 8.07 KB | None | 0 0
  1. // ==UserScript==
  2. // @name         Fuck Da Man lulz
  3. // @namespace    https://tampermonkey.net/
  4. // @version      2.0
  5. // @match        https://pokemoncreed.net/battle.php*
  6. // @match        https://pokemoncreed.net/profile.php*
  7. // @grant        none
  8. // @require      http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js
  9. // ==/UserScript==
  10.  
  11. var API_KEY = '6719dbc1561263aae9c42965a78c8b37';
  12. var attackFunctionStr =
  13.   'function attack(){\n' +
  14.   'document.getElementById(\'loading\').style.display = "";\n' +
  15.   'document.getElementById(\'moves\').style.display = "none";\n' +
  16.   'document.getElementById(\'moves2\').style.display = "none";\n' +
  17.   'return true;\n' +
  18.   '}';
  19.  
  20. function battle() {
  21.   if (isError()) {
  22.     console.error('Error occurred');
  23.     confirm('Error occurred');
  24.   } else if (isFrozen()) {
  25.     console.error('Your account has been frozen');
  26.     confirm('Your account has been frozen');
  27.   } else if (isCaptchaActive()) {
  28.     solveCaptcha();
  29.   } else if (isResendAction()) {
  30.     resendAction();
  31.   } else if (hasBattleEnded()) {
  32.     restartBattle();
  33.   } else if (canContinueBattle()) {
  34.     continueBattle();
  35.   } else if (!window.attack) {
  36.     console.error('window.attack not present');
  37.     confirm('window.attack not present');
  38.     return;
  39.   } else if (window.attack.toString() !== attackFunctionStr) {
  40.     console.error('window.attack has been changed', window.attack, window.attack.toString());
  41.     confirm('window.attack has been changed');
  42.     return;
  43.   } else {
  44.     var $yourRoster = $('tr td[style="vertical-align: top; text-align: center; padding: 3px"]:nth-child(1)');
  45.     var yourRosterLinks = $yourRoster.find('a').toArray();
  46.     var yourSlotHP6 = $yourRoster.find('div[style*="width: 100px; border: 1px solid red; float: right; text-align: left"] img[src="hp.gif"]').width();
  47.     var yourPokeIsFainted = !!$('.battlefast th[width="50%"]:nth-child(1) img[src*="img/types/fnt.png"]')[0];
  48.     var enemyPokeIsPoisoned = !!$('.battlefast th[width="50%"]:nth-child(2) img[src*="img/types/psn.png"]')[0];
  49.     var enemySlotHP1 = $($('tr td[style="vertical-align: top; text-align: center; padding: 3px"]:nth-child(2)').find('div[style*="width: 100px; border: 1px solid red; float: right; text-align: left"] img[src="hp.gif"]').toArray()[0]).width();
  50.  
  51.     if (!enemyPokeIsPoisoned) {
  52.       if (yourSlotHP6 !== 100 || yourPokeIsFainted) {
  53.         console.log('Enemy is not poisoned and slot 6 has taken damage. Restart battle.');
  54.         restartBattle();
  55.       } else {
  56.         console.log('Enemy is not poisoned. Trying to use Toxic.');
  57.         if (getMove('Toxic')) {
  58.           useMove(getMove('Toxic'));
  59.         } else {
  60.           if (yourRosterLinks[4]) {
  61.             console.log('Pokemon does not have Toxic. Switching to slot 6.');
  62.             yourRosterLinks[4].click();
  63.           } else {
  64.             console.log('Pokemon does not have Toxic and slot 6 is fainted. Using a random move.');
  65.             useRandomMove();
  66.           }
  67.         }
  68.       }
  69.     } else if (!yourPokeIsFainted) {
  70.       if (!getMove('Fly')) {
  71.         console.log('Pokemon does not have Fly. Using a random move.');
  72.         useRandomMove();
  73.       } else if (enemySlotHP1 <= 10) {
  74.         console.log('Enemy Pokemon HP is at 10% or less. Switching to slot 1.');
  75.         yourRosterLinks[0].click();
  76.       } else {
  77.         useMove(getMove('Fly'));
  78.       }
  79.     } else {
  80.       console.log('Enemy is poisoned and your Pokemon has fainted. Switch to the next available Pokemon.');
  81.       $yourRoster.find('a').toArray().reverse()[0].click();
  82.     }
  83.   }
  84. }
  85.  
  86. function canContinueBattle() {
  87.   return !!getContinueBattleLink();
  88. }
  89.  
  90. function continueBattle() {
  91.   console.log('continue battle');
  92.   getContinueBattleLink().click();
  93. }
  94.  
  95. function getContinueBattleLink() {
  96.   return $('a:contains("Continue Battle")')[0];
  97. }
  98.  
  99. function hasBattleEnded() {
  100.   return !$('tr td[style="vertical-align: top; text-align: center; padding: 3px"]:nth-child(1)').find('div[style*="width: 100px; border: 1px solid red; float: right; text-align: left"] img[src="hp.gif"]').toArray().map(img => $(img).width()).find(w => w) || $('.battlefast td.bord:visible[colspan=3][style="text-align: center"]').text().includes("Foe Mysterious Trainer's Mew fainted.");
  101. }
  102.  
  103. function restartBattle() {
  104.   $('button:visible:contains("Restart Battle")[onclick*="window.location"][class="button"]').click();
  105. }
  106.  
  107. function isError() {
  108.   return !!$('.title:contains("An Error Occured")')[0];
  109. }
  110.  
  111. function isFrozen() {
  112.   return !!$('.title:contains("Frozen")')[0];
  113. }
  114.  
  115. function isCaptchaActive() {
  116.   return !!$('.title:contains("Verification Code")')[0];
  117. }
  118.  
  119. function isResendAction() {
  120.   return !!$('input:visible[type=submit][name=restoreform][value="Resend Action"]')[0];
  121. }
  122.  
  123. function resendAction() {
  124.   $('input:visible[type=submit][name=restoreform][value="Resend Action"]').click();
  125. }
  126.  
  127. function getMove(moveName) {
  128.   var foundMove = false;
  129.  
  130.   $('tr[id*="moves"] form:visible[action*="battle.php?c="][method="POST"][onsubmit="return attack();"]').each(function () {
  131.     var $moveButton = $(this).find('input:visible[type=submit][value*="'+moveName+'"]');
  132.     if ($moveButton[0]) {
  133.       foundMove = $moveButton[0];
  134.       return;
  135.     }
  136.   });
  137.  
  138.   return foundMove;
  139. }
  140.  
  141. function useMove(moveButton) {
  142.   if (!moveButton) {
  143.     console.error('Move does not exist', moveButton);
  144.     confirm('Move does not exist');
  145.     return;
  146.   }
  147.  
  148.   console.log('Use move', moveButton);
  149.  
  150.   $(moveButton).click();
  151. }
  152.  
  153. function useRandomMove() {
  154.   var moveButton = $('tr form:visible[action*="battle.php?c="][method="POST"][onsubmit="return attack();"]:nth-child(1) input:visible[type=submit]')[Math.floor(Math.random() * 4) + 0];
  155.   useMove(moveButton);
  156. }
  157.  
  158. function solveCaptcha() {
  159.   console.log('Trying to solve captcha.');
  160.  
  161.   toDataURL(
  162.     $('.contentcontent .ranks tbody tr th img:visible[src*="captcha/captcha.php?t="]').attr('src'),
  163.     function(dataUrl) {
  164.       $.ajax('https://2captcha.com/in.php', {
  165.         method: 'POST',
  166.         dataType: 'json',
  167.         data: {
  168.           key: API_KEY,
  169.           method: 'base64',
  170.           json: 1,
  171.           header_acao: 1,
  172.           body: dataUrl
  173.         },
  174.         success: checkCaptcha
  175.       });
  176.     }
  177.   );
  178. }
  179.  
  180. function checkCaptcha(data) {
  181.   console.log('Requested a captcha be solved. Now we wait for it.', data);
  182.  
  183.   setTimeout(function () {
  184.     if (data.status != '1') {
  185.       console.error('Error solving captcha', data);
  186.       confirm('Error solving captcha, check console');
  187.       return;
  188.     }
  189.  
  190.     $.ajax('https://2captcha.com/res.php', {
  191.       method: 'GET',
  192.       dataType: 'json',
  193.       data: {
  194.         key: API_KEY,
  195.         action: 'get',
  196.         id: data.request,
  197.         json: 1,
  198.         header_acao: 1
  199.       },
  200.       success: function (data2) {
  201.         if (data2.status == '1') {
  202.           console.log('Captcha solved', data2);
  203.           $('.contentcontent .ranks input:visible[type=text][class=text][name=captcha]').val(data2.request);
  204.           $('.contentcontent .ranks input:visible[type=submit][name=button][value=Submit][class=button]').click();
  205.         } else {
  206.           console.warn('Captcha not solved yet, retrying', data2);
  207.           checkCaptcha(data);
  208.         }
  209.       }
  210.     });
  211.   }, Math.floor(Math.random() * 2500) + 5000);
  212. }
  213.  
  214. function toDataURL(src, callback, outputFormat) {
  215.   var img = new Image();
  216.   img.crossOrigin = 'Anonymous';
  217.   img.onload = function() {
  218.     var canvas = document.createElement('CANVAS');
  219.     var ctx = canvas.getContext('2d');
  220.     var dataURL;
  221.     canvas.height = this.naturalHeight;
  222.     canvas.width = this.naturalWidth;
  223.     ctx.drawImage(this, 0, 0);
  224.     dataURL = canvas.toDataURL(outputFormat);
  225.     callback(dataURL);
  226.   };
  227.   img.src = src;
  228.   if (img.complete || img.complete === undefined) {
  229.     img.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
  230.     img.src = src;
  231.   }
  232. }
  233.  
  234. var timeout = Math.floor(Math.random() * 650) + 1000;
  235.  
  236. if (Math.floor(Math.random() * 100) == 1) {
  237.   timeout = Math.floor(Math.random() * 5000) + 5000;
  238. }
  239.  
  240. setTimeout(() => {
  241.   battle();
  242. }, timeout);
Add Comment
Please, Sign In to add comment