HWM_All_Class_Change

Смена класса любой фракции с домашней страницы (2015.08.29)

当前为 2015-08-29 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name HWM_All_Class_Change
  3. // @author ElMarado (Идею дал HWM_Quick_Class_Change от Рианти)
  4. // @description Смена класса любой фракции с домашней страницы (2015.08.29)
  5. // @version 1.25
  6. // @include http://*.heroeswm.*/home.php*
  7. // @include http://178.248.235.15/home.php*
  8. // @icon https://app.box.com/representation/file_version_34029013909/image_2048/1.png?shared_name=hz97b2qwo2ycc5ospb7ccffn13w3ehc4
  9. // @namespace https://greasyfork.org/users/14188
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. //*******
  14. var url_cur = location.href;
  15. var _formAction = 'http://'+location.hostname+'/castle.php';
  16. var _ajaxTimeout = 5000;
  17.  
  18. var all_Class = [
  19. [1, 'Рыцарь', 0, 'http://dcdn.heroeswm.ru/i/r1.gif'],
  20. [1, 'Рыцарь Света', 1, 'http://dcdn.heroeswm.ru/i/r101.gif'],
  21. [2, 'Некромант', 0, 'http://dcdn.heroeswm.ru/i/r2.gif'],
  22. [2, 'Некромант Повелитель Смерти', 1, 'http://dcdn.heroeswm.ru/i/r102.gif'],
  23. [3, 'Маг', 0, 'http://dcdn.heroeswm.ru/i/r3.gif'],
  24. [3, 'Маг-разрушитель', 1, 'http://dcdn.heroeswm.ru/i/r103.gif'],
  25. [4, 'Эльф', 0, 'http://dcdn.heroeswm.ru/i/r4.gif'],
  26. [4, 'Эльф-заклинатель', 1, 'http://dcdn.heroeswm.ru/i/r104.gif'],
  27. [5, 'Варвар', 0, 'http://dcdn.heroeswm.ru/i/r5.gif'],
  28. [5, 'Варвар Крови', 1, 'http://dcdn.heroeswm.ru/i/r105.gif'],
  29. [5, 'Варвар Шаман', 2, 'http://dcdn.heroeswm.ru/i/r205.gif'],
  30. [6, 'Темный эльф', 0, 'http://dcdn.heroeswm.ru/i/r6.gif'],
  31. [7, 'Демон', 0, 'http://dcdn.heroeswm.ru/i/r7.gif'],
  32. [7, 'Демон Тьмы', 1, 'http://dcdn.heroeswm.ru/i/r107.gif'],
  33. [8, 'Гном', 0, 'http://dcdn.heroeswm.ru/i/r8.gif'],
  34. [9, 'Степной варвар', 0, 'http://dcdn.heroeswm.ru/i/r9.gif']
  35. ];
  36.  
  37. // Делаем запрос на сервер.
  38. // target - адрес
  39. // params - передаваемые параметры
  40. // ajaxCallback - что выполнить при удачном исходе
  41. // timeoutHandler - что выполнить при неудачном (не получаем ответа в течении _ajaxTimeout мс)
  42. function postRequest(target, params, ajaxCallback, timeoutHandler)
  43. {
  44. var xmlhttp;
  45. if (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest();
  46. else xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
  47. xmlhttp.onreadystatechange=function(){
  48. if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
  49. ajaxCallback(xmlhttp.responseText);
  50. }
  51. }
  52. xmlhttp.open('POST', target, true);
  53. xmlhttp.overrideMimeType('text/plain; charset=windows-1251');
  54. xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  55. xmlhttp.timeout = _ajaxTimeout;
  56. xmlhttp.ontimeout = function(){
  57. timeoutHandler();
  58. }
  59. xmlhttp.send(params);
  60. }
  61.  
  62. // Сообщение игроку, если за 5 сек не получили ответа от сервера на смену класса/фракции
  63. function alert_error(){
  64. document.body.style.cursor = 'default';
  65. alert('Ошибка, проверьте связь с интернетом.');
  66. }
  67.  
  68. // подфункция смена класса(только) на "cl"
  69. function changeClass(cl){
  70. document.body.style.cursor = 'progress';
  71. postRequest(_formAction, 'classid=' + cl,
  72. function (){ setTimeout(function(){location.reload()}, 300); },
  73. function (){ alert_error();}
  74. );
  75. }
  76.  
  77. // функция смены класса/фракции
  78. function changeFractClass(fr,cl){
  79. document.body.style.cursor = 'progress';
  80. if (fr == cur_fr)
  81. {
  82. changeClass(cl);
  83. return;
  84. }
  85.  
  86. if (cl == 0) {
  87. postRequest(_formAction, 'fract='+fr,
  88. function (){ setTimeout(function(){location.reload()}, 300); },
  89. function (){ alert_error();}
  90. );
  91. return;
  92. }
  93.  
  94. postRequest(_formAction, 'fract='+fr,
  95. function (){ changeClass(cl);},
  96. function (){ alert_error();}
  97. );
  98. }
  99.  
  100. // обрабаытваем клик мышки и вызываем смену на соответствующий класс
  101. function appendEvent(fr,cl){
  102. document.getElementById('fc'+fr+'-'+cl).onclick = function(){changeFractClass(fr,cl); this.style.cursor = 'progress'};
  103. }
  104.  
  105. // получаем место вставки иконок класса
  106. var icons = document.querySelector('.wb > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > center:nth-child(1)').getElementsByTagName('img');
  107. var icon = icons[icons.length - 1];
  108. var cur_ico = 'http://dcdn.heroeswm.ru/i/'+icon.src.substring(icon.src.lastIndexOf("/")+1,icon.src.length);
  109. // выводим все иконки
  110. var ii, elem, cur_fr, content = '<br><font style="color:#0070FF;">Изменить на:</font> ';
  111. for (ii=0; ii < all_Class.length; ii++){
  112. if (all_Class[ii][3] == cur_ico) cur_fr =all_Class[ii][0];
  113. elem = all_Class[ii];
  114. 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] + '">';
  115. }
  116. icon.parentNode.innerHTML += content;
  117. // назначаем на иконки события
  118. for (ii=0; ii < all_Class.length; ii++){
  119. elem = all_Class[ii];
  120. appendEvent(elem[0],elem[2]);
  121. }
  122. //*********
  123. })();