Advertisement
Guest User

Untitled

a guest
Jun 30th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         market .pt
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  try to take over the world!
  6. // @author       You
  7. // @match        https://*.tribalwars.com.pt/*
  8. // @grant        none
  9. // @grant       GM_getValue
  10. // @grant       GM_setValue
  11. // ==/UserScript==
  12. /* jshint -W097 */
  13. 'use strict';
  14.  
  15. // Your code here...
  16. var maximumSellValue=220;
  17. var minumunSellAmount=1000;
  18.  
  19. if($(location).attr('href').indexOf('screen=market&mode=exchange') != -1&&$('[id="market_merchant_available_count"]').text()*1<0){
  20.    
  21. alert("You should have at least 9 merchants available to use this script.");
  22.  
  23. }else{
  24.  
  25.  
  26. setInterval(function(){
  27.    
  28.    
  29.    
  30.     $('[class="btn evt-cancel-btn btn-confirm-no"]').click();
  31.    
  32.    
  33.      $('[name="sell_wood"]').val(0);
  34.      $('[name="sell_stone"]').val(0);
  35.      $('[name="sell_iron"]').val(0);
  36.    
  37.     if ($(location).attr('href').indexOf('screen=market&mode=exchange') != -1) {
  38.         var woodPrice=$('[id="premium_exchange_rate_wood"]').find('div').eq(0).text()*1;
  39.         var stonePrice=$('[id="premium_exchange_rate_stone"]').find('div').eq(0).text()*1;
  40.         var ironPrice=$('[id="premium_exchange_rate_iron"]').find('div').eq(0).text()*1;
  41.  
  42.         var myWood = $('[id="wood"]').text()*1;
  43.         var myStone = $('[id="stone"]').text()*1;
  44.         var myIron = $('[id="iron"]').text()*1;
  45.        
  46.         var stockWood=$('[id="premium_exchange_stock_wood"]').text()*1;
  47.         var stockStone=$('[id="premium_exchange_stock_stone"]').text()*1;
  48.         var stockIron=$('[id="premium_exchange_stock_iron"]').text()*1;
  49.  
  50.         var stockWoodCapacity=$('[id="premium_exchange_capacity_wood"]').text()*1;
  51.         var stockStoneCapacity=$('[id="premium_exchange_capacity_stone"]').text()*1;
  52.         var stockIronCapacity=$('[id="premium_exchange_capacity_iron"]').text()*1;
  53.  
  54.    
  55.        
  56.        
  57.        
  58.        
  59.         var aux=shouldSell(woodPrice,myWood,stockWood,stockWoodCapacity);
  60.          aux = aux/1000<$('[id="market_merchant_available_count"]').text()*1 ? aux : $('[id="market_merchant_available_count"]').text()*1000 - maximumSellValue-1;
  61.         if(aux>0&&aux/1000<$('[id="market_merchant_available_count"]').text()*1){
  62.              $('[name="sell_wood"]').val(aux);
  63.             console.log("sold "+aux +"for "+woodPrice+" each.");
  64.             setPointsEarned(Math.ceil(aux/woodPrice)-1);
  65.         $('[class="btn float_right btn-premium-exchange-buy"]').click();
  66.         setTimeout(function(){
  67.            
  68.          $('[class="btn evt-confirm-btn btn-confirm-yes"]').click();
  69.         },1500);
  70.         }else{
  71.        
  72.         aux=shouldSell(stonePrice,myStone,stockStone,stockStoneCapacity);
  73.              aux = aux/1000<$('[id="market_merchant_available_count"]').text()*1 ? aux : $('[id="market_merchant_available_count"]').text()*1000 - maximumSellValue-1;
  74.         if(aux>0&&aux/1000<$('[id="market_merchant_available_count"]').text()*1){
  75.              $('[name="sell_stone"]').val(aux);
  76.             console.log("sold "+aux +"for "+stonePrice+" each.");
  77.             setPointsEarned(Math.ceil(aux/stonePrice)-1);
  78.         $('[class="btn float_right btn-premium-exchange-buy"]').click();
  79.         setTimeout(function(){
  80.            
  81.          $('[class="btn evt-confirm-btn btn-confirm-yes"]').click();
  82.         },1500);
  83.         }else{
  84.        
  85.          aux=shouldSell(ironPrice,myIron,stockIron,stockIronCapacity);
  86.            
  87.            aux = aux/1000<$('[id="market_merchant_available_count"]').text()*1 ? aux : $('[id="market_merchant_available_count"]').text()*1000 - maximumSellValue-1;
  88.         if(aux>0&&aux/1000<$('[id="market_merchant_available_count"]').text()*1){
  89.              $('[name="sell_iron"]').val(aux);
  90.             console.log("sold "+aux +"for "+ironPrice+" each.");
  91.             setPointsEarned(Math.ceil(aux/ironPrice)-1);
  92.         $('[class="btn float_right btn-premium-exchange-buy"]').click();
  93.         setTimeout(function(){
  94.            
  95.          $('[class="btn evt-confirm-btn btn-confirm-yes"]').click();
  96.         },1500);
  97.         }
  98.         }
  99.        
  100.         }
  101.        
  102.     }
  103.  
  104. },9000);
  105.  
  106.  
  107. }
  108. function shouldSell(price,my,stock, capacity){
  109.  
  110.     if(capacity-stock <4000||my<minumunSellAmount||price>maximumSellValue){
  111.     return -1;
  112.     }
  113.    
  114.     return Math.min(Math.floor(my/1000)*1000-1-price,Math.floor((capacity-stock)/1000)*1000-1-price);
  115.  
  116.  
  117. }
  118.  
  119.  
  120. //setInterval(function(){
  121.  
  122. //if(maximumSellValue==170){
  123. // maximumSellValue=170;
  124. //    console.log('changing maximum price to 140');
  125. //}else{
  126. // maximumSellValue=170;
  127. //    console.log('changing maximum price to 170');
  128. //}
  129.  
  130.  
  131. //},3*60*60*1000);
  132.  
  133. function setPointsEarned(points){
  134.  
  135. var d = new Date();
  136.  console.log(d+" ==== earned points ======> "+points);
  137.    
  138.  
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement