From 59f80fe633fbe4291dbd11cba00a23280154584b Mon Sep 17 00:00:00 2001 From: annabunches Date: Fri, 22 Oct 2021 16:14:36 -0400 Subject: [PATCH] Initial commit --- erkul_redundancy_filter.user.js | 67 +++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 erkul_redundancy_filter.user.js diff --git a/erkul_redundancy_filter.user.js b/erkul_redundancy_filter.user.js new file mode 100644 index 0000000..f83dfcf --- /dev/null +++ b/erkul_redundancy_filter.user.js @@ -0,0 +1,67 @@ +// ==UserScript== +// @name Erkul Redundancy Filter +// @namespace https://annabunch.es +// @version 0.1 +// @description Hide identical columns on erkul.games +// @copyright 2021, annabunches +// @include https://www.erkul.games/* +// @require https://code.jquery.com/jquery-latest.js +// @require https://gist.githubusercontent.com/BrockA/2625891/raw/9c97aa67ff9c5d56be34a55ad6c18a314e5eb548/waitForKeyElements.js +// @grant none +// ==/UserScript== + +console.log("Erkul Redundancy Filter pre-loading."); + +waitForKeyElements("div.filter", loadWidgets); + +function makeButton() { + let button = $(document.createElement("div")); + button.html(''); + return button; +} + +function loadWidgets(jNode) { + console.log("Erkul Redundancy Filter loading."); + let button = makeButton(); + $("div.filter").append(button); + button.click(function() { + // get all the rows + let rows = $("tr.mat-row"); + let nCols = $("td", rows[0]).length; + + // for each column... + for (let i = 0; i < nCols; i++) { + let last = ""; + let diff = false; + + // ... iterate over every row, checking whether that column is different + // on any row. If it is the same everywhere... + $.each(rows, function(j, row){ + let cols = $("td", row); + console.log("Last: " + last); + console.log("This: " + $(cols[i]).html()); + if (last == "") { + last = $(cols[i]).html(); + } else if ($(cols[i]).html() != last) { + diff = true; + } + }); + + // hide that column. + if (diff === false) { + $.each(rows, function(j, row) { + let cols = $("td", row); + $(cols[i]).css("display", "none"); + }); + + // and your little header, too + let headers = $("tr.mat-header-row th"); + $(headers[i]).css("display", "none"); + } + } + }); + + console.log("Erkul Redundancy Filter fully loaded."); +} + +console.log("Erkul Redundancy Filter pre-loaded.");