Greasy Fork 支持简体中文。

hwm_price_for_one_battle

shows price for 1 battle from shop, market and map

  1. // ==UserScript==
  2. // @name hwm_price_for_one_battle
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @author Лосось
  6. // @description shows price for 1 battle from shop, market and map
  7. // @match /^https{0,1}:\/\/((www|qrator|my)\.(heroeswm|lordswm)\.(ru|com)|178\.248\.235\.15)\/(art_info).php*/
  8. // @include /^https{0,1}:\/\/((www|qrator|my)\.(heroeswm|lordswm)\.(ru|com)|178\.248\.235\.15)\/(art_info).php*/
  9. // @license MIT
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15. let query = '&sort=204&type=0&'
  16.  
  17. const createElement = (el, style, innerText) => {
  18. let element = document.createElement(el);
  19. if (style) element.style = style;
  20. if (innerText) element.innerText = innerText;
  21. return element;
  22. }
  23.  
  24. let tables = [...document.getElementsByTagName('table')];
  25. let amount = tables[tables.length - 1].innerText;
  26. let shopStrength = Number(document.getElementsByClassName('s_art_inside')[0].innerText.match(/прочность: \d+/gi)[0].match(/\d+/gi).join(''));
  27. amount = Number(amount.replace(',',''))*1.05;
  28.  
  29. let infoBlockHtml = document.getElementById('set_mobile_max_width');
  30.  
  31. let myInfoBlock = createElement('div');
  32. let amountInfoSpan = createElement('div', '', `Цена за бой в магазине ${Math.round(amount / shopStrength)}`);
  33.  
  34. myInfoBlock.appendChild(amountInfoSpan);
  35.  
  36. infoBlockHtml.insertBefore(myInfoBlock, infoBlockHtml.lastElementChild);
  37.  
  38. let links = document.querySelectorAll('.art_info_left_block')[0].lastElementChild;
  39. links = [...links.getElementsByTagName('a')];
  40. let linkToMarket;
  41. let linkToMap;
  42. links.forEach(el => {
  43. if (el.innerText.trim() === 'На рынке') {
  44. linkToMarket = el.href;
  45. } else if (el.innerText.trim() === 'На карте') {
  46. linkToMap = el.href;
  47. }
  48. })
  49. linkToMarket = linkToMarket.split('&');
  50. linkToMarket.splice(1, 0, query);
  51. linkToMarket = linkToMarket.join('');
  52.  
  53. const getMarket = (doc) => {
  54. let priceBlock = doc.getElementsByClassName('wbwhite')[0];
  55. let price = Number(priceBlock.getElementsByTagName('table')[3].getElementsByTagName('td')[1].innerText.replace(',', ''));
  56. let strength = Number(priceBlock.getElementsByTagName('table')[1].getElementsByTagName('td')[1].innerText.match(/Прочность: .+/gi)[0].match(/\d+/gi)[0]);
  57. let priceForOneBattle = createElement('div', '', `Цена за бой на рынке ${Math.round(price / strength)}`);
  58. myInfoBlock.appendChild(priceForOneBattle);
  59. }
  60.  
  61. const getMap = (doc) => {
  62. let table = doc.getElementById('global_table_div');
  63. let amount = Number(table.getElementsByTagName('tbody')[0].firstChild.lastChild.innerText.trim().replace(',', ''));
  64. let priceForOneBattle = createElement('div', '', `Цена за бой на предприятии ${Math.round(amount / shopStrength)}`);
  65. myInfoBlock.appendChild(priceForOneBattle);
  66. }
  67.  
  68. const fetchXml = (link, callback) => {
  69. if (!link) return;
  70. const xhr = new XMLHttpRequest();
  71. xhr.open('get', link);
  72. xhr.setRequestHeader('Content-type', 'text/html; charset=windows-1251');
  73. if (xhr.overrideMimeType) {
  74. xhr.overrideMimeType('text/html; charset=windows-1251');
  75. }
  76.  
  77. xhr.addEventListener('load', () => {
  78. let parser = new DOMParser();
  79. let doc = parser.parseFromString(xhr.responseText, "text/html");
  80. callback(doc);
  81. })
  82. xhr.send();
  83. }
  84. fetchXml(linkToMarket, getMarket);
  85. fetchXml(linkToMap, getMap)
  86.  
  87. })();