Advertisement
Meshy

class change

Nov 9th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.37 KB | None | 0 0
  1. // ==UserScript==
  2. // @name HWM_All_Class_Change
  3. // @author ElMarado (Идею дал HWM_Quick_Class_Change от Рианти)
  4. // @description Смена класса любой фракции с домашней страницы (2016.07.04)
  5. // @version 1.26
  6. // @include http://*.lordswm.*/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, 'Knight', 0, 'http://dcdn.lordswm.com/i/r1.gif'],
  20. [1, 'Holy Knight', 1, 'http://dcdn.lordswm.com/i/r101.gif'],
  21. [2, 'Necro', 0, 'http://dcdn.lordswm.com/i/r2.gif'],
  22. [2, 'Unholy Necro', 1, 'http://dcdn.lordswm.com/i/r102.gif'],
  23. [3, 'Wizard', 0, 'http://dcdn.lordswm.com/i/r3.gif'],
  24. [3, 'Battle Wizard', 1, 'http://dcdn.lordswm.com/i/r103.gif'],
  25. [4, 'Elf', 0, 'http://dcdn.lordswm.com/i/r4.gif'],
  26. [4, 'Charmer elf', 1, 'http://dcdn.lordswm.com/i/r104.gif'],
  27. [5, 'Barbarian', 0, 'http://dcdn.lordswm.com/i/r5.gif'],
  28. [5, 'Fury Barbarian', 1, 'http://dcdn.lordswm.com/i/r105.gif'],
  29. [5, 'Shadow barbarian', 2, 'http://dcdn.lordswm.com/i/r205.gif'],
  30. [6, 'Dark Elf', 0, 'http://dcdn.lordswm.com/i/r6.gif'],
  31. [6, 'Tamer Dark Elf', 1, 'http://dcdn.lordswm.com/i/r106.gif'],
  32. [7, 'Demon', 0, 'http://dcdn.lordswm.com/i/r7.gif'],
  33. [7, 'Darkness Demon', 1, 'http://dcdn.lordswm.com/i/r107.gif'],
  34. [8, 'Dwarf', 0, 'http://dcdn.lordswm.com/i/r8.gif'],
  35. [9, 'Tribal', 0, 'http://dcdn.lordswm.com/i/r9.gif']
  36. ];
  37.  
  38. // Делаем запрос на сервер.
  39. // target - адрес
  40. // params - передаваемые параметры
  41. // ajaxCallback - что выполнить при удачном исходе
  42. // timeoutHandler - что выполнить при неудачном (не получаем ответа в течении _ajaxTimeout мс)
  43. function postRequest(target, params, ajaxCallback, timeoutHandler)
  44. {
  45. var xmlhttp;
  46. if (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest();
  47. else xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
  48. xmlhttp.onreadystatechange=function(){
  49. if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
  50. ajaxCallback(xmlhttp.responseText);
  51. }
  52. }
  53. xmlhttp.open('POST', target, true);
  54. xmlhttp.overrideMimeType('text/plain; charset=windows-1251');
  55. xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  56. xmlhttp.timeout = _ajaxTimeout;
  57. xmlhttp.ontimeout = function(){
  58. timeoutHandler();
  59. }
  60. xmlhttp.send(params);
  61. }
  62.  
  63. // Сообщение игроку, если за 5 сек не получили ответа от сервера на смену класса/фракции
  64. function alert_error(){
  65. document.body.style.cursor = 'default';
  66. alert('Ошибка, проверьте связь с интернетом.');
  67. }
  68.  
  69. // подфункция смена класса(только) на "cl"
  70. function changeClass(cl){
  71. document.body.style.cursor = 'progress';
  72. postRequest(_formAction, 'classid=' + cl,
  73. function (){ setTimeout(function(){location.reload()}, 300); },
  74. function (){ alert_error();}
  75. );
  76. }
  77.  
  78. // функция смены класса/фракции
  79. function changeFractClass(fr,cl){
  80. document.body.style.cursor = 'progress';
  81. if (fr == cur_fr)
  82. {
  83. changeClass(cl);
  84. return;
  85. }
  86.  
  87. if (cl == 0) {
  88. postRequest(_formAction, 'fract='+fr,
  89. function (){ setTimeout(function(){location.reload()}, 300); },
  90. function (){ alert_error();}
  91. );
  92. return;
  93. }
  94.  
  95. postRequest(_formAction, 'fract='+fr,
  96. function (){ changeClass(cl);},
  97. function (){ alert_error();}
  98. );
  99. }
  100.  
  101. // обрабаытваем клик мышки и вызываем смену на соответствующий класс
  102. function appendEvent(fr,cl){
  103. document.getElementById('fc'+fr+'-'+cl).onclick = function(){changeFractClass(fr,cl); this.style.cursor = 'progress'};
  104. }
  105.  
  106. // получаем место вставки иконок класса
  107. 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');
  108. var icon = icons[icons.length - 1];
  109. var cur_ico = 'http://dcdn.lordswm.com/i/'+icon.src.substring(icon.src.lastIndexOf("/")+1,icon.src.length);
  110. // выводим все иконки
  111. var ii, elem, cur_fr, content = '<br><font style="color:#0070FF;">Change faction:</font> ';
  112. for (ii=0; ii < all_Class.length; ii++){
  113. if (all_Class[ii][3] == cur_ico) cur_fr =all_Class[ii][0];
  114. elem = all_Class[ii];
  115. content += (ii?' ':'') + '<img src="' + elem[3] + '" title="Change to: ' + elem[1] + '" align="absmiddle" border="0" height="15" width="15" style="cursor: pointer" id="fc' + elem[0]+'-'+elem[2] + '">';
  116. }
  117. icon.parentNode.innerHTML += content;
  118. // назначаем на иконки события
  119. for (ii=0; ii < all_Class.length; ii++){
  120. elem = all_Class[ii];
  121. appendEvent(elem[0],elem[2]);
  122. }
  123. //*********
  124. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement