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.3
- // @description second searchbox with OR regex, lowercase and capital doesn't matter so don't use /i. parses gametype and lobby name. Usage: a|b returns anything with a or b. Note that Regular Search takes precedence, so if you have no results, clear the first search and try again. The page will refresh every 3 seconds.
- // @author xThomas
- // @match https://aoe2.net/
- // @icon https://www.google.com/s2/favicons?domain=aoe2.net
- // @grant none
- // @run-at document-end
- // ==/UserScript==
- (function() {
- 'use strict';
- setTimeout(main_Func, 400); // Wait 400 milliseconds after page load before starting the script
- })();
- // TODO: do not refresh if tab is not focused
- // TODO: Alerts for iOS users through Spontit app if game is available
- // TODO: Allow users to set refresh frequency
- // TODO: Allow user to pause refresh
- var searchCount = 0;
- 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 = "";
- }
- }
- console.log("SearchCount = " + (searchCount++) + "\n");
- }
- function main_Func(){
- // 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");
- if (!OLDSEARCHBOX) {
- console.log("OLDSEARCHBOX is null, timeout for 1 second and try again");
- setTimeout(main_Func, 1000);
- return;
- } else {
- if (!SEARCHNODE) {
- console.log("OLDSEARCHBOX is not null, but SEARCHNODE is null.\ntimeout for 1 second and try again");
- setTimeout(main_Func, 1000);
- return;
- } else {
- console.log("OLDSEARCHBOX is not null and SEARCHNODE is not null.");
- //console.log("Proceed to disable old search box and create new search box.");
- console.log("Proceed to create new search box.");
- console.log("Value of OLDSEARCHBOX = " + OLDSEARCHBOX.value + "\nProceed to clear input value");
- OLDSEARCHBOX.value = "";
- console.log("Value of OLDSEARCHBOX = " + OLDSEARCHBOX.value + "");
- // Old search box is absolute
- // OLDSEARCHBOX.disabled= "true";
- // SEARCHNODE.removeChild(OLDSEARCHBOX);
- OLDSEARCHBOX.placeholder = "Default Search";
- var NEWSEARCHBOX = document.createElement("input");
- NEWSEARCHBOX.id = 'regex-search';
- NEWSEARCHBOX.setAttribute("type", "text");
- NEWSEARCHBOX.onkeyup = SearchIt;
- NEWSEARCHBOX.placeholder="Enhanced: Use | for OR";
- SEARCHNODE.appendChild(NEWSEARCHBOX);
- var INTERVAL_TIME = 3000; // Set to 3 seconds
- setInterval(SearchIt, INTERVAL_TIME);
- }
- }
- }
Add Comment
Please, Sign In to add comment