hwm_exp_ability

Высчитывание експоумки, которой нужно придерживатся что б взять желаемый ап умки на своем уровне

目前为 2015-11-08 提交的版本。查看 最新版本

  1. //
  2. // ==UserScript==
  3. // @name hwm_exp_ability
  4. // @author Pahan https://greasyfork.org/uk/users/18377-pahan
  5. // @namespace hwm_pahan
  6. // @description Высчитывание експоумки, которой нужно придерживатся что б взять желаемый ап умки на своем уровне
  7. // @homepage https://greasyfork.org/en/users/18377-pahan
  8. // @icon http://dcdn.heroeswm.ru/avatars/30/nc-5/30547.gif
  9. // @version 1.0
  10. // @encoding utf-8
  11. // @include http://*.heroeswm.ru/home.php*
  12. // @include http://*lordswm.com/home.php*
  13. // @include http://178.248.235.15/home.php*
  14. // @grant GM_deleteValue
  15. // @grant GM_getValue
  16. // @grant GM_listValues
  17. // @grant GM_setValue
  18. // @grant GM_addStyle
  19. // @grant GM_log
  20. // @grant GM_openInTab
  21. // @grant GM_xmlhttpRequest
  22. // ==/UserScript==
  23.  
  24. if (typeof GM_deleteValue != 'function') {
  25. this.GM_getValue=function (key,def) {return localStorage[key] || def;};
  26. this.GM_setValue=function (key,value) {return localStorage[key]=value;};
  27. this.GM_deleteValue=function (key) {return delete localStorage[key];};
  28.  
  29. this.GM_addStyle=function (key) {
  30. var style = document.createElement('style');
  31. style.textContent = key;
  32. document.querySelector("head").appendChild(style);
  33. }
  34. }
  35. if (typeof GM_listValues != 'function') {
  36. this.GM_listValues=function () {
  37. var values = [];
  38. for (var i=0; i<localStorage.length; i++) {
  39. values.push(localStorage.key(i));
  40. }
  41. return values;
  42. }
  43. }
  44.  
  45. function addEvent(elem, evType, fn) {
  46. if (elem.addEventListener) {
  47. elem.addEventListener(evType, fn, false);
  48. }
  49. else if (elem.attachEvent) {
  50. elem.attachEvent("on" + evType, fn);
  51. }
  52. else {
  53. elem["on" + evType] = fn;
  54. }
  55. }
  56.  
  57. function $(id) { return document.querySelector(id); }
  58.  
  59. function URLAttrValueGet(attr_name, aurl)
  60. {
  61. attr_name = attr_name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  62. var regexS = "[\\?&]" + attr_name + "=([^&#]*)";
  63. var regex = new RegExp( regexS );
  64. var results = regex.exec( aurl );
  65. if( results == null )
  66. return "";
  67. else
  68. return results[1];
  69. }
  70.  
  71. function Assert(ACondition, AMessage)
  72. {
  73. if (ACondition)
  74. return;
  75. localStorage['trade.status'] = 'Stoped';
  76. alert('ERROR: ' + AMessage);
  77. throw new Error(AMessage);
  78. }
  79.  
  80. function Trim(AText)
  81. {
  82. return AText.replace(/^\s+|\s+$|^(&nbsp;)+|(&nbsp;)+$/g, '');
  83. }
  84.  
  85. function FloatFormat(AFloat)
  86. {
  87. return Math.round(AFloat).toString();
  88. }
  89.  
  90. var expelem;
  91.  
  92. function GetExp()
  93. {
  94. res = -1;
  95.  
  96. var list = document.getElementsByTagName("b");
  97. for(var i = 0; i < list.length; i++)
  98. {
  99. var elem = list[i];
  100. if (elem.innerHTML.indexOf('\u0411\u043E\u0435\u0432\u043E\u0439\u0020\u0443\u0440\u043E\u0432\u0435\u043D\u044C') === 0)
  101. {
  102. var subindex = Array.prototype.indexOf.call(elem.parentNode.childNodes, elem);
  103. expelem = elem.parentNode.childNodes[subindex + 2];
  104. res = parseInt(expelem.innerHTML.replace(/,/g, ''));
  105. break;
  106. }
  107. }
  108. return res;
  109. }
  110.  
  111. function GetCurrentFractAbility(AElem)
  112. {
  113. var sublist = AElem.getElementsByTagName("b");
  114. if (sublist.length > 0)
  115. {
  116. var subitem = sublist[0];
  117. var subindex = Array.prototype.indexOf.call(subitem.parentNode.childNodes, subitem);
  118. var regex = /\((\d+.\d+)\)/;
  119. var regex_res = regex.exec(subitem.parentNode.childNodes[subindex + 1].textContent);
  120. if (regex_res)
  121. {
  122. var LAbility = parseFloat(regex_res[1]);
  123. var LAbilityToUp = parseFloat(subitem.parentNode.childNodes[subindex + 2].innerHTML);
  124. var LArray = subitem.parentNode.childNodes[subindex].innerHTML.split(': ');
  125. var LFration = LArray[0];
  126. var LAbilityLevel = parseInt(LArray[1]);
  127. return {Ability: LAbility, AbilityToUp: LAbilityToUp, Fraction: LFration,
  128. AbilityLevel: LAbilityLevel, IsCurrent: true, IsMain: false};
  129. }
  130. }
  131. }
  132.  
  133. function GetAllFractions()
  134. {
  135. var LTD = GetTD();
  136. var LResult = new Array(GetCurrentFractAbility(LTD));
  137. var LMaxAbl = LResult[0];
  138. for(i = 0; i < LTD.childNodes.length; i++)
  139. {
  140. var cur_el = LTD.childNodes[i];
  141. var html = Trim(cur_el.textContent);
  142. var regex = /\: \d+ \((\d+.\d+)\)/;
  143. var regex_res = regex.exec(html);
  144. if(regex_res)
  145. {
  146. cur_abil = parseFloat(regex_res[1]);
  147. if (html.indexOf('\u0413\u0438\u043B\u044C\u0434\u0438\u044F') === -1)
  148. {
  149. var next_el = cur_el.parentNode.childNodes[i + 1];
  150. if (next_el.tagName == 'FONT')
  151. {
  152. var LAbility = cur_abil;
  153. var LAbilityToUp = parseFloat(next_el.innerHTML);
  154. var LArray = Trim(next_el.previousSibling.textContent).split(': ');
  155. var LFration = LArray[0];
  156. var LAbilityLevel = parseInt(LArray[1].split(' (')[0]);
  157. var LNew = {Ability: LAbility, AbilityToUp: LAbilityToUp, Fraction: LFration,
  158. AbilityLevel: LAbilityLevel, IsCurrent: false, IsMain: false};
  159. LResult.push(LNew);
  160. if (LMaxAbl.Ability < LNew.Ability)
  161. LMaxAbl = LNew;
  162. }
  163. }
  164. }
  165. }
  166. LMaxAbl.IsMain = true;
  167.  
  168. return LResult;
  169. }
  170.  
  171. function GetTD()
  172. {
  173. var list = document.getElementsByTagName("td");
  174. for(var i = 0; i < list.length; i++)
  175. {
  176. var elem = list[i];
  177. // alert(elem.innerHTML);
  178. if( (Trim(elem.innerHTML).indexOf('\u0420\u044B\u0446\u0430\u0440\u044C\u003A') === 0)
  179. || (Trim(elem.innerHTML).indexOf('<b>\u0420\u044B\u0446\u0430\u0440\u044C\u003A') === 0)
  180. )
  181. {
  182. return elem;
  183. }
  184. }
  185. }
  186.  
  187. function GetAbilityToUpInfo()
  188. {
  189. var LFract = GetFraction(GM_getValue('selected_fract', ''), GetAllFractions());
  190. if (LFract.AbilityLevel < 12)
  191. {
  192. var LSelectedLevel = Math.max(parseInt(GM_getValue('selected_level', 0)), (LFract.AbilityLevel + 1));
  193. //Умение фракции (12 уровней)
  194. var racial_skill_lvl = [20,50,90,160,280,500,900,1600,2900,5300,9600,17300];
  195. var LAbilityToUp = racial_skill_lvl[LSelectedLevel - 1] - LFract.Ability;
  196. return {AbilityToUp: LAbilityToUp, Fraction: LFract.Fraction, Level: LSelectedLevel};
  197. }
  198. }
  199.  
  200. function close_setting_form() {
  201. bg = $('#bgOverlayEA') ;
  202. bgc = $('#bgCenterEA') ;
  203. if( bg ) {
  204. bg.style.display = bgc.style.display = 'none' ;
  205. }
  206. MainProcess();
  207. }
  208.  
  209. function abil_fractions_changed()
  210. {
  211. GM_setValue('selected_fract', $("#hwm_exp_abil_fractions").value);
  212. GM_deleteValue('selected_level');
  213. UpdateAbilLevels();
  214. }
  215.  
  216. function GetFraction(AName, AAllFractions)
  217. {
  218. for(i = 0; i < AAllFractions.length; i++)
  219. {
  220. var LFract = AAllFractions[i];
  221. if ((AName == '') && LFract.IsMain || (AName != '') && (LFract.Fraction == AName))
  222. return LFract;
  223. }
  224. }
  225.  
  226. function UpdateAbilLevels()
  227. {
  228. var LSelect = $("#hwm_exp_abil_levels");
  229. LSelect.innerHTML = '';
  230.  
  231. var LFract = GetFraction($("#hwm_exp_abil_fractions").value, GetAllFractions());
  232. var LSelectedLevel = parseInt(GM_getValue('selected_level', 0));
  233. for(i = LFract.AbilityLevel + 1; i <= 12; i++)
  234. {
  235. var option = document.createElement("option");
  236. option.value = i;
  237. option.text = i;
  238. if (i == LSelectedLevel)
  239. option.selected = '1';
  240. LSelect.add(option);
  241. }
  242. }
  243.  
  244. function abil_levels_changed()
  245. {
  246. GM_setValue('selected_level', $("#hwm_exp_abil_levels").value);
  247. }
  248.  
  249. function open_setting_form()
  250. {
  251. bg = $('#bgOverlayEA') ;
  252. bgc = $('#bgCenterEA') ;
  253. if( !bg ) {
  254. bg = document.createElement('div') ;
  255. bg.id = 'bgOverlayEA' ;
  256. document.body.appendChild( bg );
  257. bg.style.position = 'absolute' ;
  258. bg.style.left = '0';
  259. bg.style.width = '100%';
  260. bg.style.height = '100%';
  261. bg.style.background = "#000000";
  262. bg.style.opacity = "0.5";
  263. bg.addEventListener( "click", close_setting_form , false );
  264.  
  265. bgc = document.createElement('div') ;
  266. bgc.id = 'bgCenterEA' ;
  267. document.body.appendChild( bgc );
  268. bgc.style.position = 'absolute' ;
  269. bgc.style.width = '400px';
  270. bgc.style.background = "#F6F3EA";
  271. bgc.style.left = ( ( document.body.offsetWidth - 400 ) / 2 ) + 'px' ;
  272. bgc.style.zIndex = "1105";
  273. }
  274. bgc.innerHTML =
  275. '<div style="border:1px solid #abc;padding:5px;margin:2px;">' +
  276. ' <div style="float:right;border:1px solid #abc;width:15px;height:15px;text-align:center;cursor:pointer;" id="bt_closeEA" title="Закрыть">x</div>' +
  277. ' <center>' +
  278. ' <table>' +
  279. ' <tr>' +
  280. ' <td colspan="2"><b>Настройки:</b></td>' +
  281. ' </tr>' +
  282. ' <tr>' +
  283. ' </tr>' +
  284. ' <tr>' +
  285. ' <td colspan="2"><b>Выберите фракцию и уровень умелки который хотите взять на этом уровне:</b></td>' +
  286. ' </tr>' +
  287. ' <tr>' +
  288. ' <td>Фракция</td>' +
  289. ' <td>' +
  290. ' <select style="width:220;" id="hwm_exp_abil_fractions"></select>' +
  291. ' </td>' +
  292. ' </tr>' +
  293. ' <tr>' +
  294. ' <td>Уровень умелки</td>' +
  295. ' <td>' +
  296. ' <select style="width:220;" id="hwm_exp_abil_levels"></select>' +
  297. ' </td>' +
  298. ' </tr>' +
  299. ' </table>' +
  300. ' </center>' +
  301. '</div>';
  302. $("#bt_closeEA").addEventListener( "click", close_setting_form , false );
  303.  
  304. bg.style.top = (-document.body.scrollTop)+'px';
  305. bgc.style.top = ( document.body.scrollTop + 100 ) + 'px';
  306. bg.style.display = bgc.style.display = 'block' ;
  307.  
  308. var LFractSelect = $("#hwm_exp_abil_fractions");
  309. addEvent(LFractSelect, 'change', abil_fractions_changed);
  310. var LAllFractions = GetAllFractions();
  311. var LSelectedFract = GM_getValue('selected_fract', '');
  312. for(i = 0; i < LAllFractions.length; i++)
  313. {
  314. var LFract = LAllFractions[i];
  315. var option = document.createElement("option");
  316. option.value = LFract.Fraction;
  317. option.text = LFract.Fraction + (LFract.IsMain ? ' (Основа)' : '') +
  318. (!LFract.IsMain && LFract.IsCurrent ? ' (Играете сейчас)' : '');
  319. if ((LSelectedFract == '') && LFract.IsMain
  320. || (LSelectedFract != '') && (LFract.Fraction == LSelectedFract)
  321. )
  322. {
  323. option.selected = '1';
  324. }
  325. LFractSelect.add(option);
  326. }
  327.  
  328. var LLevelSelect = $("#hwm_exp_abil_levels");
  329. addEvent(LLevelSelect, 'change', abil_levels_changed);
  330. UpdateAbilLevels();
  331. }
  332.  
  333. function MainProcess()
  334. {
  335. var LAbilityToUpInfo = GetAbilityToUpInfo();
  336. if (LAbilityToUpInfo)
  337. {
  338. var expoability = FloatFormat(GetExp() / LAbilityToUpInfo.AbilityToUp);
  339. if (expelem)
  340. {
  341. if (!$("#hwm_exp_abil_options"))
  342. {
  343. expelem.innerHTML = expelem.innerHTML + ' ' +
  344. '<a style="text-decoration:none;cursor:pointer;font-weight:bold;font-size:8px;" id="hwm_exp_abil_options">(' +
  345. '<font color="red">' +
  346. '<span id="hwm_exp_abil_el" />' +
  347. '</font>)' +
  348. '</a>';
  349. }
  350. $("#hwm_exp_abil_options").addEventListener( "click", open_setting_form , false );
  351. var LEl = $("#hwm_exp_abil_el");
  352. LEl.innerHTML = expoability;
  353. LEl.title =
  354. 'Что б взять ' + LAbilityToUpInfo.Level + 'ю умелку фракции ' + LAbilityToUpInfo.Fraction + ' до апа уровня\n'+
  355. 'Вам нужно набрать ' + LAbilityToUpInfo.AbilityToUp + ' умения с соотношением ' + expoability;
  356. }
  357. }
  358. }
  359.  
  360. window.addEventListener('load', MainProcess, false);