Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- javascript: function search_table() {
- //overview_villages&mode=units&type=away_detail&group=0&page=-1&type=away_detail
- if (window.location.href.indexOf('overview_villages&mode=units&type=away_detail&group=0&page=-1&type=away_detail') < 0) {
- window.location.assign(game_data.link_base_pure + "overview_villages&mode=units&type=away_detail&group=0&page=-1&type=away_detail");
- }
- var playersSupported ={};
- //html part here, table to prepend is units_table
- if ($('button').length == 0) {
- var onlyShowOutsideSupport = false;
- body = document.getElementById("paged_view_content");
- htmlString = `
- <div id="supportQuery">
- <table id="filterTable" class="vis">
- <thead>
- <tr>
- <th>Filter</th>
- <th style="text-align:center" width="">Amount currently filtered</th>
- <th></th>
- <th></th>
- </tr>
- </thead>
- <tbody>
- <td>
- <input type="text" ID="search_field_input" name="filter" size="20" margin="5" align=left >
- </td>
- <td>
- <span id="filterCount">Currently 0 filtered</span>
- </td>
- <td>
- <input type="checkbox" ID="showOnlyFiltered" name="showOnlyFiltered" > Show only external support
- </td>
- <td>
- <button type="button" ID="button" class="btn-confirm-yes" >Filter for player/tribe</button>
- </td>
- <thead>
- <tr>
- <th></th>
- <th></th>
- <th></th>
- <th></th>
- </tr>
- </thead>
- </tbody>
- </table>
- </div>`;
- supportDiv = document.createElement('div');
- supportDiv.innerHTML = htmlString;
- body.prepend(supportDiv.firstChild);
- document.getElementById("showOnlyFiltered").addEventListener("change", function () {
- if (document.getElementById("showOnlyFiltered").checked == true) {
- onlyShowOutsideSupport = true;
- }
- else {
- onlyShowOutsideSupport = false;
- }
- });
- button.addEventListener("click", function () {
- //filter here
- // Declare variables
- var input, filter, i;
- playersSupported={};
- input = document.getElementById("search_field_input");
- filter = input.value.toUpperCase();
- checkboxes = document.getElementsByClassName("village_checkbox");
- //reseting all checkboxes and counter
- amountChecked = 0;
- count = 0;
- for (i = 0; i < checkboxes.length; i++) checkboxes[i].checked = false;
- //checking if filter is empty
- if (filter == "" || filter.length <= 2) return;
- //checking through all the checkboxes
- for (i = 0; i < checkboxes.length; i++) {
- //checking if support is at another player
- supportedPlayer = checkboxes[i].nextElementSibling.nextElementSibling;
- if (supportedPlayer) {
- //check if support is at the right player
- if (supportedPlayer.innerHTML.toUpperCase().indexOf(filter) > -1) {
- checkboxes[i].checked = true;
- amountChecked++;
- playerName = supportedPlayer.innerHTML;
- tribeName = checkboxes[i].nextElementSibling.nextElementSibling.nextElementSibling.innerHTML;
- playersSupported[supportedPlayer.innerHTML]=[
- {
- name: playerName,
- tribe: tribeName,
- count: 1+count
- }
- ]
- }
- else
- //check if filtered on tribe instead
- if (checkboxes[i].nextElementSibling.nextElementSibling.nextElementSibling.innerHTML.toUpperCase().indexOf(filter) > -1) {
- checkboxes[i].checked = true;
- amountChecked++;
- playerName = supportedPlayer.innerHTML;
- tribeName = checkboxes[i].nextElementSibling.nextElementSibling.nextElementSibling.innerHTML;
- playersSupported[supportedPlayer.innerHTML]=[
- {
- name: playerName,
- tribe: tribeName,
- count: 1+count
- }
- ]
- createTable([[playersSupported[supportedPlayer.innerHTML][0].name,playersSupported[supportedPlayer.innerHTML][0].tribe,playersSupported[supportedPlayer.innerHTML][0].count]]);
- }
- }
- else {
- //not our filter, need to hide?
- if (onlyShowOutsideSupport == true) {
- checkboxes[i].parentNode.parentNode.parentNode.style.display = 'none';
- }
- }
- }
- $('span#filterCount').html("Currently " + amountChecked + " filtered");
- console.log(playersSupported);
- });
- }
- function createTable(tableData) {
- var tableBody = document.getElementById("filterTable");
- tableData.forEach(function (rowData) {
- var row = document.getElementById("filterTable").insertRow("-1");
- rowData.forEach(function (cellData) {
- var cell = document.createElement('td');
- cell.appendChild(document.createTextNode(cellData));
- row.appendChild(cell);
- });
- tableBody.appendChild(row);
- });
- }
- }
- search_table();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement