hwm_gi_battles_loader

Загрузка боёв ГИ

  1. // ==UserScript==
  2. // @name hwm_gi_battles_loader
  3. // @author omne
  4. // @namespace omne
  5. // @connect daily.heroeswm.ru
  6. // @description Загрузка боёв ГИ
  7. // @version 0.3
  8. // @encoding utf-8
  9. // @include /^https{0,1}:\/\/((www|qrator|)\.(heroeswm|lordswm)\.(ru|com)|178\.248\.235\.15)\/(pl_warlog|war).php/
  10. // @grant GM_xmlhttpRequest
  11. // ==/UserScript==
  12. (function() {
  13. if (/pl_warlog/.test(location.href)) {
  14. let pers_id = document.documentElement.innerHTML.match(/pl_hunter_stat\.php\?id=([0-9]+)/)[1];
  15. let data = '';
  16. let ch = 0;
  17. let all_ch = 0;
  18. let elem = document.getElementsByClassName('sh_ResourcesItem_icon')[0];
  19. if (elem === undefined) {
  20. elem = document.getElementsByClassName('rs')[0];
  21. }
  22. elem.addEventListener("click", get_data, false);
  23. function get_data() {
  24. let elem = document.getElementsByClassName('global_container_block_header global_a_hover')[0].nextElementSibling;
  25. elem.insertAdjacentHTML("afterbegin", "<center><span id = 'loader'>Загрузка боёв ГИ:</span></center><BR>");
  26. let last_page = get_last_page();
  27. get_page('/pl_warlog.php?id=' + pers_id + '&page=', 0, last_page);
  28. }
  29. function get_last_page() {
  30. let result = get_hwm('/pl_warlog.php?id=' + pers_id + '&page=9999999');
  31. return result.match(/<a class=\"active\".+?([0-9]+)/)[1];
  32. }
  33. function get_page(url, page, count) {
  34. GM_xmlhttpRequest({
  35. method: "GET",
  36. url: url + page,
  37. onload: function(response) {
  38. let battles = response.responseText.match(/&nbsp;&nbsp;.+?<!--110--><BR>/g);
  39. if (battles !== null) {
  40. for (let j = 0; j < battles.length; j++) {
  41. data = data + battles[j].match(/warid=([0-9]+)/)[1] + "|" + battles[j].match(/(show_for_all|show)=([0-9a-zA-Z\-\_]+)/)[2] + ";";
  42. ch++;
  43. all_ch++;
  44. }
  45. }
  46. if (ch > 100) {
  47. get_daily('https://daily.heroeswm.ru/services/help/gi.php?data=' + data);
  48. data = '';
  49. ch = 0;
  50. }
  51. page++;
  52. if (page <= count) {
  53. document.getElementById('loader').innerHTML = 'Загрузка боёв ГИ: страниц ' + page + '/' + count + '. Боёв найдено: ' + all_ch;
  54. get_page('/pl_warlog.php?id=' + pers_id + '&page=', page, count);
  55. }
  56. else {
  57. get_daily('https://daily.heroeswm.ru/services/help/gi.php?data=' + data);
  58. }
  59. }
  60. });
  61. }
  62. }
  63. if (/war\.php/.test(location.href)) {
  64. let btype = document.documentElement.innerHTML.match(/btypeo\|([0-9]+)/)[1];
  65. if (btype == 110) {
  66. get_daily('https://daily.heroeswm.ru/services/help/gi.php' + location.search);
  67. }
  68. }
  69. function get_daily(url) {
  70. GM_xmlhttpRequest({
  71. method: "GET",
  72. url: url
  73. });
  74. }
  75. function get_hwm(url) {
  76. let xhr = new XMLHttpRequest();
  77. xhr.open('GET', url, false);
  78. xhr.send();
  79. return xhr.responseText;
  80. }
  81. })();