Eternity Tower Mining Details

Adds mining details to the UI for the Eternity Tower game

  1. // ==UserScript==
  2. // @name Eternity Tower Mining Details
  3. // @icon https://www.eternitytower.net/favicon.png
  4. // @namespace http://mean.cloud/
  5. // @version 1.04
  6. // @description Adds mining details to the UI for the Eternity Tower game
  7. // @match http*://*.eternitytower.net/*
  8. // @copyright 2017, MeanCloud
  9. // @run-at document-end
  10. // ==/UserScript==
  11.  
  12. function addJQuery(callback)
  13. {
  14. var script = document.createElement("script");
  15. script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js");
  16. script.addEventListener('load', function()
  17. {
  18. var script = document.createElement("script");
  19. script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();";
  20. document.body.appendChild(script);
  21. }, false);
  22. document.body.appendChild(script);
  23. }
  24.  
  25. function main()
  26. {
  27. jQ("head").append
  28. (
  29. "<style type=\"text/css\">\r\n" +
  30. ".ET_tooltip {\r\n" +
  31. " position: relative;\r\n" +
  32. " display: inline-block;\r\n" +
  33. "}\r\n" +
  34. "\r\n" +
  35. ".ET_tooltip .ET_tooltiptext {\r\n" +
  36. " visibility: hidden;\r\n" +
  37. " width: 120px;\r\n" +
  38. " background-color: #555;\r\n" +
  39. " color: #fff;\r\n" +
  40. " text-align: center;\r\n" +
  41. " border-radius: 6px;\r\n" +
  42. " padding: 5px 0;\r\n" +
  43. " position: absolute;\r\n" +
  44. " z-index: 1;\r\n" +
  45. " bottom: 125%;\r\n" +
  46. " left: 50%;\r\n" +
  47. " margin-left: -60px;\r\n" +
  48. " opacity: 0;\r\n" +
  49. " transition: opacity 1s;\r\n" +
  50. "}\r\n" +
  51. "\r\n" +
  52. ".ET_tooltip .ET_tooltiptext::after {\r\n" +
  53. " content: \"\";\r\n" +
  54. " position: absolute;\r\n" +
  55. " top: 100%;\r\n" +
  56. " left: 50%;\r\n" +
  57. " margin-left: -5px;\r\n" +
  58. " border-width: 5px;\r\n" +
  59. " border-style: solid;\r\n" +
  60. " border-color: #555 transparent transparent transparent;\r\n" +
  61. "}\r\n" +
  62. "\r\n" +
  63. ".ET_tooltip:hover .ET_tooltiptext {\r\n" +
  64. " visibility: visible;\r\n" +
  65. " opacity: 1;\r\n" +
  66. "</style>\r\n" +
  67. "}\r\n"
  68. );
  69.  
  70. // Set background tasks
  71. setTimeout(document.ET_fnRender, 1000);
  72. }
  73.  
  74. document.ET_fnRender = function()
  75. {
  76. Meteor.connection._stream.on('message', function(sMeteorRawData)
  77. {
  78. try
  79. {
  80. var oMeteorData = JSON.parse(sMeteorRawData);
  81. //console.log('collcetions: ' + oMeteorData.collection);
  82.  
  83. if (oMeteorData.collection == "mining")
  84. {
  85. //console.log(oMeteorData.collection);
  86. document.ET_Stat_UserMiningAttack = oMeteorData.fields.stats.attack;
  87. }
  88.  
  89. }
  90. catch (err) { }
  91. });
  92.  
  93. jQ(".ET_extradetails").remove();
  94.  
  95. jQ("div.mine-space-container").css("backgroundColor", "");
  96.  
  97. jQ("div.mine-space-container > img").each(function()
  98. {
  99. function trim(str, charlist)
  100. {
  101. charlist = !charlist ? " \s\r\n\t\xA0\x0B\0" :
  102. charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, "\$1");
  103.  
  104. var re = new RegExp("^[" + charlist + "]+|[" + charlist + "]+$", "g");
  105.  
  106. return str.replace(re, '');
  107. }
  108. var oParent = jQ(this).parent();
  109. var sHTML = oParent.html();
  110.  
  111. var iCurDmgMining = document.ET_Stat_UserMiningAttack;
  112.  
  113. var sType = document.ChopperBlank(sHTML, "/icons/", ".");
  114. var sSpanVal = document.ChopperBlank(sHTML, '<span style="font-size: 12px; white-space: nowrap">', '</span>');
  115. var sHealth = trim(sSpanVal.split(' / ')[0]);
  116. sHealth = sHealth.indexOf('k')!=-1 ? parseInt(parseFloat(sHealth.substring(0, sHealth.length - 1))*1000) : parseInt(sHealth);
  117. var sMaxHealth = trim(sSpanVal.split(' / ')[1]);
  118. sMaxHealth = sMaxHealth.indexOf('k')!=-1 ? parseInt(parseFloat(sMaxHealth.substring(0, sMaxHealth.length - 1))*1000) : parseInt(sMaxHealth);
  119. //console.log(oDmgMining.html());
  120.  
  121. if (sType.length > 0)
  122. {
  123. if (sType.indexOf("Cluster") !== -1)
  124. sType = document.ChopperBlank(sType, "", "Cluster");
  125.  
  126. sType = sType.toLowerCase();
  127.  
  128. if (sType == "gem") sType = "GEM";
  129. else if (sType == "stone") sType = "STONE";
  130. else if (sType == "copper") sType = "COPPER";
  131. else if (sType == "coal") sType = "COAL";
  132. else if (sType == "tin") sType = "TIN";
  133. else if (sType == "bronze") sType = "BRONZE";
  134. else if (sType == "iron") sType = "IRON";
  135. else if (sType == "silver") sType = "SILVER";
  136. else if (sType == "gold") sType = "GOLD";
  137. else if (sType == "carbon") sType = "CARBON";
  138. else if (sType == "steel") sType = "STEEL";
  139. else if (sType == "platinum") sType = "PLATINUM";
  140. else if (sType == "titanium") sType = "TITANIUM";
  141. else if (sType == "tungsten") sType = "TUNGSTEN";
  142. else if (sType == "obsidian") sType = "OBSIDIAN";
  143. else if (sType == "cobalt") sType = "COBALT";
  144.  
  145. else if (sType == "silveressence") sType = "ESSENCE (silver)";
  146. else if (sType == "goldessence") sType = "ESSENCE (gold)";
  147. else if (sType == "carbonessence") sType = "ESSENCE (carbon)";
  148. else if (sType == "steelessence") sType = "ESSENCE (steel)";
  149. else if (sType == "platinumessence") sType = "ESSENCE (platinum)";
  150. else if (sType == "titaniumessence") sType = "ESSENCE (titanium)";
  151. else if (sType == "tungstenessence") sType = "ESSENCE (tungsten)";
  152. else if (sType == "obsidianessence") sType = "ESSENCE (obsidian)";
  153. else if (sType == "cobaltessence") sType = "ESSENCE (cobalt)";
  154.  
  155. else if (sType == "jade") sType = "GEM (jade)";
  156. else if (sType == "lapis") sType = "GEM (lapis)";
  157. else if (sType == "sapphire") sType = "GEM (sapphire)";
  158. else if (sType == "ruby") sType = "GEM (ruby)";
  159. else if (sType == "emerald") sType = "GEM (emerald)";
  160.  
  161. else sType = sType.toUpperCase();
  162.  
  163. oParent.append("<div class=\"ET_extradetails\" style=\"font-size: 10px; margin-top: -14px; margin-bottom: 4px;\"><br />" + sType + "</div>");
  164.  
  165. if (sType == "GEM") oParent.css("backgroundColor", "#e7cff7");
  166. else if (sHealth < iCurDmgMining) oParent.css("backgroundColor", "#05a3a3");
  167. else if (sHealth < (iCurDmgMining*10)) oParent.css("backgroundColor", "RGB("+(125-(((sHealth/iCurDmgMining)/10)*125)+130)+", 0, 0)");
  168. //else if (sHealth < 30) oParent.css("backgroundColor", "#d3d1d6");
  169. //else if (sType == "STONE") oParent.css("backgroundColor", "#d3d1d6");
  170. //else if (sType == "COAL") oParent.css("backgroundColor", "#b9b4b2");
  171. else if (sType.indexOf("ESSENSE") !== -1) oParent.css("backgroundColor", "#f9e9c7");
  172. else if (sType.indexOf("GEM (") !== -1) oParent.css("backgroundColor", "#ccf9c7");
  173. }
  174. });
  175.  
  176. setTimeout(document.ET_fnRender, 1000);
  177. };
  178.  
  179. document.ChopperBlank = function (sText, sSearch, sEnd)
  180. {
  181. var sIntermediate = "";
  182.  
  183. if (sSearch === "")
  184. sIntermediate = sText.substring(0, sText.length);
  185. else
  186. {
  187. var iIndexStart = sText.indexOf(sSearch);
  188. if (iIndexStart === -1)
  189. return "";
  190.  
  191. sIntermediate = sText.substring(iIndexStart + sSearch.length);
  192. }
  193.  
  194. if (sEnd === "")
  195. return sIntermediate;
  196.  
  197. var iIndexEnd = sIntermediate.indexOf(sEnd);
  198.  
  199. return (iIndexEnd === -1) ? sIntermediate : sIntermediate.substring(0, iIndexEnd);
  200. };
  201.  
  202. addJQuery(main);