Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Zbieractwo
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description try to take over the world!
- // @author You
- // @match https://*.plemiona.pl/game.php?*&screen=place&mode=scavenge
- // @grant none
- // ==/UserScript==
- (function () {
- if(game_data.units.length == 10){
- window.units = [{
- name: 'pik',
- count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(1) > a').innerText.replace(/[(|)]/gm, '')),
- input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(1) > input'),
- capacity: 25
- },
- {
- name: 'sword',
- count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(2) > a').innerText.replace(/[(|)]/gm, '')),
- input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(2) > input'),
- capacity: 15
- },
- {
- name: 'axe',
- count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(3) > a').innerText.replace(/[(|)]/gm, '')),
- input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(3) > input'),
- capacity: 10
- },
- {
- name: 'light',
- count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(4) > a').innerText.replace(/[(|)]/gm, '')),
- input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(4) > input'),
- capacity: 80
- },
- {
- name: 'heavy',
- count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(5) > a').innerText.replace(/[(|)]/gm, '')),
- input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(5) > input'),
- capacity: 50
- },
- {
- name: 'noble',
- count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(6) > a').innerText.replace(/[(|)]/gm, '')),
- input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(6) > input'),
- capacity: 100
- }
- ]
- }else{
- window.units = [{
- name: 'pik',
- count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(1) > a').innerText.replace(/[(|)]/gm, '')),
- input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(1) > input'),
- capacity: 25
- },
- {
- name: 'sword',
- count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(2) > a').innerText.replace(/[(|)]/gm, '')),
- input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(2) > input'),
- capacity: 15
- },
- {
- name: 'axe',
- count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(3) > a').innerText.replace(/[(|)]/gm, '')),
- input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(3) > input'),
- capacity: 10
- },
- {
- name: 'arrow',
- count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(4) > a').innerText.replace(/[(|)]/gm, '')),
- input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(4) > input'),
- capacity: 10
- },
- {
- name: 'light',
- count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(5) > a').innerText.replace(/[(|)]/gm, '')),
- input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(5) > input'),
- capacity: 80
- },
- {
- name: 'arrowhorse',
- count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(6) > a').innerText.replace(/[(|)]/gm, '')),
- input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(6) > input'),
- capacity: 50
- },
- {
- name: 'heavy',
- count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(7) > a').innerText.replace(/[(|)]/gm, '')),
- input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(7) > input'),
- capacity: 50
- },
- {
- name: 'noble',
- count: parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(8) > a').innerText.replace(/[(|)]/gm, '')),
- input: document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(8) > input'),
- capacity: 100
- }
- ]
- }
- window.get_capacity = function () {
- var output = 0;
- units.forEach(unit => {
- output = output + unit.capacity * unit.count
- });
- return output;
- }
- window.getSelectedCapacity = function(){
- var output = 0;
- units.forEach(unit =>{
- output = output + unit.input.value * unit.capacity;
- });
- return output;
- }
- window.customFlag1 = false;
- window.requiredResources = [];
- window.requiredParts = [10,4,2,1];
- window.activeplans = $('.status-specific').length - $('.locked-view').length;
- var partsCount = activeplans == 1 ? 10 : activeplans == 2 ? 14 : activeplans == 3 ? 16 : activeplans == 4 ? 17 : null;
- window.queCurrent = function(){
- if(!window.customFlag1)
- this.setTimeout(show_current, 50);
- window.customFlag1 = true;
- }
- window.show_current = function () {
- window.customFlag1 = false;
- $('.remove_selector_countAll').remove()
- $('#scavenge_screen > div > div.options-container > div').each(function (index, element) {
- var e = $(element).find('ul');
- if (typeof e != 'undefined') {
- var sum = 0;
- for (var lii = 0; lii < e.children(':not([class])').length; lii++) {
- sum = sum + parseInt($(e.children(':not([class])')[lii]).find(':last-child').text());
- }
- e.append('<li class="remove_selector_countAll">' + sum + ' / '+getSelectedCapacity()+'</li>')
- }
- })
- }
- window.calculateInput = function(){
- var part = Math.floor(get_capacity() / partsCount);
- for(var index = 0; index<activeplans; index++){
- window.requiredResources[index] = part*window.requiredParts[index];
- }
- }
- window.refreshUnits = function(){
- for(var unitIndex = 1; unitIndex <= units.length; unitIndex++){
- units[unitIndex-1].count = parseInt(document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child('+unitIndex+') > a').innerText.replace(/[(|)]/gm, ''))
- }
- }
- window.fillInputs = async function(){
- for(var inde = 0; inde<activeplans; inde++){
- refreshUnits();
- var selectedUnits = [];
- var filledCappacity = 0;
- for(var currentUnitIndex = 0; currentUnitIndex < units.length; currentUnitIndex++){
- //Analiza pojedynczej jednostki
- if(filledCappacity < requiredResources[inde]){
- var u = units[currentUnitIndex];
- var count = 0;
- for(var unitCountIndex = 0; unitCountIndex<u.count; unitCountIndex++){
- filledCappacity = filledCappacity + u.capacity;
- if(filledCappacity < requiredResources[inde]){
- count++;
- }else{
- break;
- }
- }
- if(count > 0){
- console.log("Push to "+(inde+1)+" "+count+" of "+units[currentUnitIndex].name);
- selectedUnits.push({
- unitID:currentUnitIndex,
- unitCount:count,
- input:u.input
- });
- }
- }else{
- break;
- }
- }
- selectedUnits.forEach(su=>{
- $(su.input).trigger('focus');
- $(su.input).trigger('keydown');
- $(su.input).val(su.unitCount);
- $(su.input).trigger('keyup');
- $(su.input).trigger('change');
- });
- await sleep(2000);
- $('#scavenge_screen > div > div.options-container > div:nth-child('+(inde+1)+') > div.status-specific > div > div.action-container > a.btn.btn-default.free_send_button').click();
- await sleep(2000);
- }
- window.BotIsWorking = false;
- }
- window.startBot = function(){
- console.log("trying to start");
- var active_buttons = $('.action-container > a.free_send_button').length;
- if(active_buttons == window.activeplans && localStorage.botIsActive == "true"){
- console.log("Started");
- setTimeout(calculateInput, 2000);
- setTimeout(fillInputs, 4000);
- }
- }
- window.BotIsWorking = null;
- window.preStartBot = function(){
- console.log("PreStarting");
- clearTimeout(window.BotIsWorking);
- window.BotIsWorking = setTimeout(startBot, 20000);
- }
- window.turnOnFarm = function(e){
- localStorage.botIsActive = e.checked;
- location.reload();
- }
- function sleep(ms) {
- return new Promise(resolve => setTimeout(resolve, ms));
- }
- $('#scavenge_screen > div > div.options-container > div > div.status-specific > div > div.squad-preview > ul > li:nth-child(1) > span.wood-value').bind("DOMSubtreeModified", function() {
- queCurrent();
- });
- window.Collecting = false;
- $('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(1)').append('<th></th>');
- $('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(1)').append('<th></th>');
- $('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2)').append('<td><a href="#" class="btn btn-default custom-lock-buttons" onclick="calculateInput()">Oblicz</a></td>');
- $('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2)').append('<td><a href="#" class="btn btn-default custom-lock-buttons" onclick="fillInputs()">Wypełnij</a></td>');
- $('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(1)').append('<th>Działaj ciągle</th>');
- $('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2)').append('<td><input type="checkbox" onchange="turnOnFarm(this)" /></td>');
- document.querySelector('#scavenge_screen > div > div.candidate-squad-container > table > tbody > tr:nth-child(2) > td:nth-child(11) > input[type=checkbox]').checked = localStorage.botIsActive == "true";
- if(localStorage.botIsActive == "true"){
- $('.custom-lock-buttons').hide();
- startBot();
- }
- $('.status-specific').bind("DOMSubtreeModified",function(){
- var active_buttons = $('.action-container > a.free_send_button').length;
- if(active_buttons == window.activeplans && localStorage.botIsActive == "true")
- window.preStartBot();
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement