Facebook
From Edgy Moth, 1 Year ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 90
  1. // ==UserScript==
  2.     // @name         Automated call resources in marketplace
  3.     // @namespace    http://tampermonkey.net/
  4.     // @version      1.4
  5.     // @description  try to take over the world!
  6.     // @author       pts
  7.     // @match        https://*.plemiona.pl/game.php?*screen=market*mode=call*
  8.     // @grant        none
  9.     // ==/UserScript==
  10.  
  11.     timer = getCookie("timerCallSources");
  12.     if (timer) {
  13.         refresh_time = parseInt(timer)
  14.     } else {
  15.         refresh_time = 5
  16.     }
  17.  
  18.     coin_price_handler = getCookie("coin_price_handler");
  19.     console.log('CPH: '+coin_price_handler)
  20.     if (coin_price_handler) {
  21.  
  22.     } else {
  23.         coin_price_handler = "0"
  24.     }
  25.  
  26.     coin_prices = getCookie("coin_price");
  27.     if (coin_prices) {
  28.         coin_prices = JSON.parse(coin_prices);
  29.     } else {
  30.         coin_prices = [28000,30000,25000];
  31.     }
  32.  
  33.     console.log(coin_prices)
  34.  
  35.     counter = refresh_time * 60
  36.  
  37.     cookie = getCookie("autoCallSources");
  38.     if (cookie == "auto") {
  39.         btn_text = "Deaktywuj";
  40.         next_refresh_row = `<td>Nastepny refresh za</td><td><span id="counter">${counter}</span> sekund</td>`
  41.         setTimeout(() => {
  42.             $("input[name='select-all']").click()
  43.             if (coin_price_handler == '1') {
  44.                 $.each($(".supply_location"),function(index,row) {
  45.                     columns = $(row).find('td')
  46.                     row_supplies = [parseInt($(columns[2]).find('input').val().replace(".","")),parseInt($(columns[3]).find('input').val().replace(".","")),parseInt($(columns[4]).find('input').val().replace(".","")),parseInt($(columns[6]).text().split("/")[0])]
  47.                     quantity = []
  48.                     for (i=0;i<3;i++) {
  49.                         quantity.push(Math.floor(row_supplies[i]/coin_prices[i]))
  50.                     }
  51.                     min = Math.min(...quantity)
  52.                     $(columns[2]).find('input').val(min * coin_prices[0])
  53.                     $(columns[3]).find('input').val(min * coin_prices[1])
  54.                     $(columns[4]).find('input').val(min * coin_prices[2])
  55.                 })
  56.             }
  57.  
  58.             setTimeout(() => {$("input[value='Poproś o surowce']").click()},1000)
  59.         },200)
  60.         setInterval(() => {
  61.             counter -= 1
  62.             $("#counter").text(counter)
  63.             if (counter == 0) {
  64.                 location.reload()
  65.             }
  66.         },1000)
  67.     } else {
  68.         btn_text = "Aktywuj";
  69.         next_refresh_row = ''
  70.     }
  71.  
  72.     $("#content_value").prepend(`<div class="bordered-box">
  73.     <h3>Ściąganie surowców</h3>
  74.     <br>
  75.     <table style="width:300px;">
  76.     <tr><td>Co ile minut refresh?</td><td><input id="refresh_interval" value="${refresh_time}" type="num" min="0" step="1"></td></tr>
  77.     <tr>${next_refresh_row}</tr>
  78.     <tr><td colspan="2"><button id="toogle" style="width:100%;" class="btn btn-block">${btn_text}</button></td></tr>
  79.     </table>
  80.     <h4>Cena monety</h4>
  81.     <table>
  82.     <tr><th style="width:100px"><span class="icon header wood"></span></th><th style="width:100px"><span class="icon header stone"></span></th><th style="width:100px"><span class="icon header iron"></span></th><th><input id="price_handler" type="checkbox"> Uwzględnij ceny monet</th></tr>
  83.     <tr><th><input id="wood_price" value="${coin_prices[0]}"></th><th><input id="stone_price" value="${coin_prices[1]}"></th><th><input id="iron_price" value="${coin_prices[2]}"></th></tr>
  84.     </table>
  85.     </div>`)
  86.  
  87.     if (coin_price_handler == "1") $("#price_handler")[0].checked = true
  88.  
  89.     function setCookie(cname, cvalue, exdays) {
  90.         var d = new Date();
  91.         d.setTime(d.getTime() + (exdays*24*60*60*1000));
  92.         var expires = "expires="+ d.toUTCString();
  93.         document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
  94.     }
  95.  
  96.     function getCookie(cname) {
  97.         var name = cname + "=";
  98.         var decodedCookie = decodeURIComponent(document.cookie);
  99.         var ca = decodedCookie.split(';');
  100.         for(var i = 0; i <ca.length; i++) {
  101.             var c = ca[i];
  102.             while (c.charAt(0) == ' ') {
  103.                 c = c.substring(1);
  104.             }
  105.             if (c.indexOf(name) == 0) {
  106.                 return c.substring(name.length, c.length);
  107.             }
  108.         }
  109.         return "";
  110.     }
  111.  
  112.  
  113.     $(document.body).on('click','#toogle',() => {
  114.         if (cookie == "auto") {
  115.             setCookie('autoCallSources','no_auto',9999);
  116.             location.reload();
  117.         } else {
  118.             if ($("#price_handler")[0].checked) {handler = "1"} else {handler = "0"}
  119.             prices = [parseInt($("#wood_price").val()),parseInt($("#stone_price").val()),parseInt($("#iron_price").val())]
  120.             prices = JSON.stringify(prices)
  121.             console.log(handler)
  122.             setCookie('timerCallSources',$("#refresh_interval").val(),9999)
  123.             setCookie('autoCallSources','auto',9999);
  124.             setCookie('coin_price_handler',handler,9999)
  125.             setCookie('coin_price',prices,9999)
  126.             location.reload();
  127.         }
  128.     })