Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name AOE2.net REGEX Search
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description try to take over the world!
- // @author You
- // @match https://aoe2.net/
- // @icon https://www.google.com/s2/favicons?domain=aoe2.net
- // @grant none
- // @run-at document-end
- // ==/UserScript==
- (function() {
- 'use strict';
- var TIMEOUT_VALUE = 1000;
- setTimeout(firstStuff, TIMEOUT_VALUE);
- // IMPORTANT: Set a timeout because otherwise i can't disable or hide the oldsearchbox, it keeps coming up as null
- // maybe its using ajax or something i dont rly know.. timeout is the dumb easy way to fix it
- ////
- })();
- function SearchIt() {
- var TABLE = document.querySelector("table#aoe2de-lobbies-table");
- var ROWS = TABLE.rows;
- var NEWSEARCHBOX = document.getElementById("regex-search");
- // note: I should just make a new fragment and then set its display to ""
- // setting each row's display one at a time will cause lots of page reflow
- // that's what i did with my hp business outlet filter
- for (let i = ROWS.length - 1; i >= 1; i--) {
- let row = ROWS[i];
- let cell1 = row.cells[1];
- let cell3 = row.cells[3];
- let ALLCAPS1 = cell1.innerHTML.toUpperCase();
- let ALLCAPS3 = cell3.innerHTML.toUpperCase();
- let search1 = ALLCAPS1.search(NEWSEARCHBOX.value.toUpperCase());
- let search2 = ALLCAPS3.search(NEWSEARCHBOX.value.toUpperCase());
- // string.search returns -1 if it fails to find a match
- if(search1 === -1 && search2 === -1) {
- //hideRow(row);
- row.style.display = "none";
- } else {
- //showRow(row);
- row.style.display = "";
- }
- }
- }
- function firstStuff(){
- // Cell 0 is ignorable
- // Cell 1 is Type (Random Map, Scenario, ..)
- // Cell 2 is ignorable
- // Cell 3 is Lobby Name
- // Cell 4 is Location (Coastal, Arabia, ..)
- // Custom Input with OR implemented...
- //document.querySelector("table#aoe2de-lobbies-table").rows[1].cells[3].innerHTML.search("CBA|Michi")
- // REGEX SEARCH
- var OLDSEARCHBOX = document.querySelector("div label input.form-control.form-control-sm");
- var SEARCHNODE = document.querySelector("div#aoe2de-lobbies-table_filter label");
- OLDSEARCHBOX.disabled= "true";
- SEARCHNODE.removeChild(OLDSEARCHBOX);
- var NEWSEARCHBOX = document.createElement("input");
- NEWSEARCHBOX.id = 'regex-search';
- NEWSEARCHBOX.setAttribute("type", "text");
- NEWSEARCHBOX.onkeyup = SearchIt;
- SEARCHNODE.appendChild(NEWSEARCHBOX);
- }
Add Comment
Please, Sign In to add comment