Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.28 KB | None | 0 0
  1. javascript: function search_table() {
  2. //overview_villages&mode=units&type=away_detail&group=0&page=-1&type=away_detail
  3. if (window.location.href.indexOf('overview_villages&mode=units&type=away_detail&group=0&page=-1&type=away_detail') < 0) {
  4. window.location.assign(game_data.link_base_pure + "overview_villages&mode=units&type=away_detail&group=0&page=-1&type=away_detail");
  5. }
  6. var playersSupported ={};
  7. //html part here, table to prepend is units_table
  8. if ($('button').length == 0) {
  9. var onlyShowOutsideSupport = false;
  10. body = document.getElementById("paged_view_content");
  11. htmlString = `
  12. <div id="supportQuery">
  13. <table id="filterTable" class="vis">
  14. <thead>
  15. <tr>
  16. <th>Filter</th>
  17. <th style="text-align:center" width="">Amount currently filtered</th>
  18. <th></th>
  19. <th></th>
  20. </tr>
  21. </thead>
  22. <tbody>
  23. <td>
  24. <input type="text" ID="search_field_input" name="filter" size="20" margin="5" align=left >
  25. </td>
  26. <td>
  27. <span id="filterCount">Currently 0 filtered</span>
  28. </td>
  29. <td>
  30. <input type="checkbox" ID="showOnlyFiltered" name="showOnlyFiltered" > Show only external support
  31. </td>
  32.  
  33. <td>
  34. <button type="button" ID="button" class="btn-confirm-yes" >Filter for player/tribe</button>
  35. </td>
  36.  
  37. <thead>
  38. <tr>
  39. <th></th>
  40. <th></th>
  41. <th></th>
  42. <th></th>
  43. </tr>
  44. </thead>
  45. </tbody>
  46. </table>
  47. </div>`;
  48.  
  49.  
  50.  
  51. supportDiv = document.createElement('div');
  52. supportDiv.innerHTML = htmlString;
  53. body.prepend(supportDiv.firstChild);
  54.  
  55.  
  56. document.getElementById("showOnlyFiltered").addEventListener("change", function () {
  57. if (document.getElementById("showOnlyFiltered").checked == true) {
  58. onlyShowOutsideSupport = true;
  59. }
  60. else {
  61. onlyShowOutsideSupport = false;
  62. }
  63. });
  64. button.addEventListener("click", function () {
  65. //filter here
  66. // Declare variables
  67. var input, filter, i;
  68. playersSupported={};
  69. input = document.getElementById("search_field_input");
  70. filter = input.value.toUpperCase();
  71. checkboxes = document.getElementsByClassName("village_checkbox");
  72.  
  73. //reseting all checkboxes and counter
  74. amountChecked = 0;
  75. count = 0;
  76. for (i = 0; i < checkboxes.length; i++) checkboxes[i].checked = false;
  77.  
  78. //checking if filter is empty
  79. if (filter == "" || filter.length <= 2) return;
  80.  
  81. //checking through all the checkboxes
  82. for (i = 0; i < checkboxes.length; i++) {
  83. //checking if support is at another player
  84. supportedPlayer = checkboxes[i].nextElementSibling.nextElementSibling;
  85. if (supportedPlayer) {
  86. //check if support is at the right player
  87. if (supportedPlayer.innerHTML.toUpperCase().indexOf(filter) > -1) {
  88. checkboxes[i].checked = true;
  89. amountChecked++;
  90. playerName = supportedPlayer.innerHTML;
  91. tribeName = checkboxes[i].nextElementSibling.nextElementSibling.nextElementSibling.innerHTML;
  92. playersSupported[supportedPlayer.innerHTML]=[
  93. {
  94. name: playerName,
  95. tribe: tribeName,
  96. count: 1+count
  97. }
  98. ]
  99. }
  100. else
  101. //check if filtered on tribe instead
  102. if (checkboxes[i].nextElementSibling.nextElementSibling.nextElementSibling.innerHTML.toUpperCase().indexOf(filter) > -1) {
  103. checkboxes[i].checked = true;
  104. amountChecked++;
  105. playerName = supportedPlayer.innerHTML;
  106. tribeName = checkboxes[i].nextElementSibling.nextElementSibling.nextElementSibling.innerHTML;
  107. playersSupported[supportedPlayer.innerHTML]=[
  108. {
  109. name: playerName,
  110. tribe: tribeName,
  111. count: 1+count
  112. }
  113. ]
  114. createTable([[playersSupported[supportedPlayer.innerHTML][0].name,playersSupported[supportedPlayer.innerHTML][0].tribe,playersSupported[supportedPlayer.innerHTML][0].count]]);
  115.  
  116. }
  117. }
  118. else {
  119. //not our filter, need to hide?
  120. if (onlyShowOutsideSupport == true) {
  121. checkboxes[i].parentNode.parentNode.parentNode.style.display = 'none';
  122. }
  123. }
  124. }
  125. $('span#filterCount').html("Currently " + amountChecked + " filtered");
  126. console.log(playersSupported);
  127. });
  128. }
  129. function createTable(tableData) {
  130.  
  131. var tableBody = document.getElementById("filterTable");
  132.  
  133. tableData.forEach(function (rowData) {
  134. var row = document.getElementById("filterTable").insertRow("-1");
  135.  
  136. rowData.forEach(function (cellData) {
  137. var cell = document.createElement('td');
  138. cell.appendChild(document.createTextNode(cellData));
  139. row.appendChild(cell);
  140. });
  141.  
  142. tableBody.appendChild(row);
  143. });
  144.  
  145. }
  146.  
  147.  
  148. }
  149.  
  150.  
  151.  
  152.  
  153.  
  154. search_table();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement