🏠 返回首頁 

Greasy Fork is available in English.

HWM_Count_Clan_Medals

Подсчет общего кол-ва медалей, турнирного золота членов клана

  1. // ==UserScript==
  2. // @name HWM_Count_Clan_Medals
  3. // @namespace Рианти
  4. // @description Подсчет общего кол-ва медалей, турнирного золота членов клана
  5. // @include http://www.heroeswm.ru/clan_info.php?id=*
  6. // @version 1
  7. // @grant GM_xmlhttpRequest
  8. // ==/UserScript==
  9. function requestPage (url, onloadHandler){
  10. console.log('loading: ', url);
  11. try{
  12. GM_xmlhttpRequest({
  13. overrideMimeType: 'text/plain; charset=windows-1251',
  14. synchronous: false,
  15. url: url,
  16. method: "GET",
  17. onload: function(response){
  18. onloadHandler(new DOMParser().parseFromString(response.responseText, 'text/html').documentElement);
  19. },
  20. onerror: function(){ setTimeout(function(){ requestPage (url, onloadHandler) }, 1000) },
  21. ontimeout: function(){ setTimeout(function(){ requestPage (url, onloadHandler) }, 1000) },
  22. timeout: 5000
  23. });
  24. } catch (e) {
  25. console.log(e);
  26. }
  27. }
  28. function typeMedals (dom){
  29. try{
  30. var cells = dom.querySelectorAll('.srch > td');
  31. if(!cells.length) return [0,0,0,0,0];
  32. var colVals = [];
  33. for (var i = 0; i < 5; i ++){
  34. colVals[i] = parseInt(cells[i + 2].innerHTML.replace(/<[^>]+>/,'').replace(/ /,''));
  35. }
  36. return colVals;
  37. } catch (E) { console.log(E) }
  38. }
  39. function collectPlayers()
  40. {
  41. var outputArray = [];
  42. try {
  43. var p = document.querySelectorAll('a[href*="pl_info.php?id="]');
  44. dataTable = p[p.length-1].parentElement.parentElement.parentElement;
  45. var cells = dataTable.querySelectorAll("td"); //relevant cells are 3, 5 in each row
  46. var rows =cells.length/5;
  47. var tmp,plID,plNick,plLVL;
  48. for (var i = 0; i < rows; i++) {
  49. plLVL = parseInt(cells[i * 5 + 3].innerHTML);
  50. tmp = cells[i * 5 + 2].getElementsByClassName('pi')[0];
  51. plID = tmp.href.split('=')[1];
  52. plNick = tmp.innerHTML;
  53. outputArray.push({plID: plID, plNick: plNick, plLVL: plLVL})
  54. }
  55. return outputArray;
  56. } catch (e) {
  57. console.log(e);
  58. }
  59. }
  60. function collectPlayerData(plID){
  61. var player = allPlayers[plID];
  62. _workArr = [player.plNick, player.plLVL];
  63. requestPage (pages[0] + player.plID, function(dom){
  64. _workArr = _workArr.concat(typeMedals (dom));
  65. requestPage (pages[1] + player.plID, function(dom){
  66. _workArr = _workArr.concat(typeMedals (dom));
  67. requestPage (pages[2] + player.plID, function(dom){
  68. _workArr = _workArr.concat(typeMedals (dom));
  69. requestPage (pages[3] + player.plID, function(dom){
  70. try{
  71. _workArr = _workArr.concat(typeMedals (dom));
  72. fOutput.push(_workArr);
  73. console.log(_workArr)
  74. dataTable.querySelector('a[href*="id=' + player.plID + '"]').style.color = 'white';
  75. if (plID < allPlayers.length - 1) collectPlayerData(plID + 1);
  76. else {
  77. console.log(fOutput);
  78. downloadCSV(fOutput);
  79. }
  80. } catch (e){ console.log(e); console.log(fOutput); downloadCSV(fOutput);}
  81. });
  82. });
  83. });
  84. });
  85. }
  86. function downloadCSV(twoDArray){
  87. var csvContent = "data:text/csv;charset=utf-8,";
  88. for(var row in twoDArray){
  89. csvContent += twoDArray[row].join("|").replace(/\./g, ',') + "\n";
  90. }
  91. var encodedUri = encodeURI(csvContent);
  92. alert('Сейчас вам будет предложено загрузить файл со статистикой. При сохранении установите расширешие .csv\nВ дальнейшем, вы сможете открыть его для работы в Экселе или аналогах.');
  93. window.open(encodedUri);
  94. }
  95. function addQuickLink (label, id, action){
  96. var quickLinksTableTR = document.querySelector('body > center:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1)');
  97. var td = document.createElement('td');
  98. td.innerHTML = '<div id="breadcrumbs" style="z-index: auto;"><ul style="z-index: auto;"><li class="subnav" style="z-index: auto;"><nobr>\
  99. | <a class="pi" id="' + id + '" href="javascript:void(0)">' + label + '</a>\
  100. </nobr></li></ul></div>';
  101. quickLinksTableTR.appendChild(td);
  102. var elem = document.getElementById(id);
  103. elem.onclick = action;
  104. }
  105. var _workArr;
  106. var dataTable;
  107. var pages = [
  108. 'http://bizzle.ru/hwm/pvp_tour/?typetour=1&srch=', // МТ
  109. 'http://bizzle.ru/hwm/pvp_tour/?typetour=2&srch=', // ПТ
  110. 'http://bizzle.ru/hwm/pvp_tour/?typetour=4&srch=', // СмТ
  111. 'http://bizzle.ru/hwm/pvp_tour/?typetour=5&srch=' // ПТЭ
  112. ];
  113. var fOutput = [
  114. [
  115. 'Ник', 'БУ', 'МТ-Зол', 'МТ-Сер', 'МТ-бронз', 'МТ-10%', 'МТ-доход', 'ПТ-Зол', 'ПТ-Сер', 'ПТ-бронз', 'ПТ-10%', 'ПТ-доход', 'СмТ-Зол', 'СмТ-Сер', 'СмТ-бронз', 'СмТ-10%', 'СмТ-доход', 'ПТЭ-Зол', 'ПТЭ-Сер', 'ПТЭ-бронз', 'ПТЭ-10%', 'ПТЭ-доход'
  116. ]
  117. ];
  118. var allPlayers = collectPlayers();
  119. addQuickLink ('Считать медали', 'count_medals',
  120. function (){
  121. collectPlayerData(0);
  122. });