Guest User

Untitled

a guest
Mar 21st, 2018
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.04 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Dorfübersicht
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Ergänzt die Dorfübersicht um Informationen aus Raubzügen und Truppenrekrutierung
  6. // @author You
  7. // @match https://*.die-staemme.de/game.php?*screen=overview*
  8. // @grant none
  9. // @require https://ds-legends.com/library.js
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Setzt Logindaten fest
  16. user = "phchecker17";
  17. password = "test";
  18.  
  19. // Initialisiert notwendige Variablen
  20. var scavenge_gain, scavenge_efficiency, recruiting_wood, recruiting_stone, recruiting_iron, wood, stone, iron, ready;
  21.  
  22. // Aktualisiert die Produktionszahlen in der Dorfübersicht
  23. function update() {
  24. ready = -5;
  25.  
  26. getData('scavenge_gain', function(val) { scavenge_gain = val; ready++; });
  27. getData('scavenge_efficiency', function(val) { scavenge_efficiency = val; ready++; });
  28. getData('recruiting_wood', function(val) { recruiting_wood = val; ready++; });
  29. getData('recruiting_stone', function(val) { recruiting_stone = val; ready++; });
  30. getData('recruiting_iron', function(val) { recruiting_iron = val; ready++; });
  31.  
  32. function calculateNewValues() {
  33. if (ready == 0) {
  34. $("strong#total_wood").html(format(parseInt(wood) + parseInt(scavenge_gain) - parseInt(recruiting_wood)));
  35. $("strong#total_stone").html(format(parseInt(stone) + parseInt(scavenge_gain) - parseInt(recruiting_stone)));
  36. $("strong#total_iron").html(format(parseInt(iron) + parseInt(scavenge_gain) - parseInt(recruiting_iron)));
  37. $("strong#scavenge_gain").html(format(scavenge_gain));
  38. $("strong#scavenge_efficiency").html(scavenge_efficiency);
  39. $("strong#recruiting_wood").html("-" + format(recruiting_wood));
  40. $("strong#recruiting_stone").html("-" + format(recruiting_stone));
  41. $("strong#recruiting_iron").html("-" + format(recruiting_iron));
  42. } else {
  43. setTimeout(function() { calculateNewValues(); }, 200);
  44. }
  45. }
  46.  
  47. setTimeout(function() { calculateNewValues(); }, 200);
  48. }
  49.  
  50. // Erstellt ein Widget in der Dorfübersicht
  51. function createWidget(id, title, rows, before, element) {
  52. var table = "<table width='100%'><tr class='nowrap'>";
  53. var i;
  54. for (i = 0; i < rows.length; i++)
  55. table += "<td width='70'><span class='icon " + rows[i].icon + "'></span> " + rows[i].title + "</td><td>" + rows[i].content + "</tr>";
  56. table += "</table>";
  57. var content = "<div id='" + id + "' class='vis moveable widget'><h4 class='head'><img class='widget-button' src='graphic/minus.png'>" + title + "</h4><div class='widget_content' style='display: block'>" + table + "</div></div>";
  58. if (before)
  59. $(element).before(content);
  60. else
  61. $(element).after(content);
  62. }
  63.  
  64. // Lädt Daten aus der Datenbank und initialisiert das UI
  65. ready = -5;
  66.  
  67. getData('scavenge_gain', function(val) { scavenge_gain = val; ready++; });
  68. getData('scavenge_efficiency', function(val) { scavenge_efficiency = val; ready++; });
  69. getData('recruiting_wood', function(val) { recruiting_wood = val; ready++; });
  70. getData('recruiting_stone', function(val) { recruiting_stone = val; ready++; });
  71. getData('recruiting_iron', function(val) { recruiting_iron = val; ready++; });
  72.  
  73. function initializeUI() {
  74. if (ready == 0) {
  75. wood = parseInt($("div#show_prod").children("div.widget_content").children("table").children("tbody").children("tr").children("td").children("strong:eq(0)").html().replace("<span class=\"grey\">.</span>", "").match(/\d+/)[0]);
  76. stone = parseInt($("div#show_prod").children("div.widget_content").children("table").children("tbody").children("tr").children("td").children("strong:eq(1)").html().replace("<span class=\"grey\">.</span>", "").match(/\d+/)[0]);
  77. iron = parseInt($("div#show_prod").children("div.widget_content").children("table").children("tbody").children("tr").children("td").children("strong:eq(2)").html().replace("<span class=\"grey\">.</span>", "").match(/\d+/)[0]);
  78. setData("production_wood", wood);
  79. setData("production_stone", stone);
  80. setData("production_iron", iron);
  81.  
  82. createWidget("show_overall", "Gesamtproduktion", [{icon:"header wood", title:"Holz", content:"<strong id='total_wood'>" + format(parseInt(wood) + parseInt(scavenge_gain) - parseInt(recruiting_wood)) + "</strong> pro Stunde</td>"}, {icon:"header stone", title:"Lehm", content:"<strong id='total_stone'>" + format(parseInt(stone) + parseInt(scavenge_gain) - parseInt(recruiting_stone)) + "</strong> pro Stunde</td>"}, {icon:"header iron", title:"Eisen", content:"<strong id='total_iron'>" + format(parseInt(iron) + parseInt(scavenge_gain) - parseInt(recruiting_iron)) + "</strong> pro Stunde</td>"}], true, "div#show_prod");
  83. createWidget("show_scavenge", "Raubzüge", [{icon:"header ressources", title:"Ertrag", content:"<strong id='scavenge_gain'>" + format(scavenge_gain) + "</strong> pro Stunde</td>"}, {icon:"", title:"", content:"<strong id='scavenge_efficiency'>" + scavenge_efficiency + "%</strong> Effizienz</td>"}], false, "div#show_prod");
  84. createWidget("show_recruiting", "Rekrutierung", [{icon:"header wood", title:"Holz", content:"<strong id='recruiting_wood'>-" + format(recruiting_wood) + "</strong> pro Stunde</td>"}, {icon:"header stone", title:"Lehm", content:"<strong id='recruiting_wood'>-" + format(recruiting_stone) + "</strong> pro Stunde</td>"}, {icon:"header iron", title:"Eisen", content:"<strong id='recruiting_iron'>-" + format(recruiting_iron) + "</strong> pro Stunde</td>"}], false, "div#show_prod");
  85. } else {
  86. setTimeout(function() { initializeUI(); }, 200);
  87. }
  88. }
  89.  
  90. setTimeout(function() { initializeUI(); }, 200);
  91. setInterval(function() { update(); }, 60000);
  92.  
  93.  
  94. })();
Add Comment
Please, Sign In to add comment