hwmResoursesAsImages

Ресурсы и части в картинках

  1. // ==UserScript==
  2. // @name hwmResoursesAsImages
  3. // @namespace hwmResoursesAsImages
  4. // @description Ресурсы и части в картинках
  5. // @author raTaHoa; Чеширский КотЪ; code: Dinozon2, ElMarado; style: sw.East
  6. // @version 4.7
  7. // @include https://www.heroeswm.ru/pl_info.php*
  8. // @include https://www.lordswm.com/pl_info.php*
  9. // @include http://178.248.235.15/pl_info.php*
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. addStyle (`
  14. .resourceSlot{
  15. overflow: hidden;
  16. float: left;
  17. width: 48px;
  18. height: 48px;
  19. margin: 4px 4px 4px 0;
  20. padding: 0;
  21. border: 4px solid #fff;
  22. box-shadow: 0px 0px 5px #aaa;
  23. z-index: 1;
  24. }
  25. .resourceSlot img {
  26. display: block;
  27. width: 42px;
  28. height: 42px;
  29. margin: 3px 0 0 3px;
  30. padding: 0;
  31. }
  32. .resourceSlot a img {
  33. -webkit-transition: all 0.2s linear;
  34. -moz-transition: all 0.2s linear;
  35. -ms-transition: all 0.2s linear;
  36. -o-transition: all 0.2s linear;
  37. transition: all 0.2s linear;
  38. }
  39. .resourceSlot:hover a img {
  40. -webkit-transform: scale(1.20,1.20);
  41. -moz-transform: scale(1.20,1.20);
  42. -ms-transform: scale(1.20,1.20);
  43. -o-transform: scale(1.10,1.20);
  44. transform: scale(1.20,1.20);
  45. opacity:1;
  46. }
  47. .resourceSlot a{
  48. text-decoration: none;
  49. }
  50. .amountSlot {
  51. position: absolute;
  52. min-width: 14px;
  53. height: 13px;
  54. margin: -48px 0 0 -3px;
  55. padding: 0 1px 1px;
  56. color: #fff;
  57. border: 2px solid #fff;
  58. background: #222;
  59. -webkit-box-shadow: 1px 1px 1px #aaa;
  60. -moz-box-shadow: 1px 1px 1px #aaa;
  61. box-shadow: 1px 1px 1px #aaa;
  62. z-index: 15;
  63. font-size: 10px;
  64. text-align: center;
  65. text-decoration: none !important;
  66. text-shadow: 1px 1px 1px rgba(0,0,0, 0.8);
  67. cursor: pointer;
  68. opacity: .7;
  69. -webkit-transition: opacity 0.4s ease-in-out, visibility 0.4s ease-in-out;
  70. -moz-transition: opacity 0.4s ease-in-out, visibility 0.4s ease-in-out;
  71. -ms-transition: opacity 0.4s ease-in-out, visibility 0.4s ease-in-out;
  72. -o-transition: opacity 0.4s ease-in-out, visibility 0.4s ease-in-out;
  73. transition: opacity 0.4s ease-in-out, visibility 0.4s ease-in-out;
  74. }` );
  75. const ElementsArray = {
  76. "Сапоги страха": "part_fear_boots",
  77. "Роба страха": "part_fear_bonearmour",
  78. "Коса страха": "part_fear_scythe",
  79. "Плащ страха": "part_fear_cloack",
  80. "Амулет страха": "part_fear_amulk",
  81. "Щит страха": "part_fear_shield",
  82. "Фонарь страха": "part_fear_lantern",
  83. "Серп страха": "part_fear_sickle",
  84. "Лук страха": "part_fear_bow",
  85. "Маска страха": "part_fear_maska",
  86. "Магма меч": "part_magma_swrd",
  87. "Магма шлем": "part_magma_helm",
  88. "Магма кулон": "part_magma_pend",
  89. "Магма кольцо": "part_magma_rd",
  90. "Магма доспех": "part_magma_armor",
  91. "Магма плащ": "part_magma_clc",
  92. "Магма арбалет": "part_magma_arb",
  93. "Магма сапоги": "part_magma_boots",
  94. "Магма щит": "part_magma_lshield",
  95. "Магма кинжал": "part_magma_dagger",
  96. "Небесный посох": "part_heaven_staff",
  97. "Небесная диадема": "part_heaven_helm",
  98. "Небесные сандалии": "part_heaven_bts",
  99. "Небесный доспех": "part_heaven_armr",
  100. "Небесная мантия": "part_heaven_clk",
  101. "Небесный лук": "part_heaven_bow",
  102. "Небесный щит": "part_heaven_shield",
  103. "Небесный амулет": "part_heaven_amlt",
  104. "Небесное кольцо": "part_heaven_rn",
  105. "Небесный кинжал": "part_heaven_dagger",
  106. // *** Артефакты тьмы
  107. 'Амулет тьмы': 'part_dark_amul',
  108. 'Доспех тьмы': 'part_dark_armor',
  109. 'Меч тьмы': 'part_dark_sword',
  110. 'Сапоги тьмы': 'part_dark_boots',
  111. 'Топор тьмы': 'part_dark_axe',
  112. 'Шлем тьмы': 'part_dark_helmet',
  113. 'Щит тьмы': 'part_dark_shield',
  114. 'Плащ тьмы': 'part_dark_cloak',
  115. 'Кинжал тьмы': 'part_dark_dagger',
  116. 'Кольцо тьмы': 'part_dark_ring',
  117. 'Лук тьмы': 'part_dark_bow',
  118. // *** Имперские артефакты
  119. 'Имперский амулет': 'part_imp_amul',
  120. 'Имперский арбалет': 'part_imp_crossbow',
  121. 'Имперский доспех': 'part_imp_armor',
  122. 'Имперский кинжал': 'part_imp_dagger',
  123. 'Имперское кольцо': 'part_imp_ring',
  124. 'Имперский меч': 'part_imp_sword',
  125. 'Имперский плащ': 'part_imp_cloak',
  126. 'Имперские сапоги': 'part_imp_boots',
  127. 'Имперский шлем': 'part_imp_helmet',
  128. 'Имперский щит': 'part_imp_shield',
  129. // *** Части Гильдии Лидеров
  130. 'Части редкого отряда': 'https://dcdn.heroeswm.ru/i/rewards/gn/task3.png',
  131. 'Частей редкого отряда': 'https://dcdn.heroeswm.ru/i/rewards/gn/task3.png',
  132. 'Части очень редкого отряда': 'https://dcdn.heroeswm.ru/i/rewards/gn/task4.png',
  133. 'Частей очень редкого отряда':'https://dcdn.heroeswm.ru/i/rewards/gn/task4.png',
  134. 'Части таинственного свитка': 'https://i.imgur.com/38VoKxQ.png',
  135. // *** Элементы Гильдии Наёмников
  136. 'Абразив': 'abrasive',
  137. 'Змеиный яд': 'snake_poison',
  138. 'Клык тигра': 'tiger_tusk',
  139. 'Ледяной кристалл': 'ice_crystal',
  140. 'Лунный камень': 'moon_stone',
  141. 'Огненный кристалл': 'fire_crystal',
  142. 'Осколок метеорита': 'meteorit',
  143. 'Цветок ведьм': 'witch_flower',
  144. 'Цветок ветров': 'wind_flower',
  145. 'Цветок папоротника': 'fern_flower',
  146. 'Ядовитый гриб': 'badgrib',
  147. // *** Элементы с предприятий
  148. 'Кожа': 'https://i.imgur.com/Xn82L25.png',
  149. 'Сталь': 'https://i.imgur.com/hwThTJE.png',
  150. 'Никель': 'https://i.imgur.com/6lHniay.png',
  151. 'Волшебный порошок': 'https://i.imgur.com/IuqF7rI.png',
  152. 'Мифриловая руда': 'https://i.imgur.com/dv6rzKn.png',
  153. 'Обсидиан': 'https://i.imgur.com/4yOWbK8.png',
  154. 'Мифрил': 'https://i.imgur.com/1Y1Z7Mq.png',
  155. 'Орихалк': 'https://i.imgur.com/qRGZzCs.png'
  156. };
  157.  
  158. main();
  159. function main() {
  160. const resourcesPanel = getResourcesPanel();
  161. if(!resourcesPanel) {
  162. return;
  163. }
  164. const parsedResourcesInfo = getParsedResourcesInfo(resourcesPanel);
  165. for(const resource of parsedResourcesInfo) {
  166. if(resource.Amount > 0) {
  167. let resourceCode = ElementsArray[resource.Name];
  168. if(!resourceCode) {
  169. continue;
  170. }
  171. const toolTip = `${resource.Name}: ${resource.Amount}`;
  172. let html;
  173. if(resourceCode.startsWith("https")) {
  174. html = `<a href="#"><img src="${resourceCode}" alt="${toolTip}" title="${toolTip}"></a>`;
  175. } else {
  176. let artCategory;
  177. let imageSource;
  178. if(isArtPart(resource.Name)) {
  179. artCategory = "part";
  180. imageSource = `/i/artifacts/parts/${resourceCode}.png`;
  181. } else {
  182. artCategory = "elements";
  183. imageSource = `/i/gn_res/${resourceCode}.png?v=0`;
  184. }
  185. html = `<a href="/auction.php?cat=${artCategory}&sort=0&art_type=${resourceCode}"><img src="${imageSource}" alt="${toolTip}" title="${toolTip}"></a>`;
  186. }
  187. let amountDivWidth = Math.max(15, Math.ceil(getNumberLength(resource.Amount) * 7.5));
  188. //console.log(`resource.Amount: ${resource.Amount}, amountDivWidth: ${amountDivWidth}`);
  189. html += `<div class="amountSlot" style="width: ${amountDivWidth}px">${resource.Amount}</div>`;
  190. if(resource.TextNode.nextSibling && resource.TextNode.nextSibling.tagName.toLowerCase() == "br") {
  191. resource.TextNode.nextSibling.remove();
  192. }
  193. resource.TextNode.replaceWith(createElement("div", { class: "resourceSlot", innerHTML: html }));
  194. }
  195. }
  196. }
  197. function isArtPart(name) { return name.includes('Импер') || name.includes('Магма') || name.includes('тьмы') || name.includes('Небесн') || name.includes('трах'); }
  198. function getParsedResourcesInfo(resourcesPanel) {
  199. const walker = document.createTreeWalker(resourcesPanel, NodeFilter.SHOW_TEXT);
  200. let textNodes = [];
  201. while(walker.nextNode()) {
  202. textNodes.push(walker.currentNode)
  203. }
  204. textNodes = textNodes.map(x => [x, x.textContent.replace("\n", "").trimStart()]).filter(x => x[1] != "" && !x[1].includes("function")).map(x => { return { TextNode: x[0], Name: x[1].split(":")[0], Amount: parseInt(x[1].split(":")[1].replace(/,/g, "")) }; });
  205. //console.log(textNodes);
  206. return textNodes;
  207. }
  208. function getResourcesPanel() {
  209. const tables = document.querySelectorAll("table.wblight");
  210. for(const table of tables) {
  211. const bolds = table.querySelectorAll("b");
  212. for(const bold of bolds) {
  213. if(bold.innerText == "Ресурсы") {
  214. return table.rows[1].cells[0];
  215. }
  216. }
  217. }
  218. }
  219. function getNumberLength(number) { return number.toString().length; }
  220. function addElement(type, parent, data) {
  221. let el = createElement(type, data);
  222. if(parent) {
  223. parent.appendChild(el);
  224. }
  225. return el;
  226. }
  227. function createElement(type, data) {
  228. let el = document.createElement(type);
  229. if(data) {
  230. for(let key in data) {
  231. if(key == "innerText" || key == "innerHTML") {
  232. el[key] = data[key];
  233. } else {
  234. el.setAttribute(key, data[key]);
  235. }
  236. }
  237. }
  238. return el;
  239. }
  240. function addStyle(css) { addElement("style", document.head, { type: "text/css", innerHTML: css }); }
  241.