HWM All Class Change

Смена фракции и класса с домашней страницы (версия от 2025.03.20)

  1. // ==UserScript==
  2. // @name HWM All Class Change
  3. // @description Смена фракции и класса с домашней страницы (версия от 2025.03.20)
  4. // @author ElMarado (Идею дал HWM_Quick_Class_Change от Рианти)
  5. // @version 1.60
  6. // @include https://www.heroeswm.ru/home.php*
  7. // @include https://www.lordswm.com/home.php*
  8. // @include http://178.248.235.15/home.php*
  9. // @icon https://app.box.com/representation/file_version_34029013909/image_2048/1.png?shared_name=hz97b2qwo2ycc5ospb7ccffn13w3ehc4
  10. // @namespace https://greasyfork.org/users/14188
  11. // @license GNU GPLv3
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. //*******
  16. var url_cur = location.href;
  17. var _formAction = location.protocol+'//'+location.hostname+'/castle.php';
  18. var _ajaxTimeout = 5000;
  19. var sign = document.body.innerHTML.match(/sign=([a-z0-9]+)/);
  20. if(sign) sign = sign[1];
  21. else return;
  22.  
  23. var all_Class = [
  24. [1, 'Рыцарь', 0, 'http://dcdn.heroeswm.ru/i/f/r1.png?v=1.1'],
  25. [1, 'Рыцарь света', 1, 'http://dcdn.heroeswm.ru/i/f/r101.png?v=1.1'],
  26. [2, 'Некромант', 0, 'http://dcdn.heroeswm.ru/i/f/r2.png?v=1.1'],
  27. [2, 'Некромант - повелитель смерти', 1, 'http://dcdn.heroeswm.ru/i/f/r102.png?v=1.1'],
  28. [3, 'Маг', 0, 'http://dcdn.heroeswm.ru/i/f/r3.png?v=1.1'],
  29. [3, 'Маг - разрушитель', 1, 'http://dcdn.heroeswm.ru/i/f/r103.png?v=1.1'],
  30. [4, 'Эльф', 0, 'http://dcdn.heroeswm.ru/i/f/r4.png?v=1.1'],
  31. [4, 'Эльф - заклинатель', 1, 'http://dcdn.heroeswm.ru/i/f/r104.png?v=1.1'],
  32. [5, 'Варвар', 0, 'http://dcdn.heroeswm.ru/i/f/r5.png?v=1.1'],
  33. [5, 'Варвар крови', 1, 'http://dcdn.heroeswm.ru/i/f/r105.png?v=1.1'],
  34. [5, 'Варвар - шаман', 2, 'http://dcdn.heroeswm.ru/i/f/r205.png?v=1.1'],
  35. [6, 'Темный эльф', 0, 'http://dcdn.heroeswm.ru/i/f/r6.png?v=1.1'],
  36. [6, 'Темный эльф - укротитель', 1, 'http://dcdn.heroeswm.ru/i/f/r106.png?v=1.1'],
  37. [7, 'Демон', 0, 'http://dcdn.heroeswm.ru/i/f/r7.png?v=1.1'],
  38. [7, 'Демон тьмы', 1, 'http://dcdn.heroeswm.ru/i/f/r107.png?v=1.1'],
  39. [8, 'Гном', 0, 'http://dcdn.heroeswm.ru/i/f/r8.png?v=1.1'],
  40. [8, 'Гном огня', 1, 'http://dcdn.heroeswm.ru/i/f/r108.png?v=1.1'],
  41. [9, 'Степной варвар', 0, 'http://dcdn.heroeswm.ru/i/f/r9.png?v=1.1'],
  42. [9, 'Степной варвар ярости', 1, 'http://dcdn.heroeswm.ru/i/f/r109.png?v=1.1'],
  43. [10, 'Фараон', 0, 'http://dcdn.heroeswm.ru/i/f/r10.png?v=1.1']
  44. ];
  45.  
  46. // Делаем з-прос на сервер.
  47. // target - адрес
  48. // params - передаваемые параметры
  49. // ajaxCallback - что выполнить при удачном исходе
  50. // timeoutHandler - что выполнить при неудачном (не получаем ответа в течении _ajaxTimeout мс)
  51. function postRequest(target, params, ajaxCallback, timeoutHandler)
  52. {
  53. var xmlhttp;
  54. if (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest();
  55. else xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
  56. xmlhttp.onreadystatechange=function(){
  57. if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
  58. ajaxCallback(xmlhttp.responseText);
  59. }
  60. }
  61. xmlhttp.open('GET', target+params, true);
  62. xmlhttp.overrideMimeType('text/plain; charset=windows-1251');
  63. xmlhttp.timeout = _ajaxTimeout;
  64. xmlhttp.ontimeout = function(){
  65. timeoutHandler();
  66. }
  67. xmlhttp.send(params);
  68. }
  69.  
  70. // Сообщение игроку, если за 7 сек не получили ответа от сервера на смену класса/фракции
  71. function alert_error(){
  72. document.body.style.cursor = 'default';
  73. alert('Ошибка, проверьте связь с интернетом.');
  74. }
  75.  
  76.  
  77. // функция смены класса/фракции
  78. function changeFractClass(fr,cl){
  79. document.body.style.cursor = 'progress';
  80. postRequest(_formAction, '?change_clr_to='+(cl?cl+'0'+fr:fr)+'&sign='+sign,
  81. function (){ setTimeout(function(){location.reload()}, 300); },
  82. function (){ alert_error();}
  83. );
  84. }
  85.  
  86. // обрабаытваем клик мышки и вызываем смену на соответствующий класс
  87. function appendEvent(fr,cl){
  88. document.getElementById('fc'+fr+'-'+cl).onclick = function(){changeFractClass(fr,cl); this.style.cursor = 'progress'};
  89. }
  90.  
  91. // получаем место вставки иконок класса
  92.  
  93. var icons = document.querySelectorAll("a[href*='castle.php?change_faction_dialog']");
  94. var icon = icons[0].childNodes[0];
  95. var newInterface = false;
  96. if (icon.tagName == "DIV") {newInterface = true; icon = icon.childNodes[0];}
  97. var cur_ico = 'https://dcdn.heroeswm.ru/i/f/'+icon.src.substring(icon.src.lastIndexOf("/")+1,icon.src.length);
  98. // выводим все иконки
  99. var ii, elem, cur_fr, content = '<br>';
  100. if (newInterface) content += '<DIV align="right">';
  101. content += '<font style="color:#0070FF;">Изменить класс на:</font> ';
  102. for (ii=0; ii < all_Class.length; ii++){
  103. if (all_Class[ii][3] == cur_ico) cur_fr =all_Class[ii][0];
  104. elem = all_Class[ii];
  105. content += (ii?' ':'') + '<img src="' + elem[3] + '" title="Изменить на: ' + elem[1] + '" align="absmiddle" border="0" height="15" width="15" style="cursor: pointer" id="fc' + elem[0]+'-'+elem[2] + '">';
  106. }
  107. if (newInterface) content +="</DIV>";;
  108.  
  109. icons[0].parentNode.innerHTML += content;
  110. // назначаем на иконки события
  111. for (ii=0; ii < all_Class.length; ii++){
  112. elem = all_Class[ii];
  113. appendEvent(elem[0],elem[2]);
  114. }
  115. //*********
  116. })();