HWM warlog results

Adds links to a warlog.php page and battle results

  1. // ==UserScript==
  2. // @name HWM warlog results
  3. // @namespace alex@kocharin.ru
  4. // @description Adds links to a warlog.php page and battle results
  5. // @include https://www.heroeswm.ru/pl_warlog.php?*
  6. // @include https://www.heroeswm.com/pl_warlog.php?*
  7. // @include https://rus.heroeswm.com/pl_warlog.php?*
  8. // @include https://*lordswm.com/pl_warlog.php*
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // @version 0.0.1.20230906122812
  12. // ==/UserScript==
  13.  
  14. /*
  15. * Copyright (c) 2008-2011 by Alex Kocharin <alex@kocharin.pp.ru>
  16. *
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation; either version 2 of the License, or
  20. * (at your option) any later version.
  21. *
  22. *
  23. * Script itself:
  24. * http://hwm.kocharin.ru/gm/hwm_warlog_results/
  25. */
  26.  
  27. function addGlobalStyle(css) {
  28. var head, style;
  29. head = document.getElementsByTagName('head')[0];
  30. if (!head) { return; }
  31. style = document.createElement('style');
  32. style.type = 'text/css';
  33. style.innerHTML = css;
  34. head.appendChild(style);
  35.  
  36. }
  37.  
  38. function create_div(e, warid, links)
  39. {
  40. var newdiv = document.getElementById('bce_results');
  41. if (!newdiv) {
  42. newdiv = document.createElement('div');
  43. newdiv.setAttribute('id', 'bce_results');
  44. with (newdiv.style) {
  45. position = 'absolute';
  46. borderStyle = 'solid';
  47. borderColor = '#000000';
  48. borderWidth = '2px';
  49. padding = '0px';
  50. zIndex = '3';
  51. }
  52. }
  53. newdiv.style.left = e.pageX + 5;
  54. newdiv.style.top = e.pageY + 5;
  55. newdiv.style.display = 'block';
  56. newdiv.innerHTML = '<table cellspacing=4 cellpadding=0 bgcolor="#ddd9cd">'+
  57. '<tr>'+
  58. '<td align="left">Warid <b>'+warid+'</b>:</td>'+
  59. '<td align="center"><a class="wars" href="'+links[0]+'">&lt;&lt; begin</a></td>'+
  60. '<td align="center"><a class="wars" href="'+links[1]+'">#chat</a></td>'+
  61. '<td align="center"><a class="wars" href="'+links[2]+'">end &gt;&gt;</a></td>'+
  62. '<td align="right"><a href="#" id="close_div" onclick="var x=document.getElementById(\'bce_results\');x.parentNode.removeChild(x);return false;">[X]</a></td>'+
  63. '</tr>'+
  64. '<tr><td align="left" id="bce_results_hr" colspan="5"></td></tr>'+
  65. '<tr><td align="left" id="bce_results_cont" colspan="5"></td></tr>'+
  66. '</table>';
  67. document.body.appendChild(newdiv);
  68. // document.getElementById('close_div').onclick = function() {
  69. // newdiv.style.display = 'none';
  70. // return false;
  71. // }
  72. return newdiv;
  73. }
  74.  
  75. function load_battle(url)
  76. {
  77. var xmlhttp = new XMLHttpRequest();
  78. xmlhttp.open('GET', url, true);
  79. xmlhttp.overrideMimeType("text/plain; charset=UTF-8");
  80. xmlhttp.onreadystatechange = function() {
  81. parsebattle(xmlhttp);
  82. }
  83. xmlhttp.send(null);
  84. }
  85.  
  86. function parsebattle(xmlhttp)
  87. {
  88. var div = document.getElementById('bce_results_cont');
  89. if (xmlhttp.readyState != 4) return;
  90. if (xmlhttp.status != 200) {
  91. div.innerHTML = 'http error '+String(xmlhttp.status);
  92. return;
  93. }
  94. document.getElementById('bce_results_hr').innerHTML = '<hr>';
  95. var arr = xmlhttp.responseText.split(";/", 2);
  96. var pos = arr[0].indexOf('f<font size="18"><b>');
  97. if (pos == -1) {
  98. div.innerHTML = 'parse error';
  99. return;
  100. }
  101. var tmp = arr[0].substr(pos+1);
  102. var pos2 = tmp.indexOf('|#');
  103. div.innerHTML = tmp.substr(0, pos2).replace(/size="18"/g, '');
  104. }
  105.  
  106. addGlobalStyle('a.wars { text-decoration: none; color:grey } a.wars:hover { color: black } ');
  107.  
  108. var _alla = document.getElementsByTagName('a');
  109. var alla = [];
  110. for(var i=0;i<_alla.length;i++) {
  111. if (_alla[i].innerHTML.match(/^\d{2}-\d{2}-\d{2} \d{2}:\d{2}/) || _alla[i].innerHTML.match(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}/)) {
  112. alla.push(_alla[i]);
  113. }
  114. }
  115.  
  116. for(var i=0;i<alla.length;i++) {
  117. var m;
  118. if (m = alla[i].href.match(/warlog\.php\?warid=(\d+)/)) {
  119. var myspan = document.createElement('span');
  120.  
  121.  
  122. var newa = document.createElement('a');
  123. var h1 = newa.href = alla[i].href.replace(/\?/, '?lt=-1&');
  124. newa.innerHTML = '<';
  125. newa.setAttribute('class', 'wars');
  126. myspan.appendChild(newa);
  127.  
  128. var newa = document.createElement('a');
  129. var h2 = newa.href = alla[i].href.replace(/warlog\.php/, 'battlechat.php');
  130. newa.innerHTML = '#';
  131. newa.setAttribute('class', 'wars');
  132. myspan.appendChild(newa);
  133.  
  134. var newa = document.createElement('a');
  135. var h3 = newa.href = alla[i].href;
  136. newa.innerHTML = '>';
  137. newa.setAttribute('class', 'wars');
  138. myspan.appendChild(newa);
  139. alla[i].parentNode.insertBefore(myspan, alla[i]);
  140. alla[i].parentNode.insertBefore(document.createTextNode(' '), alla[i]);
  141.  
  142. with({warid: m[1], links: [h1, h2, h3]}) {
  143. alla[i].addEventListener('click', function(e)
  144. {
  145. e.preventDefault();
  146. create_div(e, warid, links);
  147. load_battle(e.target.href.replace('warlog.php', 'battle.php').replace('?', '?lastturn=-2&'));
  148. }, false);
  149. }
  150. }
  151. }