Facebook
From XXDD, 2 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 97
  1. // ==UserScript==
  2. // @name         Auto-Etykieta
  3. // @version      2.1.7.1
  4. // @description  Tags new incomings
  5. // @author       FunnyPocketBook
  6. // @match        https://*/game.php?*mode=incomings*
  7. // @grant        none
  8. // @namespace https://greasyfork.org/users/151096
  9. // ==/UserScript==
  10. let attack = "Atak"; // Change this to your language
  11. let support = "Wsparcie"; // Change this to your language
  12. let noble = "Szlachcic" // Change this to your language
  13. const wait = 2000; // How often the script checks for new attacks in milliseconds
  14.  
  15. const domain = document.domain;
  16. if(domain.includes("tribalwars.com.pt") || domain.includes("tribalwars.com.br")) {
  17.     attack = "ataque";
  18.     support = "apoio";
  19.     noble = "nobre";
  20. }
  21. attack = attack.toLowerCase();
  22. support = support.toLowerCase();
  23. noble = noble.toLowerCase();
  24.  
  25. const incRow = document.querySelector("#incomings_table").rows.length;
  26. const timeout = Math.max(60000, incRow * 31);
  27. setTimeout(function() {
  28.     "use strict";
  29.     tagger();
  30. }, wait);
  31.  
  32. setTimeout(function() {
  33.     window.location.reload();
  34. }, timeout);
  35.  
  36. function tagger() {
  37.     "use strict";
  38.     let attackingVillage = []; // Store all attacking villages
  39.     let villNr = []; // Store number of attacks per attacking village, same index as attackingVillage
  40.     let index;
  41.     for (let i = 2; i < incRow; i++) {
  42.         index = attackingVillage.indexOf($("#incomings_table > tbody > tr:nth-child(" + i + ") > td:nth-child(3) > a").text()); // See if the attacking village is already in the array
  43.         if(index === -1) { // If attacking village is not in array, push it into array
  44.             attackingVillage.push($("#incomings_table > tbody > tr:nth-child(" + i + ") > td:nth-child(3) > a").text());
  45.             villNr.push(1);
  46.         } else { // If attacking village is in array, increase attack number
  47.             villNr[index]++;
  48.         }
  49.         let incName = document.querySelector("#incomings_table > tbody > tr:nth-child(" + i + ") > td:nth-child(1) > span > span > a:nth-child(1) > span.quickedit-label").innerHTML;
  50.         let nobleIcon = "";
  51.         // If icon exist, save it in nobleIcon
  52.         if (document.querySelector("#incomings_table > tbody > tr:nth-child(" + i + ") > td:nth-child(1) > span > span > a:nth-child(1) > span:nth-child(2) > img")) {
  53.             nobleIcon = document.querySelector("#incomings_table > tbody > tr:nth-child(" + i + ") > td:nth-child(1) > span > span > a:nth-child(1) > span:nth-child(2) > img").getAttribute("src");
  54.         }
  55.         incName = incName.trim().toLowerCase();
  56.         // If the attack has the noble icon and is not already tagged as noble, tag it as noble
  57.         if (nobleIcon.includes("snob.png") && !incName.includes(noble)) {
  58.             document.querySelector("#incomings_table > tbody > tr:nth-child(" + i + ") > td:nth-child(1) > span > span > a.rename-icon").click();
  59.             document.querySelector('#incomings_table > tbody > tr:nth-child(' + i + ') > td:nth-child(1) > span > span.quickedit-edit > input[type="text"]:nth-child(1)').value = noble;
  60.             document.querySelector("#incomings_table > tbody > tr:nth-child(" + i + ") > td:nth-child(1) > span > span.quickedit-edit > input.btn").click();
  61.         }
  62.         // If the attack is labelled with attack or support, click the checkbox so the system automatically tags the inc
  63.         else if (incName.includes(attack) || incName.includes(support)) {
  64.                         document.querySelector('#incomings_table > tbody > tr:nth-child(' + i + ') > td:nth-child(1) > input[type="checkbox"]:nth-child(2)').click();
  65.                 }
  66.     }
  67.  
  68.     // Tag the attacks with the number of attacks per attacking village
  69.     let j = 2;
  70.     let tagInterval = setInterval(function() { // Interval instead of for-loop to control the server requests
  71.         let incName = document.querySelector("#incomings_table > tbody > tr:nth-child(" + j + ") > td:nth-child(1) > span > span > a:nth-child(1) > span.quickedit-label").innerHTML; // Get inc name
  72.         incName = incName.replace(/(\r\n|\n|\r)/gm,"").replace(/ /g,"").toLowerCase(); // Remove all whitespace from attack name and make it lowercase
  73.         const attVill = attackingVillage.indexOf($("#incomings_table > tbody > tr:nth-child(" + j + ") > td:nth-child(3) > a").text());
  74.         if(!incName.includes(attack) && incName.slice(-1) != villNr[attVill]) { // If the last character in the inc name is not a number and the incName does not include "attack", append the number
  75.             index = attackingVillage.indexOf($("#incomings_table > tbody > tr:nth-child(" + j + ") > td:nth-child(3) > a").text()); // See which index the attack has
  76.             document.querySelector("tr.nowrap:nth-child(" + j + ") > td:nth-child(1) > span:nth-child(3) > span:nth-child(1) > a:nth-child(2)").click();
  77.             const incLabel = document.querySelector('#incomings_table > tbody > tr:nth-child(' + j + ') > td:nth-child(1) > span > span.quickedit-edit > input[type="text"]:nth-child(1)');
  78.             if(Number.isInteger(parseInt(incName.slice(-1)))) {
  79.                 incLabel.value = incLabel.value.slice(0, -1);
  80.             }
  81.             document.querySelector("tr.nowrap:nth-child(" + j + ") > td:nth-child(1) > span:nth-child(3) > span:nth-child(2) > input:nth-child(1)").value += " " + villNr[index];
  82.             document.querySelector("tr.nowrap:nth-child(" + j + ") > td:nth-child(1) > span:nth-child(3) > span:nth-child(2) > input:nth-child(2)").click();
  83.         }
  84.         j++;
  85.         if(j >= incRow) { // Stop interval, just like the for-loop condition
  86.             clearInterval(tagInterval);
  87.             document.querySelector("[name=label]").click();
  88.         }
  89.     }, 40);
  90. }