daily pastebin goal
9%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //if the minutes until the refill are a high number probably there was a recent refill
  2. const LBPminutesToCheckAt = 8
  3. const LBPminutesToResetFight = 5
  4. const LBPminuteCheckRegex = /0\d:/g
  5.  
  6. let LBPfought = true
  7.  
  8. function battlePage() {
  9.     //find minutes remaining until refill
  10.     // let minutesText = $("#minutesLimit").text() // format should be: "0X:" where X is between 0-9
  11.     // if (minutesText === '0-1' || minutesText === '0-2') refreshPage()
  12.  
  13.     //reset the regex
  14.     LBPminuteCheckRegex.lastIndex = 0
  15.     //finds matches and if everything is ok the index must be at 0, else refreshes the page
  16.     // let isMatching = LBPminuteCheckRegex.exec(minutesText)
  17.     /* try {
  18.          if (isMatching.index !== 0) {
  19.              refreshPage()
  20.              console.log('xD')
  21.          }
  22.      }
  23.      catch (e) {
  24.          refreshPage()
  25.      }*/
  26.     let minutesTillRefill = Number($("#limit_timer_time_text").text().replace(/m \d*s/g, ''))
  27.     //gets the HP and performs some calculations to take the right action
  28.     let hpSpan = $('span:contains(\'Health:\')').next().text()
  29.     //if the battle is over or the round is over takes action
  30.     isRoundBattleActive()
  31.     if (minutesTillRefill !== NaN && minutesTillRefill >= LBPminutesToCheckAt && hpSpan === '0.0' && !LBPfought) {
  32.         refreshPage()
  33.     }
  34.     else performAction(hpSpan)
  35.     if (minutesTillRefill <= LBPminutesToResetFight) LBPfought = false
  36.  
  37. }
  38.  
  39.  
  40. function performAction(hpSpan) {
  41.     if (hpSpan !== '0.0') {
  42.         fight(1)
  43.  
  44.         setTimeout(battlePage, generateRandomBetween(3000, 7000))
  45.     }
  46.     else {
  47.         //if nothing more to hit closes the window
  48.         let closeHitData = $('div.pico-close:contains(\'×\')')
  49.         if (closeHitData[0] !== undefined) closeHitData[0].click()
  50.     }
  51. }
  52.  
  53. //clicks the fight button takes 1 or 5 as an argument
  54. function fight(hits) {
  55.     console.log('fights')
  56.     LBPfought = true
  57.     //gets the divs
  58.     let berserk = $('#fightButtonBerserk1')
  59.     let normalHit = $('#fightButton1')
  60.     let fightAgain = $('#fightagainbutton')
  61.     if (fightAgain[0] !== undefined) {
  62.         fightAgain[0].click()
  63.     }
  64.     else if (hits == '5') {
  65.         if (berserk[0] !== undefined) {
  66.             //find 'i' finds the icon so it hits the button in the boundaries
  67.             berserk.find('i')[0].click()
  68.         }
  69.     }
  70.     else if (hits == '1') {
  71.         if ($('#fightButton2')[0] !== undefined) {
  72.             $('#fightButton2').find('i')[0].click()
  73.         }
  74.         else if (normalHit[0] !== undefined) {
  75.             normalHit.find('i')[0].click()
  76.         }
  77.     }
  78. }
  79.  
  80.  
  81. //checks whether the current opened battle is valid, if not opens another one
  82. //checks if round is over. if yes refreshes the page
  83. function isRoundBattleActive() {
  84.     let battleTime = $('#roundCountdown').find('span').text()
  85.     let wrongLocation = $("div:contains('t fight in this battle from your current location.')")
  86.     if (battleTime === '00:00:00' || wrongLocation[0] !== undefined) {
  87.         //looks for button with battle drops text
  88.         let battleDrops = $('input[value=\'Show battle drops\']')
  89.         if (battleDrops[0] !== undefined || wrongLocation[0] !== undefined) {
  90.             //navigates to another battle
  91.             console.log('xD')
  92.             buildSwitchBattleTask()
  93.         }
  94.         //if you are not browsing other pages
  95.         else if (window.location.search.indexOf('round') === -1) {
  96.             //automatically goes to the last page
  97.             refreshPage()
  98.         }
  99.         else {
  100.             let battleId = Number(window.location.search.replace("?id=", '').replace(/&round=\d/, ''))
  101.             window.location.search = "?id=" + battleId
  102.         }
  103.     }
  104. }
  105.  
  106. function buildSwitchBattleTask(Memory = new LongTermMemory('FindBattle')) {
  107.  
  108.     //first step
  109.     let navigateHome = `()=>{
  110.         window.location.pathname = '/index.html'
  111.     }`
  112.     Memory.createTask('navigate-home', navigateHome)
  113.  
  114.     gotoBattleTask(Memory)
  115.  
  116. }
  117.  
  118. function gotoBattleTask(Memory = new LongTermMemory('FindBattle')) {
  119.     //secondStep
  120.     //checks for available battles
  121.     let findBattle = `()=>{
  122.         $('#tabs-4').find('a')[0].click()
  123.     }`
  124.  
  125.     Memory.createTask('click-battle', findBattle)
  126.  
  127.     fulfillTask(Memory)
  128. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top