Don't like ads? PRO users don't see any ads ;-)
Guest

maad

By: a guest on Jul 24th, 2012  |  syntax: LOL Code  |  size: 13.23 KB  |  hits: 34  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // ==UserScript==
  2. // @name           Pokemon Vortex
  3. // @namespace      http://flamescape.com/
  4. // @include        http://*.pokemonvortex.org/*
  5. // @exclude        http://*.pokemonvortex.org/adv.php*
  6. // @exclude        http://*.pokemonvortex.org/ads2.htm
  7. // ==/UserScript==
  8.  
  9. var legends = [
  10.         // Custom
  11.         //'Dark Golett',
  12.  
  13.         // Grass
  14.         'Shaymin (Sky)',
  15.         'Celebi',
  16.         'Latios',
  17.         'Latias',
  18.         'Rayquaza',
  19.         'Shaymin',
  20.         'Mew',
  21.         'Cresselia',
  22.         'Azelf',
  23.         'Uxie',
  24.         'Mesprit',
  25.         'Virizion',
  26.         'Genesect',
  27.  
  28.         // Grass (water)
  29.         'Manaphy',
  30.         'Phione',
  31.         'Suicune',
  32.         'Keldeo',
  33.        
  34.         // Ice
  35.         'Articuno',
  36.         'Suicune',
  37.         'Lugia',
  38.         'Regice',
  39.         'Kyurem',
  40.        
  41.         // Cave (land)
  42.         'Groudon',
  43.         'Arceus',
  44.         'Regigigas',
  45.         'Palkia',
  46.         'Dialga',
  47.         'Deoxys',
  48.         'Jirachi',
  49.         'Registeel',
  50.         'Regirock',
  51.         'Mewtwo',
  52.         'Cobalion',
  53.         'Terrakion',
  54.         'Virizion',
  55.         'Reshiram',
  56.         'Zekrom',
  57.         'Kyurem',
  58.         'Genesect',
  59.         'Tornadus',
  60.         'Landorus',
  61.  
  62.         // Cave (water)
  63.         'Kyogre',
  64.         'Lugia',
  65.         'Keldeo',
  66.         'Arceus(Water)',       
  67.         // Ghost
  68.         'Mew',
  69.         'Giratina',
  70.         'Rotom',
  71.         'Mesprit',
  72.         'Azelf',
  73.         'Uxie',
  74.         'Celebi',
  75.         'Darkrown',
  76.         'Darkrai',
  77.        
  78.         // Electric
  79.         'Zapdos',
  80.         'Raikou',
  81.         'Jirachi',
  82.         'Darkrai',
  83.         'Darkrown',
  84.         'Thundurus',
  85.         'Zekrom',
  86.         'Genesect',
  87.        
  88.         // Fire
  89.         'Heatran',
  90.         'Ho-oh',
  91.         'Moltres',
  92.         'Entei',
  93.         'Reshiram',
  94.         'Victini'
  95. ];
  96. var settings = {
  97.         'keys': ['autoBattle', 'findRare', 'findLegendary'],
  98.         'data': {},
  99.         'save': function() {
  100.                 for (var i = 0; i < this.keys.length; i++) {
  101.                         GM_setValue(this.keys[i], this.data[this.keys[i]]);
  102.                 }
  103.         },
  104.         'load': function() {
  105.                 for (var i = 0; i < this.keys.length; i++) {
  106.                         this.data[this.keys[i]] = GM_getValue(this.keys[i], false);
  107.                 }
  108.         }
  109. };
  110. var movPos = 0;
  111.  
  112. function moveAround() {
  113.         movPos += 10;
  114.         if (movPos > 360) {
  115.                 movPos = 0;
  116.         }
  117.        
  118.         var xpos = parseInt(Math.sin(movPos * (Math.PI / 180))*10);
  119.         var ypos = parseInt(Math.cos(movPos * (Math.PI / 180))*10);
  120.         unsafeWindow.PlayRequest(xpos + 14, ypos + 14, parseInt(Math.random()*8)+1);
  121. /*      var btnArrow = unsafeWindow.document.querySelector('#arrows img[onclick]')
  122.         if (btnArrow) {
  123.                 btnArrow.click();
  124.         } else {
  125.                 unsafeWindow.console.info('No buttons?');
  126.         }*/
  127. }
  128.  
  129. function findLegendary() {
  130.         var wildText = unsafeWindow.document.querySelector('#pkmnappearsigma');
  131.         if (!wildText) {
  132.                 moveAround();
  133.                 return;
  134.         }
  135.        
  136.         wildText = wildText.textContent.trim();
  137.         for (var i = 0; i < legends.length; i++) {
  138.                 if (wildText.match(legends[i])) {
  139.                         unsafeWindow.console.info('Legendary found ', wildText);
  140.                         return;
  141.                 }
  142.         }
  143.  
  144.         moveAround();  
  145. }
  146.  
  147. function findRare() {
  148.         var wildText = unsafeWindow.document.querySelector('#pkmnappearsigma');
  149.         if (!wildText) {
  150.                 moveAround();
  151.                 return;
  152.         }
  153.        
  154.         wildText = wildText.textContent.trim();
  155.         if (!wildText.match(/Wild (Dark|Shiny|Ancient|Mystic)/)) {
  156.                 moveAround();
  157.                 return;
  158.         }
  159.        
  160.         unsafeWindow.console.info('Rare found ', wildText);
  161. }
  162.  
  163. function autoBattle() {
  164.         try {
  165.                 var btnContinue = unsafeWindow.document.querySelector('[type="submit"][value="Continue"]');
  166.                 if (btnContinue) {
  167.                         btnContinue.click();
  168.                 }
  169.                
  170.                 var btnContinue2 = unsafeWindow.document.querySelector('[type="submit"][value="Continue!"]');
  171.                 if (btnContinue2) {
  172.                         btnContinue2.click();
  173.                 }
  174.        
  175.                 var btnAttack = unsafeWindow.document.querySelector('[type="submit"][value="Attack!"]');
  176.                 if (btnAttack) {
  177.                         btnAttack.click();
  178.                 }
  179.                
  180.                 var linkReturnToMap = unsafeWindow.document.querySelector('.optionsList a');
  181.                 if (linkReturnToMap && linkReturnToMap.textContent.trim() == 'Return to the Map') {
  182.                         settings.data.nextBattle = new Date().getTime() + 0;
  183.                         unsafeWindow.location.href = linkReturnToMap.href;
  184.                 }
  185.                
  186.                 // check for battle button
  187.                 var btnBattle = unsafeWindow.document.querySelector('#appear form input[type="submit"][value="Battle!"]');
  188.                 var linkRebattle = unsafeWindow.document.querySelector('.optionsList a');
  189.                 if (btnBattle) {
  190.                         // wait until 10 seconds since last battle
  191.                         //var delay = GM_getValue('lastBattle');
  192.                         window.setTimeout(function() {
  193.                                 btnBattle.click();
  194.                         }, 0);
  195.                 } else if (linkRebattle && linkRebattle.textContent.trim() == 'Rebattle Opponent') {
  196.                         window.setTimeout(function() {
  197.                                 unsafeWindow.location.href = linkRebattle.href;
  198.                         }, 0);
  199.                 } else {
  200.                         // if NOT found, click a direction
  201.                         var btnArrow = unsafeWindow.document.querySelector('#arrows img[onclick]')
  202.                         console.info('arrow', btnArrow);
  203.                         if (btnArrow) {
  204.                                 btnArrow.click();
  205.                         }
  206.                 }
  207.         } catch (e) {
  208.                 unsafeWindow.console.warn('Exception: ', e);
  209.         }
  210. }
  211.  
  212. function autoContinue() {
  213.         if (settings.data.findRare) {
  214.                 findRare();
  215.         }
  216.  
  217.         if (settings.data.autoBattle) {
  218.                 autoBattle();
  219.         }
  220.        
  221.         if (settings.data.findLegendary) {
  222.                 findLegendary();
  223.         }
  224. }
  225.  
  226. unsafeWindow.AjaxRequest = function () {
  227.         if (!this.xmlhttp) {
  228.                 try {
  229.                         // Try to create object for Firefox, Safari, IE7, etc.
  230.                         this.xmlhttp = new XMLHttpRequest();
  231.                 } catch (e) {
  232.                         try {
  233.                                 // Try to create object for later versions OF IE.
  234.                                 this.xmlhttp = new ActiveXObject('MSXML2.XMLHTTP');
  235.                         } catch (e) {
  236.                                 try {
  237.                                         // Try to create object for early versions OF IE.
  238.                                         this.xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
  239.                                 } catch (e) {
  240.                                         // Could NOT create AN XMLHttpRequest object.
  241.                                         return false;
  242.                                 }
  243.                         }
  244.                 }
  245.         }
  246.         this.method = 'post';
  247.         this.async = true;
  248.         this.url;
  249.         this.query = '';
  250.         this.data = '';
  251.         this.reponseText;
  252.         this.reponseXML;
  253.         this.responseHandler;
  254.         this.abortHandler;
  255.         this.showLoading = false;
  256.         this.send = function () {
  257.                 if (this.method && this.url) {
  258.                         var self = this;
  259.                         this.xmlhttp.onreadystatechange = function () {
  260.                                 if (self.xmlhttp.readyState == 4) {
  261.                                         if (self.xmlhttp.status && (self.xmlhttp.status == 200 || self.xmlhttp.status == 304)) {
  262.                                                 //unsafeWindow.console.info('success', self);
  263.                                                
  264.                                                 self.responseText = self.xmlhttp.responseText;
  265.                                                 if (self.xmlhttp.responseXML) {
  266.                                                         self.responseXML = self.xmlhttp.responseXML;
  267.                                                 } else {
  268.                                                         self.responseXML = null;
  269.                                                 }
  270.                                                 if (self.responseHandler) {
  271.                                                         self.responseHandler();
  272.                                                        
  273.                                                         var evt = document.createEvent('Event');
  274.                                                         evt.initEvent('gm:ajaxhook', false, true);
  275.                                                         document.dispatchEvent(evt);
  276.                                                        
  277.                                                         //autoContinue();
  278.                                                 }
  279.                                         } else {
  280.                                                 showAlert('<p>AN error occured WHILE requesting the data.</p><p>Status Msg: ' + self.xmlhttp.statusText + '</p><p><input type="button" name="ok" value="OK" onclick="removeAlert();" id="alertFocus"></p>');
  281.                                         }
  282.                                         if (self.showLoading && self.loading) {
  283.                                                 self.loading.style.visibility = 'hidden';
  284.                                         }
  285.                                 }
  286.                         }
  287.                         if (this.showLoading) {
  288.                                 this.displayLoading();
  289.                         }
  290.                         this.xmlhttp.OPEN(this.method, this.url + '?' + encodeURI(this.query), this.async);
  291.                         if (this.method == 'post') {
  292.                                 this.xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  293.                         }
  294.                         this.xmlhttp.send(encodeURI(this.data));
  295.                 } else {
  296.                         showAlert("<p>An error occured while requesting the data.</p><p>No method, URL, and/or query string provided.</p><p><input type=\"button\" name=\"OK\" value=\"OK\" onclick=\"removeAlert();\" id=\"alertFocus\"></p>");
  297.                 }
  298.         }
  299.         this.abort = function () {
  300.                 this.xmlhttp.onreadystatechange = function () {};
  301.                 this.xmlhttp.abort();
  302.                 if (this.abortHandler) {
  303.                         this.abortHandler();
  304.                 }
  305.         }
  306.         this.getFormValues = function (form) {
  307.                 for (i = 0; i < form.elements.length; i++) {
  308.                         switch (form.elements[i].type) {
  309.                         case 'text':
  310.                         case 'hidden':
  311.                         case 'password':
  312.                         case 'textarea':
  313.                                 this.data += form.elements[i].name + "=" + form.elements[i].value + "&";
  314.                                 break;
  315.                         case 'checkbox':
  316.                         case 'radio':
  317.                                 if (form.elements[i].checked) this.data += form.elements[i].name + "=" + form.elements[i].value + "&";
  318.                                 break;
  319.                         case 'select-one':
  320.                                 this.data += form.elements[i].name + "=" + form.elements[i].options[form.elements[i].selectedIndex].value + "&";
  321.                                 break;
  322.                         }
  323.                 }
  324.                 this.data = this.data.substr(0, (this.data.length - 1));
  325.         }
  326.         this.appendHTML = function (object, flag) {
  327.                 if (this.xmlhttp.responseText) {
  328.                         if (flag) {
  329.                                 object.innerHTML = this.responseText;
  330.                         } else {
  331.                                 object.innerHTML += this.responseText;
  332.                         }
  333.                 } else {}
  334.         }
  335.         this.displayLoading = function () {
  336.                 if (this.showLoading == 'sidebar') {
  337.                         this.loading = document.getElementById('sidebarLoading');
  338.                         this.loading.style.height = document.getElementById('sidebar').offsetHeight - 2 + 'px';
  339.                         this.loading.style.width = document.getElementById('sidebarContent').offsetWidth + 'px';
  340.                         this.loading.innerHTML = '<p style="text-align: center; margin-top: 150px;"><img src="http://static.pokemonvortex.org/images/loading.gif" width="100" height="100" alt="Loading..." /></p>';
  341.                 } else if (this.showLoading == 'message') // message
  342.                 {
  343.                         this.loading = document.getElementById('messageContent');
  344.                         this.loading.style.height = document.getElementById('message').offsetHeight + 'px';
  345.                         this.loading.style.width = document.getElementById('message').offsetWidth + 'px';
  346.                         this.loading.innerHTML = '<p style="text-align: center; margin-top: 75px;"><img src="http://static.pokemonvortex.org/images/loading.gif" width="100" height="100" alt="Loading..." /></p>';
  347.                 } else if (this.showLoading == 'messageList') // message list
  348.                 {
  349.                         this.loading = document.getElementById('messageList');
  350.                         this.loading.style.height = document.getElementById('messageList').offsetHeight + 'px';
  351.                         this.loading.style.width = document.getElementById('messageList').offsetWidth + 'px';
  352.                         this.loading.innerHTML = '<p style="text-align: center; margin-top: 50px;"><img src="http://static.pokemonvortex.org/images/loading.gif" width="100" height="100" alt="Loading..." /></p>';
  353.                 } else if (this.showLoading == 'map') // map
  354.                 {
  355.                         this.loading = document.getElementById('mapLoading')
  356.                         this.loading.innerHTML = '<p style="text-align: center; margin-top: 150px;"><img src="http://static.pokemonvortex.org/images/loading_white.gif" width="100" height="100" alt="Loading..." /></p>';
  357.                 } else if (this.showLoading == 'live') {
  358.                         this.loading = document.getElementById('loading');
  359.                         this.loading.style.height = document.getElementById('scroll').offsetHeight + 'px';
  360.                         if (document.getElementById('scrollContent')) {
  361.                                 this.loading.style.width = document.getElementById('scrollContent').offsetWidth + 'px';
  362.                         } else {
  363.                                 this.loading.style.width = document.getElementById('scroll').offsetWidth + 'px';
  364.                         }
  365.                         this.loading.innerHTML = '<p class="large" style="margin-top: 75px; text-align: center;"><strong>Waiting for the other user to respond...</strong></p><p style="text-align: center;">You have been waiting <span id="waitTime">0 seconds</span>.</p>';
  366.                         waitTime(0);
  367.                 } else // main
  368.                 {
  369.                         this.loading = document.getElementById('loading');
  370.                         this.loading.style.height = document.getElementById('scroll').offsetHeight + 'px';
  371.                         if (document.getElementById('scrollContent')) {
  372.                                 this.loading.style.width = document.getElementById('scrollContent').offsetWidth + 'px';
  373.                         } else {
  374.                                 this.loading.style.width = document.getElementById('scroll').offsetWidth + 'px';
  375.                         }
  376.                         this.loading.innerHTML = '<p style="text-align: center; margin-top: 150px;"><img src="http://static.pokemonvortex.org/images/loading.gif" width="100" height="100" alt="Loading..." /></p>';
  377.                 }
  378.                 this.loading.style.visibility = 'VISIBLE';
  379.         }
  380. }
  381.  
  382. function createToggler(container, title, varname) {
  383.         var toggleEnable = unsafeWindow.document.createElement('p');
  384.         container.appendChild(toggleEnable);
  385.         toggleEnable.innerHTML = title + ' <b>' + (settings.data[varname] ? 'Enabled' : 'Disabled') + '</b>';
  386.         toggleEnable.addEventListener('click', function() {
  387.                 settings.data[varname] = !settings.data[varname];
  388.                 toggleEnable.innerHTML = title + ' <b>' + (settings.data[varname] ? 'Enabled' : 'Disabled') + '</b>';
  389.                 settings.save();
  390.                 autoContinue();
  391.         }, false);
  392. }
  393.  
  394. function init() {
  395.         var iframes = unsafeWindow.document.getElementsByTagName('iframe');
  396.         for (var i = 0; i < iframes.length; i++) {
  397.                 iframes[i].parentNode.removeChild(iframes[i]);
  398.         }
  399.         var sty = unsafeWindow.document.createElement('style');
  400.         unsafeWindow.document.querySelector('head').appendChild(sty);
  401.         sty.textContent = '#fscctrl { background: green; border: 1px solid yellow; cursor:pointer; margin: auto; padding: 10px; width: 1010px; } #fscctrl p { margin: 0; } #alert{position:absolute; z-index: 1; background:#ffc; padding: 0 10px; right: 0; width: 100px;} #alert p { margin: 0; } #loading {z-index: 0; top: 0; height: 200px;} #loading p {margin-top:0 !important;} #header{ height: 70px; }';
  402.         unsafeWindow.disableSubmitButton = function(form) {
  403.                 for (i = 0; i < form.elements.length; i++) {
  404.                         if (form.elements[i].type == 'submit') {
  405.                                 form.elements[i].value = 'Please Wait... or click again - whatever';
  406.                         }
  407.                 }
  408.                 return true;
  409.         }
  410.        
  411.         settings.load();
  412.        
  413.         document.addEventListener('gm:ajaxhook', function() {
  414.                 autoContinue();
  415.         }, false);
  416.        
  417.         var container = unsafeWindow.document.createElement('div');
  418.         unsafeWindow.document.body.insertBefore(container, unsafeWindow.document.body.firstChild);
  419.         container.setAttribute('id', 'fscctrl');
  420.  
  421.         createToggler(container, 'Auto-battle', 'autoBattle');
  422.         createToggler(container, 'Find Rare', 'findRare');
  423.         createToggler(container, 'Find Legendary', 'findLegendary');
  424.        
  425.         autoContinue();
  426. }
  427.  
  428. init();