Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.16 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Tribal wars farmrank generator - all
  3. // @version 1.0
  4. // @description Rank generator for tribal wars (www.plemiona.pl/)
  5. // @author luluu9
  6. // @match http://*.plemiona.pl/*
  7. // @license MIT
  8. // ==/UserScript==
  9.  
  10.  
  11. // By Lulusek - œwiat 136/138
  12. function fetchPlayersOnPage(doc) {
  13. let rank = doc.querySelector("#in_a_day_ranking_table > tbody");
  14. let playersOnPage = [];
  15. for (let el of rank.children) {
  16. player = {
  17. "index": el.children[0].textContent,
  18. "name": el.children[1].textContent.replace(`
  19.  
  20.  
  21.  
  22. `, '').replace(`
  23.  
  24. `,''), // bo wype³niony jest spacjami, nie wiem po co
  25. "tribe": el.children[2].textContent.replace(/\s/g,''),
  26. "score": el.children[3].textContent.replace(/\s/g,''),
  27. "date": el.children[4].textContent.replace(/\s/g,'')
  28. };
  29. if (player.index != "Ranking") { playersOnPage.push(player) };
  30. }
  31. return playersOnPage;
  32. }
  33.  
  34. function getTextToPost(players) {
  35. script = "[spoiler=Ranking farmerów, "+new Date().toLocaleDateString()+`][table]
  36. [**]LP[||]Gracz[||]Cz³on[||]Wynik[||]Ranking ogólny[/**]`;
  37. i = 1;
  38. for (let player of players) {
  39. script = script + "[*]" + i + "[|][player]" + player.name + "[/player][|][ally]" + player.tribe + "[/ally][|][b]" + player.score + "[/b][|]" + player.index + "\n";
  40. i++;
  41. }
  42. script = script + "[/table][/spoiler]";
  43. console.log(script);
  44. el = document.getElementById("generateRank");
  45. el.insertAdjacentHTML("afterend", '<textarea style="margin-bottom: -12px">'+script+'</textarea>')
  46.  
  47.  
  48. }
  49.  
  50. function getAllPlayers(amount=5, tribes=[], world=138) {
  51. allPlayers = [];
  52. matchPlayers = [];
  53. i = 0;
  54. get = function() { new Promise(function(ok, reject) {
  55. setTimeout(function() { ok("") }, i*5); // bo jeœli za du¿o requestów w jednej chwili to wywala b³¹d
  56. }).then(function(result) {
  57. return new Promise(function(ok, reject) { // musimy zrobiæ to synchronicznie
  58. urlOffset = i*25;
  59. if (urlOffset >= 3025) { console.log("Przestaje szukac (przeszukano 3000 wpisów)"); getTextToPost(matchPlayers); return; } // zapobiegamy infinite-loop
  60. url = 'https://pl'+world+'.plemiona.pl/guest.php?screen=ranking&mode=in_a_day&offset='+urlOffset+'&type=loot_res';
  61. data = $.get(url, function(data){ return data; });
  62. ok(data);
  63. })
  64. }).then(function(data) {
  65. return new Promise(function(ok, reject) {
  66. parser = new DOMParser();
  67. ok([parser, data]);
  68. })
  69. }).then(function(result) {
  70. return new Promise(function(ok, reject) {
  71. doc = result[0].parseFromString(result[1], "text/html"); // tworzymy dokument ze stringa
  72. ok(doc);
  73. });
  74. }).then(function(doc) {
  75. return new Promise(function(ok, reject) {
  76. players = fetchPlayersOnPage(doc);
  77. ok(players);
  78. });
  79. }).then(function(players) {
  80. return new Promise(function(ok, reject) {
  81. matchPlayers = matchPlayers.concat(players.sort(function(a, b) {
  82. return a.index - b.index;
  83. }).filter(player => tribes.includes(player.tribe))); // sortujemy po indeksach i wyrzucamy nie z plemienia
  84. console.log("Mam ju¿ " + matchPlayers.length + " graczy z podanych plemion");
  85. if (matchPlayers.length >= amount) {
  86. matchPlayers.length = amount; // ¿eby by³o dok³adnie ile wynosi amount
  87. getTextToPost(matchPlayers);
  88. }
  89. else {
  90. i++;
  91. get(); // za ma³o, wiêc powtarzamy z kolejn¹ stron¹
  92. }
  93. });
  94. })
  95. }
  96. get();
  97. }
  98.  
  99. function generateRank() {
  100. tribesToGenerate = document.getElementById("tribesInput").value.replace(/\s/g, "").split(",");
  101. amount = parseInt(document.getElementById("amountInput").value)
  102. world = window.location.host.replace("pl", "").replace(".plemiona.pl", "");
  103. console.log(amount, tribesToGenerate, world);
  104. if (tribesToGenerate.length == 0) { return }
  105. if (isNaN(amount) || amount <= 0) { return }
  106. console.log(amount, tribesToGenerate, world)
  107. getAllPlayers(amount, tribesToGenerate, world)
  108. }
  109.  
  110. el = document.getElementById("header_info");
  111. el.insertAdjacentHTML("afterbegin", '<table class="vis" style="margin-bottom: 5px"> <tr> <td>Plemiona: </td> <td> <input id="tribesInput" class="unitsInput" placeholder="np. Family, F@mily, F4mily" style="width: 83px;"> </input> </td> </tr> <tr> <td>IloϾ:</td> <td> <input id="amountInput" class="unitsInput" placeholder="np. 75", style="width: 83px;"> </input> </td> </tr> </table> <button id="generateRank" type="button" onclick="generateRank()" style="margin-bottom: 16px" class="btn"> Generuj </button>')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement