HWM.PlayerSemaphores


SUBMITTED BY: AnD888

DATE: Oct. 6, 2016, 1:41 p.m.

FORMAT: Text only

SIZE: 8.2 kB

HITS: 1888

  1. // ==UserScript==
  2. // @version 0.1
  3. // @author alex_kocharin
  4. // @collaborator alex_kocharin
  5. // @license free
  6. // @copyright 2014, alex_kocharin (http://www.heroeswm.ru/pl_info.php?id=78601)
  7. // @description Светофоры в личных рекордах ГО игроков
  8. // @icon http://www.heroeswm.ru/hwmicon.ico
  9. // @name HWM.PlayerSemaphores
  10. // @updateURL https://openuserjs.org/scripts/dailyhwm/HWM.PlayerSemaphores
  11. // @homepageURL https://openuserjs.org/scripts/dailyhwm/HWM.PlayerSemaphores
  12. //
  13. // @include http://www.heroeswm.ru/pl_hunter_stat.php*
  14. // @include http://www.heroeswm.com/pl_hunter_stat.php*
  15. // @include http://rus.heroeswm.com/pl_hunter_stat.php*
  16. // @include http://www.lordswm.com/pl_hunter_stat.php*
  17. // ==/UserScript==
  18. // set this to "true" for inserting my line after results table
  19. var insertafter = false;
  20. //var insertafter = true;
  21. var serv = 'ru';
  22. if (location.href.match(/heroeswm.ru/)) {
  23. serv = 'ru';
  24. } else if (location.href.match(/lordswm.com/)) {
  25. serv = 'com';
  26. } else if (location.href.match(/rus.heroeswm.com/)) {
  27. serv = 'ru';
  28. } else if (location.href.match(/heroeswm.com/)) {
  29. serv = 'com';
  30. }
  31. var text_setting, text_record, text_loaded, text_err, text_parsrec,
  32. text_loadrec, text_parspl, text_loadpl, text_sleeping, text_loadsem;
  33. if (serv == 'com') {
  34. text_setting = 'Setting semaphores...';
  35. text_record = 'Record';
  36. text_loaded = 'Semaphores loaded successfully';
  37. text_err = 'Error';
  38. text_parsrec = 'Parsing records information...';
  39. text_loadrec = 'Loading records information...';
  40. text_parspl = 'Parsing player information...';
  41. text_loadpl = 'Loading player information...';
  42. text_sleeping = 'Sleeping 2 sec... please wait';
  43. text_loadsem = 'Load semaphores';
  44. } else {
  45. text_setting = '\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0441\u0432\u0435\u0442\u043e\u0444\u043e\u0440\u043e\u0432...';
  46. text_record = '\u0420\u0435\u043a\u043e\u0440\u0434';
  47. text_loaded = '\u0421\u0432\u0435\u0442\u043e\u0444\u043e\u0440\u044b \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u044b \u0443\u0441\u043f\u0435\u0448\u043d\u043e';
  48. text_err = '\u041e\u0448\u0438\u0431\u043a\u0430';
  49. text_parsrec = '\u0421\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0440\u0435\u043a\u043e\u0440\u0434\u0430\u0445...';
  50. text_loadrec = '\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0440\u0435\u043a\u043e\u0440\u0434\u0430\u0445...';
  51. text_parspl = '\u0421\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431 \u0438\u0433\u0440\u043e\u043a\u0435...';
  52. text_loadpl = '\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431 \u0438\u0433\u0440\u043e\u043a\u0435...';
  53. text_sleeping = '\u0417\u0430\u0434\u0435\u0440\u0436\u043a\u0430, 2 \u0441\u0435\u043a... \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u043f\u043e\u0434\u043e\u0436\u0434\u0438\u0442\u0435';
  54. text_loadsem = '\u0417\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0441\u0432\u0435\u0442\u043e\u0444\u043e\u0440\u044b';
  55. }
  56. text_loaded = '';
  57. function loadsem(log, where)
  58. {
  59. function setsem(hash, hash2)
  60. {
  61. log.innerHTML = text_setting;
  62. for(var i=0; i<where.childNodes.length; i++) {
  63. var newtd = document.createElement('td');
  64. if (i == 0) {
  65. newtd.innerHTML = '&nbsp;';
  66. } else {
  67. var trec = 0;
  68. var trec2 = 0;
  69. var prec = 0;
  70. var dd = 0.6;
  71. var m;
  72. var armyx = '';
  73. if (m = where.childNodes[i].innerHTML.match(/army_info\.php\?name=(\S+)"/)) {
  74. armyx = m[1];
  75. if (hash[m[1]]) {
  76. trec = hash[m[1]];
  77. }
  78. if (hash2[m[1]]) {
  79. trec2 = hash2[m[1]];
  80. }
  81. }
  82. if (m = where.childNodes[i].innerHTML.match(/warlog\.php\?warid=\d+">(\d+)</)) {
  83. prec = m[1];
  84. }
  85. if (trec > 0 && prec > 0) {
  86. dd = prec * 1.3 / trec;
  87. }
  88. var color = 0;
  89. if (dd <= 0.3) { color = 1;
  90. } else if (dd <= 0.5) { color = 2;
  91. } else if (dd <= 0.7) { color = 3;
  92. } else if (dd <= 1) { color = 4;
  93. } else { color = 5;
  94. }
  95. var record = String(trec);
  96. if (trec != trec2) record += ' - '+String(trec2);
  97. if (trec > 0 && prec > 0) {
  98. newtd.innerHTML = '<a href="'+url+'&mid='+armyx+'#'+armyx+'"><img src="i/map/nl'+String(color)+'.gif" border="0" alt="'+text_record+': '+record+'" title="'+text_record+': '+record+'" width="12" height="12"></a>';
  99. } else {
  100. newtd.innerHTML = '&nbsp;';}}
  101. newtd.setAttribute('class', 'wblight');
  102. where.childNodes[i].insertBefore(newtd, where.childNodes[i].childNodes[0]);}
  103. log.innerHTML = text_loaded;}
  104. function parserecs()
  105. {if (xmlhttp.readyState == 4) {
  106. if (xmlhttp.status == 200) {
  107. log.innerHTML = text_parsrec;
  108. var pos1 = xmlhttp.responseText.indexOf('class=wblight');
  109. var pos2 = xmlhttp.responseText.indexOf('<tr><td', pos1+10);
  110. var pos3 = xmlhttp.responseText.indexOf('</table>', pos2+5);
  111. if (pos1 == -1 || pos2 == -1 || pos3 == -1) {
  112. log.innerHTML = text_err+': parse2 1st err'; return;}
  113. var text = xmlhttp.responseText.substr(pos2, pos3-pos2) + '<tr>';
  114. pos1 = 0;
  115. pos2 = text.indexOf('<tr>', pos1+1);
  116. var m, name, value, hash = {}, hash2 = {};
  117. while(pos2 != -1) {
  118. var textt = text.substr(pos1, pos2-pos1);
  119. if (textt.indexOf('rowspan=') > 0) {
  120. if (m = textt.match(/'army_info\.php\?name=(\S+)'/)) {
  121. name = m[1];}}
  122. if (m = textt.match(/'warlog\.php\?warid=\d+'>(\d+)</)) {
  123. value = m[1];}
  124. hash[name] = value;
  125. if (textt.indexOf('rowspan=') > 0) {
  126. hash2[name] = value;}
  127. pos1 = pos2;
  128. pos2 = text.indexOf('<tr>', pos1+1);}
  129. setsem(hash, hash2);}
  130. else {log.innerHTML = text_err+': http code is '+String(xmlhttp.status);}}}
  131. function getrecs()
  132. {log.innerHTML = text_loadrec;
  133. xmlhttp.open('GET', url, true);
  134. xmlhttp.onreadystatechange = parserecs;
  135. xmlhttp.send(null);}
  136. function parseplayer()
  137. {if (xmlhttp.readyState == 4) {
  138. if (xmlhttp.status == 200) {
  139. log.innerHTML = text_parspl;
  140. var pos1 = xmlhttp.responseText.indexOf('class=wblight');
  141. var pos2 = xmlhttp.responseText.indexOf('male.gif');
  142. if (pos1 == -1 || pos2 == -1 || pos1 > pos2) {
  143. log.innerHTML = text_err+': parse 1st err';
  144. return;}
  145. var text = xmlhttp.responseText.substr(pos1, pos2-pos1);
  146. var m;
  147. if (m = text.match(/\[(\d+)\]&nbsp;<img src='i\/r(\d+).gif'/)) {
  148. url = '/plstats_hunters.php?level='+String(m[1])+'&race='+String(m[2]);
  149. log.innerHTML = text_sleeping;
  150. setTimeout(getrecs, 2000);}
  151. else {log.innerHTML = text_err+': parse 2nd err'; return;}}
  152. else {log.innerHTML = text_err+': http code is '+String(xmlhttp.status);}}}
  153. var xmlhttp = new XMLHttpRequest();
  154. if (!xmlhttp) {
  155. log.innerHTML = text_err+': xmlhttp create';
  156. return;}
  157. var alla = where.childNodes[1].getElementsByTagName('a');
  158. var url = false;
  159. for(var i=0; i<alla.length; i++) {
  160. if (alla[i].href.indexOf('pl_info.php?') > 0) {
  161. url = alla[i].href;
  162. break;}}
  163. if (url == false) {
  164. log.innerHTML = text_err+': error 1';
  165. return;}
  166. log.innerHTML = text_loadpl;
  167. xmlhttp.open('GET', url, true);
  168. xmlhttp.onreadystatechange = parseplayer;
  169. xmlhttp.send(null);}
  170. var newtr = document.createElement('tr');
  171. var newtd = document.createElement('td');
  172. var newa = document.createElement('a');
  173. newtd.setAttribute('align', 'center');
  174. newa.innerHTML = text_loadsem;
  175. newa.href = '#';
  176. newtd.appendChild(newa);
  177. newtr.appendChild(newtd);
  178. var alltbl = document.getElementsByTagName('table');
  179. var ctbl = false;
  180. var wb = false;
  181. for(var i=0;i<alltbl.length;i++) {
  182. if (alltbl[i].getAttribute('class') == 'wbwhite') {
  183. ctbl = alltbl[i];
  184. newa.addEventListener('click', function(e) {
  185. e.preventDefault();
  186. loadsem(newtd, wb.childNodes[0]);}, false);
  187. var n = ctbl.childNodes[0];
  188. n.insertBefore(newtr, n.childNodes[insertafter ? 2 : 1]);}
  189. else if (alltbl[i].getAttribute('class') == 'wb') {
  190. wb = alltbl[i];}}

comments powered by Disqus