zitot

aoe2.net tampermonkey script to add OR search

Nov 2nd, 2021 (edited)
806
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         AOE2.net REGEX Search
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  try to take over the world!
  6. // @author       You
  7. // @match        https://aoe2.net/
  8. // @icon         https://www.google.com/s2/favicons?domain=aoe2.net
  9. // @grant        none
  10. // @run-at       document-end
  11.  
  12. // ==/UserScript==
  13. (function() {
  14.     'use strict';
  15.     var TIMEOUT_VALUE = 1000;
  16.     setTimeout(firstStuff, TIMEOUT_VALUE);
  17.     // IMPORTANT: Set a timeout because otherwise i can't disable or hide the oldsearchbox, it keeps coming up as null
  18.     // maybe its using ajax or something i dont rly know.. timeout is the dumb easy way to fix it
  19.     ////
  20. })();
  21.  
  22. function SearchIt() {
  23.     var TABLE = document.querySelector("table#aoe2de-lobbies-table");
  24.     var ROWS = TABLE.rows;
  25.     var NEWSEARCHBOX = document.getElementById("regex-search");
  26.     // note: I should just make a new fragment and then set its display to ""
  27.     // setting each row's display one at a time will cause lots of page reflow
  28.     // that's what i did with my hp business outlet filter
  29.  
  30.     for (let i = ROWS.length - 1; i >= 1; i--) {
  31.         let row = ROWS[i];
  32.         let cell1 = row.cells[1];
  33.         let cell3 = row.cells[3];
  34.  
  35.         let ALLCAPS1 = cell1.innerHTML.toUpperCase();
  36.         let ALLCAPS3 = cell3.innerHTML.toUpperCase();
  37.         let search1 = ALLCAPS1.search(NEWSEARCHBOX.value.toUpperCase());
  38.         let search2 = ALLCAPS3.search(NEWSEARCHBOX.value.toUpperCase());
  39.  
  40.         // string.search returns -1 if it fails to find a match
  41.         if(search1 === -1 && search2 === -1) {
  42.             //hideRow(row);
  43.             row.style.display = "none";
  44.         } else {
  45.             //showRow(row);
  46.             row.style.display = "";
  47.         }
  48.     }
  49. }
  50.  
  51. function firstStuff(){
  52.     // Cell 0 is ignorable
  53.     // Cell 1 is Type (Random Map, Scenario, ..)
  54.     // Cell 2 is ignorable
  55.     // Cell 3 is Lobby Name
  56.     // Cell 4 is Location (Coastal, Arabia, ..)
  57.  
  58.     // Custom Input with OR implemented...
  59.     //document.querySelector("table#aoe2de-lobbies-table").rows[1].cells[3].innerHTML.search("CBA|Michi")
  60.     // REGEX SEARCH
  61.  
  62.  
  63.     var OLDSEARCHBOX = document.querySelector("div label input.form-control.form-control-sm");
  64.     var SEARCHNODE = document.querySelector("div#aoe2de-lobbies-table_filter label");
  65.     OLDSEARCHBOX.disabled= "true";
  66.     SEARCHNODE.removeChild(OLDSEARCHBOX);
  67.     var NEWSEARCHBOX = document.createElement("input");
  68.     NEWSEARCHBOX.id = 'regex-search';
  69.     NEWSEARCHBOX.setAttribute("type", "text");
  70.     NEWSEARCHBOX.onkeyup = SearchIt;
  71.     SEARCHNODE.appendChild(NEWSEARCHBOX);
  72.  
  73. }
  74.  
Add Comment
Please, Sign In to add comment