HWM All Class Change

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

目前為 2021-11-18 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name HWM All Class Change
  3. // @description Смена фракции и класса с домашней страницы (версия от 2021.11.18)
  4. // @author ElMarado (Идею дал HWM_Quick_Class_Change от Рианти)
  5. // @version 1.51
  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. [10, 'Фараон', 0, 'http://dcdn.heroeswm.ru/i/f/r10.png?v=1.1']
  43. ];
  44.  
  45. // Делаем з-прос на сервер.
  46. // target - адрес
  47. // params - передаваемые параметры
  48. // ajaxCallback - что выполнить при удачном исходе
  49. // timeoutHandler - что выполнить при неудачном (не получаем ответа в течении _ajaxTimeout мс)
  50. function postRequest(target, params, ajaxCallback, timeoutHandler)
  51. {
  52. var xmlhttp;
  53. if (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest();
  54. else xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
  55. xmlhttp.onreadystatechange=function(){
  56. if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
  57. ajaxCallback(xmlhttp.responseText);
  58. }
  59. }
  60. xmlhttp.open('GET', target+params, true);
  61. xmlhttp.overrideMimeType('text/plain; charset=windows-1251');
  62. xmlhttp.timeout = _ajaxTimeout;
  63. xmlhttp.ontimeout = function(){
  64. timeoutHandler();
  65. }
  66. xmlhttp.send(params);
  67. }
  68.  
  69. // Сообщение игроку, если за 7 сек не получили ответа от сервера на смену класса/фракции
  70. function alert_error(){
  71. document.body.style.cursor = 'default';
  72. alert('Ошибка, проверьте связь с интернетом.');
  73. }
  74.  
  75.  
  76. // функция смены класса/фракции
  77. function changeFractClass(fr,cl){
  78. document.body.style.cursor = 'progress';
  79. postRequest(_formAction, '?change_clr_to='+(cl?cl+'0'+fr:fr)+'&sign='+sign,
  80. function (){ setTimeout(function(){location.reload()}, 300); },
  81. function (){ alert_error();}
  82. );
  83. }
  84.  
  85. // обрабаытваем клик мышки и вызываем смену на соответствующий класс
  86. function appendEvent(fr,cl){
  87. document.getElementById('fc'+fr+'-'+cl).onclick = function(){changeFractClass(fr,cl); this.style.cursor = 'progress'};
  88. }
  89.  
  90. // получаем место вставки иконок класса
  91.  
  92. var icons = document.querySelectorAll("a[href*='castle.php?change_faction_dialog']");
  93. var icon = icons[0].childNodes[0];
  94. var newInterface = false;
  95. if (icon.tagName == "DIV") {newInterface = true; icon = icon.childNodes[0];}
  96. var cur_ico = 'https://dcdn.heroeswm.ru/i/f/'+icon.src.substring(icon.src.lastIndexOf("/")+1,icon.src.length);
  97. // выводим все иконки
  98. var ii, elem, cur_fr, content = '<br>';
  99. if (newInterface) content += '<DIV align="right">';
  100. content += '<font style="color:#0070FF;">Изменить класс на:</font> ';
  101. for (ii=0; ii < all_Class.length; ii++){
  102. if (all_Class[ii][3] == cur_ico) cur_fr =all_Class[ii][0];
  103. elem = all_Class[ii];
  104. 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] + '">';
  105. }
  106. if (newInterface) content +="</DIV>";;
  107.  
  108. icons[0].parentNode.innerHTML += content;
  109. // назначаем на иконки события
  110. for (ii=0; ii < all_Class.length; ii++){
  111. elem = all_Class[ii];
  112. appendEvent(elem[0],elem[2]);
  113. }
  114. //*********
  115. })();