HWM_HuntingExpirience

Показывает опыт для охоты, автопропуск, настройки для перекачей

  1. // ==UserScript==
  2. // @name HWM_HuntingExpirience
  3. // @author Pahan https://greasyfork.org/uk/users/18377-pahan
  4. // @namespace hwm_pahan
  5. // @description Показывает опыт для охоты, автопропуск, настройки для перекачей
  6. // @homepage https://greasyfork.org/uk/scripts/13235-hwm-huntingexpirience
  7. // @icon http://dcdn.heroeswm.ru/avatars/30/nc-5/30547.gif
  8. // @version 1.52
  9. // @encoding utf-8
  10. // @include http://*heroeswm.ru/home.php*
  11. // @include http://*heroeswm.ru/map.php*
  12. // @include http://*heroeswm.ru/transfer.php*
  13. // @grant GM_deleteValue
  14. // @grant GM_getValue
  15. // @grant GM_listValues
  16. // @grant GM_setValue
  17. // @grant GM_addStyle
  18. // @grant GM_log
  19. // @grant GM_openInTab
  20. // @grant GM_xmlhttpRequest
  21. // ==/UserScript==
  22.  
  23. var version = '1.52';
  24. var str_url = 'https://greasyfork.org/uk/scripts/13235-hwm-huntingexpirience';
  25. var str_script_name = 'Опыт и умка ГО';
  26. var str_url_aut = '/sms-create.php?mailto=Pahan&subject=Скрипт: '+str_script_name+' v'+version+'. Найдена ошибка:';
  27. var str_url_sps = '/transfer.php?pahan_sps=' + encodeURIComponent('Подарок. Спасибо за скрипт: '+str_script_name+' v'+version+'.');
  28.  
  29. if (typeof GM_deleteValue != 'function') {
  30. this.GM_getValue=function (key,def) {return localStorage[key] || def;};
  31. this.GM_setValue=function (key,value) {return localStorage[key]=value;};
  32. this.GM_deleteValue=function (key) {return delete localStorage[key];};
  33.  
  34. this.GM_addStyle=function (key) {
  35. var style = document.createElement('style');
  36. style.textContent = key;
  37. document.querySelector("head").appendChild(style);
  38. }
  39. }
  40. if (typeof GM_listValues != 'function') {
  41. this.GM_listValues=function () {
  42. var values = [];
  43. for (var i=0; i<localStorage.length; i++) {
  44. values.push(localStorage.key(i));
  45. }
  46. return values;
  47. }
  48. }
  49.  
  50. function addEvent(elem, evType, fn) {
  51. // elem["on" + evType] = fn;
  52. if (elem.addEventListener) {
  53. elem.addEventListener(evType, fn, false);
  54. }
  55. else if (elem.attachEvent) {
  56. elem.attachEvent("on" + evType, fn);
  57. }
  58. else {
  59. elem["on" + evType] = fn;
  60. }
  61. }
  62.  
  63. function $(id) { return document.querySelector(id); }
  64.  
  65. function URLAttrValueGet(attr_name, aurl)
  66. {
  67. attr_name = attr_name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  68. var regexS = "[\\?&]" + attr_name + "=([^&#]*)";
  69. var regex = new RegExp( regexS );
  70. var results = regex.exec( aurl );
  71. if( results == null )
  72. return "";
  73. else
  74. return results[1];
  75. }
  76.  
  77. function Ajax(AMethod, AURL, AParams, ACallBackFunc)
  78. {
  79. var LRequest = new XMLHttpRequest();
  80. LRequest.open(AMethod, AURL, true);
  81. LRequest.overrideMimeType('text/html; charset=windows-1251');
  82. LRequest.send(AParams);
  83. LRequest.onreadystatechange = function()
  84. {
  85. if (LRequest.readyState == 4)
  86. {
  87. ACallBackFunc(LRequest.responseText);
  88. }
  89. };
  90. }
  91.  
  92. function Trim(AText)
  93. {
  94. return AText.replace(/^\s+|\s+$|^(&nbsp;)+|(&nbsp;)+$/g, '');
  95. }
  96.  
  97. function DeleteCRLF(AText)
  98. {
  99. return AText.replace(/[\n\r]/g, ' ').replace(/\s{2,}/g, ' ');
  100. }
  101.  
  102. function SpsProcess()
  103. {
  104. if (location.href.indexOf('/transfer.php') > -1)
  105. {
  106. var LSps = decodeURIComponent(URLAttrValueGet('pahan_sps', location.href));
  107. if (LSps != '')
  108. {
  109. document.forms.f.nick.value = 'Pahan';
  110. document.forms.f.gold.value = '500';
  111. document.forms.f.desc.value = LSps;
  112. }
  113. }
  114. }
  115. SpsProcess();
  116.  
  117. //-----------------------------------
  118.  
  119. // -----------------------------------------------
  120. var GlobalCultureName = location.href.match('lordswm') ? "en-US" : "ru-RU",
  121. GlobalStrings = {
  122. "ru-RU" : {
  123. // Sell : "Пр-ь:",
  124. },
  125. "en-US" : {
  126. // Sell : "Sell:",
  127. }
  128. },
  129. GlobalLocalizedString = GlobalStrings[GlobalCultureName];
  130. // -----------------------------------------------
  131.  
  132. var
  133. LMinExp = 999999;
  134. function ExperienceProcess(AValue, ALink, AIndex)
  135. {
  136. if (LMinExp > AValue)
  137. LMinExp = AValue;
  138. var LID = 'hunt_exp_' + AIndex;
  139. var LEl = $('#' + LID);
  140. if (!LEl)
  141. {
  142. var Lumka = 1 * GetPerekachInfo().umka_koef;
  143. var LExp = Math.ceil(AValue);
  144. var LExpUmka = (AValue / Lumka).toFixed(0);
  145. var LInfo = 'Опыт: '+LExp+'&nbsp;&nbsp;&nbsp;Умка: '+Lumka+'&nbsp;&nbsp;&nbsp;Експоумка: '+LExpUmka;
  146. ALink.parentNode.innerHTML += '<br><span style="color:red" id="'+LID+'">'+LInfo+'</span>';
  147. }
  148. }
  149.  
  150. function ExperienceCalculate(AMobExp, ACount, ALevel)
  151. {
  152. var LExp = parseInt(AMobExp * ACount / 5);
  153. var LExpCoef = GetPerekachInfo().exp_koef;
  154. if (ALevel >=3)
  155. LExp = Math.max(LExp, ALevel * 70) * LExpCoef;
  156. return LExp;
  157. }
  158.  
  159. var
  160. LExpAllFound = true;
  161.  
  162. function Run(ALevel, ALink, AIndex)
  163. {
  164. var
  165. LMonster = ALink.href.split('=')[1],
  166. LArr = ALink.parentNode.innerHTML.split('('),
  167. LMonsterCount = -1,
  168. LExperience;
  169.  
  170. if (LArr.length < 2)
  171. return;
  172. LMonsterCount = parseInt(LArr[1]);
  173. var LExperience = GM_getValue(LMonster, '');
  174. if (LExperience == '')
  175. {
  176. LExpAllFound = false;
  177. Ajax('GET', ALink.href, null,
  178. function(AHTML)
  179. {
  180. var
  181. LIndex = 0,
  182. LPage = document.body.appendChild(document.createElement('div')),
  183. LParams = '';
  184. LPage.style.position = 'absolute';
  185. LPage.style.width = '0px';
  186. LPage.style.height = '0px';
  187. LPage.style.overflow = 'hidden';
  188. LPage.innerHTML = AHTML;
  189. LParams = LPage.querySelector('param[value*="M001"]').getAttribute('value').split('|')[1];
  190. LIndex = LParams.length - 1;
  191. while (isNaN(parseInt(LParams[LIndex])))
  192. LIndex--;
  193. LExperience = Number(LParams.substring(LIndex - 4, LIndex));
  194. GM_setValue(LMonster, LExperience);
  195. LParams = ExperienceCalculate(LExperience, LMonsterCount, ALevel);
  196. ExperienceProcess(LParams, ALink, AIndex);
  197. }
  198. );
  199. }
  200. else
  201. {
  202. var
  203. LParams = ExperienceCalculate(LExperience, LMonsterCount, ALevel);
  204. ExperienceProcess(LParams, ALink, AIndex);
  205. }
  206. }
  207.  
  208. function links_process(ALinks)
  209. {
  210. for(var i = 0; i < ALinks.length; i++)
  211. {
  212. var LLink = ALinks[i];
  213. Run(parseInt(GM_getValue('level', '0')), LLink, i);
  214. }
  215. }
  216. function setCheck(ch) {
  217. if( GM_getValue( ch ) && GM_getValue( ch ) == 1 )
  218. GM_setValue( ch , 0 );
  219. else
  220. GM_setValue( ch , 1 );
  221. }
  222. function close_setting_form() {
  223. bg = $('#bgOverlay1') ;
  224. bgc = $('#bgCenter1') ;
  225. if( bg ) {
  226. bg.style.display = bgc.style.display = 'none' ;
  227. }
  228. }
  229.  
  230. function save_skip_exp()
  231. {
  232. var LSkiptExp = parseInt($('#id_skip_exp').value);
  233. GM_setValue('skip_exp', LSkiptExp);
  234. }
  235. function GetPerekachInfo()
  236. {
  237. var sred_umk = [
  238. 63.5,109,161,235,386,619,946,1422,1982,2724,3815,
  239. 5518,8169,12055,17112,28205,37497,54278,68909
  240. ];
  241. var exp_attuale = parseInt(GM_getValue('umka_sum', '0'));
  242. var sum_umk = exp_attuale;
  243. var LLevel = parseInt(GM_getValue('level', '0'));
  244. if (LLevel > 2)
  245. var srednya_umka = sred_umk[LLevel - 3];
  246. else
  247. var srednya_umka = sum_umk;
  248. var umk_min = srednya_umka/1.6;
  249. var umk_max = srednya_umka*1.6;
  250. exp_attuale = exp_attuale - umk_min;
  251. umk_max = umk_max - umk_min;
  252. var perc = exp_attuale * 100 / umk_max;
  253. var progress_bar_html = '';
  254. var exp_koef = 1;
  255. var umka_koef = 1 + (Boolean(GM_getValue('blago', false)) ? 0.1 : 0);
  256. if (perc<100 && perc>0) {
  257. progress_bar_html = "Вы в норме!";
  258. }
  259. if (perc>100){
  260. var temp = Math.round(((sum_umk/srednya_umka/1.6)-1)*1000)/10;
  261. exp_koef += temp / 100;
  262. progress_bar_html = "Вы перекач! Дополнительно опыта: +" + temp + "%";
  263. }
  264. if (perc<0) {
  265. var temp = Math.round(((srednya_umka/sum_umk)-1)*1000)/10;
  266. umka_koef += temp / 100;
  267. progress_bar_html = "Вы недокач! Дополнительно умений: +" + temp + "%";
  268. }
  269. return {html: progress_bar_html, exp_koef: exp_koef, umka_koef: umka_koef};
  270. }
  271. function open_setting_form()
  272. {
  273. bg = $('#bgOverlay1') ;
  274. bgc = $('#bgCenter1') ;
  275. if( !bg ) {
  276. bg = document.createElement('div') ;
  277. bg.id = 'bgOverlay1' ;
  278. document.body.appendChild( bg );
  279. bg.style.position = 'absolute' ;
  280. bg.style.left = '0';
  281. bg.style.width = '100%';
  282. bg.style.height = '100%';
  283. bg.style.background = "#000000";
  284. bg.style.opacity = "0.5";
  285. bg.addEventListener( "click", close_setting_form , false );
  286.  
  287. bgc = document.createElement('div') ;
  288. bgc.id = 'bgCenter1' ;
  289. document.body.appendChild( bgc );
  290. bgc.style.position = 'absolute' ;
  291. bgc.style.width = '600px';
  292. bgc.style.background = "#F6F3EA";
  293. bgc.style.left = ( ( document.body.offsetWidth - 400 ) / 2 ) + 'px' ;
  294. bgc.style.zIndex = "1105";
  295. }
  296. var LPerekackInfo = GetPerekachInfo();
  297. bgc.innerHTML =
  298. '<div style="border:1px solid #abc;padding:5px;margin:2px;">' +
  299. ' <div style="float:right;border:1px solid #abc;width:15px;height:15px;text-align:center;cursor:pointer;" id="bt_close1" title="Закрыть">x</div>' +
  300. ' <center>' +
  301. ' <table>' +
  302. ' <tr>' +
  303. ' <td><b>'+str_script_name+' <font style="color:#0070FF;">'+version+'</font></b><hr/></td>' +
  304. ' </tr>' +
  305. ' <tr>' +
  306. ' <td><b>Настройки:</b></td>' +
  307. ' </tr>' +
  308. ' <tr>' +
  309. ' </tr>' +
  310. ' <tr>' +
  311. ' <td><b>' + LPerekackInfo.html + '</b></td>' +
  312. ' </tr>' +
  313. ' <tr>' +
  314. ' <td>' +
  315. ' <div>Коэффициент опыта: <b>' + LPerekackInfo.exp_koef + '</b></div>' +
  316. ' <div>Коэффициент умки: <b>' + LPerekackInfo.umka_koef + '</b></div>' +
  317. ' </td>' +
  318. ' </tr>' +
  319. ' <tr>' +
  320. ' <td><b>Автоматический пропуск охоты:</b></td>' +
  321. ' </tr>' +
  322. ' <tr>' +
  323. ' <td>' +
  324. ' <div><input type="text" style="width:80;" id="id_skip_exp"> Опыт для автоматического пропуска </div>' +
  325. ' <div>Значение "0" - не пропускать охоты автоматически</div>' +
  326. ' </td>' +
  327. ' </tr>' +
  328. ' <tr><td><hr/></td></tr>' +
  329. ' <tr>' +
  330. ' <td style="font-weight:bold;font-size:10px;" >' +
  331. ' <a style="font-weight:bold;font-size:10px;" href="'+str_url+'">Обновить</a> ' +
  332. ' <a style="font-weight:bold;font-size:10px;" href="'+str_url_aut+'">Нашли ошибку?</a> ' +
  333. ' <a style="font-weight:bold;font-size:10px;" href="'+str_url_sps+'">Сказать спасибо</a> ' +
  334. ' </td>' +
  335. ' </tr>' +
  336. ' <tr>' +
  337. ' <td style="font-weight:bold;font-size:10px;" >' +
  338. ' Автор: <a style="font-weight:bold;font-size:10px;" href="http://www.heroeswm.ru/pl_info.php?id=30547">Pahan.</a>' +
  339. ' </td>' +
  340. ' </tr>' +
  341. ' </table>' +
  342. ' </center>' +
  343. '</div>';
  344. $("#bt_close1").addEventListener( "click", close_setting_form , false );
  345. var Lskip_exp = $("#id_skip_exp");
  346. Lskip_exp.value = parseInt(GM_getValue('skip_exp', '0'));
  347. Lskip_exp.addEventListener( "change", save_skip_exp , false );
  348. Lskip_exp.addEventListener( "keyup", save_skip_exp , false );
  349. Lskip_exp.addEventListener( "paste", save_skip_exp , false );
  350. bg.style.top = (-document.body.scrollTop)+'px';
  351. bgc.style.top = ( document.body.scrollTop + 100 ) + 'px';
  352. bg.style.display = bgc.style.display = 'block' ;
  353. }
  354.  
  355. function add_settings()
  356. {
  357. var LDiv = $("#hwm_hant_options");
  358. if (LDiv)
  359. return;
  360. var LLinks = document.querySelectorAll('a[href^="ecostat.php"]');
  361. if (LLinks && (LLinks.length > 0))
  362. {
  363. var LLink = LLinks[0];
  364. LDiv = document.createElement('div');
  365. LDiv.innerHTML = '<div style="text-decoration:underline;cursor:pointer;font-weight:bold;font-size:10px;" id="hwm_hant_options">Настройки калькулятора опыта охоты';
  366. LLink.parentNode.appendChild(LDiv);
  367. $("#hwm_hant_options").addEventListener( "click", open_setting_form , false );
  368. }
  369. }
  370.  
  371. function RemoveElement(El)
  372. {
  373. El.parentNode.removeChild(El);
  374. }
  375.  
  376. function skip_hant()
  377. {
  378. var LLinks = document.querySelectorAll('span[id*="hunt_exp_"]');
  379. if (LLinks)
  380. {
  381. for (var i = 0; i < LLinks.length; i++)
  382. {
  383. var LParent = LLinks[i].parentNode.parentNode.parentNode.parentNode;
  384. RemoveElement(LParent.nextSibling);
  385. RemoveElement(LParent);
  386. }
  387. }
  388. Ajax('GET', '/map.php?action=skip', null, function(AHTML){});
  389. }
  390.  
  391. function calc_hant()
  392. {
  393. LExpAllFound = true;
  394.  
  395. var LLinks = document.querySelectorAll('a[href^="army_info.php"]');
  396. var LLink;
  397. if (LLinks)
  398. links_process(LLinks);
  399. add_settings();
  400.  
  401. if(LExpAllFound)
  402. {
  403. var LSkipExp = parseInt(GM_getValue('skip_exp', '0'));
  404. if ((LMinExp != 999999) && (LSkipExp > 0) && (LMinExp > LSkipExp))
  405. {
  406. skip_hant();
  407. }
  408. }
  409. else
  410. setTimeout(calc_hant, 1000);
  411. }
  412.  
  413. function save_level()
  414. {
  415. var list = document.getElementsByTagName("b");
  416. for(var i = 0; i < list.length; i++)
  417. {
  418. var elem = list[i];
  419. if (elem.innerHTML.indexOf('\u0411\u043E\u0435\u0432\u043E\u0439\u0020\u0443\u0440\u043E\u0432\u0435\u043D\u044C') === 0)
  420. {
  421. var regex = /(\d+)/;
  422. var regex_res = regex.exec(elem.innerHTML);
  423. if (regex_res)
  424. {
  425. var LLevel = parseInt(regex_res[1]);
  426. if (LLevel)
  427. GM_setValue('level', LLevel);
  428. }
  429. return;
  430. }
  431. }
  432. }
  433.  
  434. function GetSumAbility(AElem)
  435. {
  436. var LUmka = 0;
  437. sublist = AElem.getElementsByTagName("b");
  438. if (sublist.length > 0)
  439. {
  440. var subitem = sublist[0];
  441. var subindex = Array.prototype.indexOf.call(subitem.parentNode.childNodes, subitem);
  442. var regex = /\((\d+.\d+)\)/;
  443. var regex_res = regex.exec(subitem.parentNode.childNodes[subindex + 1].textContent);
  444. if (regex_res)
  445. {
  446. LUmka += parseFloat(regex_res[1]);
  447. }
  448. }
  449. for(i = 0; i < AElem.childNodes.length; i++)
  450. {
  451. var cur_el = AElem.childNodes[i];
  452. var html = Trim(cur_el.textContent);
  453. var regex = /\: \d+ \((\d+.\d+)\)/;
  454. var regex_res = regex.exec(html);
  455. if(regex_res)
  456. {
  457. cur_abil = parseFloat(regex_res[1]);
  458. if ((html.indexOf('\u0413\u0438\u043B\u044C\u0434\u0438\u044F') === -1))
  459. {
  460. var next_el = cur_el.parentNode.childNodes[i + 1];
  461. if (next_el.tagName == 'FONT')
  462. {
  463. LUmka += cur_abil;
  464. }
  465. }
  466. }
  467. }
  468. return LUmka;
  469. }
  470.  
  471. function save_umka_sum()
  472. {
  473. var list = document.getElementsByTagName("td");
  474. for(var i = 0; i < list.length; i++)
  475. {
  476. var elem = list[i];
  477. if( (Trim(elem.innerHTML).indexOf('\u0420\u044B\u0446\u0430\u0440\u044C\u003A') === 0)
  478. || (Trim(elem.innerHTML).indexOf('<b>\u0420\u044B\u0446\u0430\u0440\u044C\u003A') === 0)
  479. )
  480. {
  481. GM_setValue('umka_sum', GetSumAbility(elem).toFixed(3));
  482. return;
  483. }
  484. }
  485. }
  486.  
  487. function save_blago()
  488. {
  489. var LLinks = document.querySelectorAll('img[src*="star.gif"]');
  490. var LBlago = (LLinks && (LLinks.length == 1));
  491. GM_setValue('blago', LBlago);
  492. }
  493.  
  494. function check_calc_hant()
  495. {
  496. if (GM_getValue('level', 'asd') === 'asd')
  497. setInterval(check_calc_hant, 1000);
  498. else
  499. calc_hant();
  500. }
  501.  
  502. function ProcessMain()
  503. {
  504. if (location.href.indexOf('/map.php') > -1)
  505. {
  506. if (GM_getValue('level', 'asd') === 'asd')
  507. {
  508. bg = document.createElement('div') ;
  509. bg.innerHTML = '<iframe width="1" height="1" frameborder="no" name="ItemInfoFrame" src="/home.php" ></iframe>';
  510. document.body.appendChild( bg );
  511. setInterval(check_calc_hant, 1000);
  512. }
  513. else
  514. calc_hant();
  515. }
  516. else
  517. if (location.href.indexOf('/home.php') > -1)
  518. {
  519. save_level();
  520. save_umka_sum();
  521. save_blago();
  522. }
  523. }
  524.  
  525. ProcessMain();