Add a 'hide' button for each column. It's ugly, but it works for now.
This commit is contained in:
parent
da81235b17
commit
74e27c3191
112
erkul_column_filter.user.js
Normal file
112
erkul_column_filter.user.js
Normal file
|
@ -0,0 +1,112 @@
|
|||
// ==UserScript==
|
||||
// @name Erkul Column Filter
|
||||
// @namespace https://annabunch.es
|
||||
// @version 0.2
|
||||
// @description Selectively hide columns on erkul.games
|
||||
// @copyright 2021, annabunches@gmail.com
|
||||
// @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==
|
||||
|
||||
waitForKeyElements("tr.mat-header-row", makeColumnFilter);
|
||||
waitForKeyElements("div.filter", makeRedundantButton);
|
||||
|
||||
function makeButton(text) {
|
||||
let button = $(document.createElement("div"));
|
||||
button.html('<button _ngcontent-dae-c11="" class="mat-focus-indicator mat-stroked-button mat-button-base mat-primary" color="primary" mat-stroked-button=""><span class="mat-button-wrapper">' + text + '</span><span class="mat-button-ripple mat-ripple" matripple=""></span><span class="mat-button-focus-overlay"></span></button>');
|
||||
return button;
|
||||
}
|
||||
|
||||
function makeColumnFilter(jNode) {
|
||||
let cols = $("th", jNode);
|
||||
|
||||
for (let i = 0; i < $(cols).length; i++) {
|
||||
let button = makeButton("Hide");
|
||||
$(cols[i]).append(button);
|
||||
button.click(function() {
|
||||
hideColumn(i);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function makeRedundantButton(jNode) {
|
||||
let button = makeButton("Hide Redundant");
|
||||
jNode.append(button);
|
||||
button.click(function() {
|
||||
let headers = $("tr.mat-header-row th");
|
||||
// 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);
|
||||
if (last == "") {
|
||||
last = $(cols[i]).html();
|
||||
} else if ($(cols[i]).html() != last) {
|
||||
diff = true;
|
||||
}
|
||||
});
|
||||
|
||||
// hide that column.
|
||||
if (diff === false) {
|
||||
hideColumn(i);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
console.log("Erkul Column Filter Plugin fully loaded.");
|
||||
}
|
||||
|
||||
function getColumnIndex(name) {
|
||||
let i;
|
||||
let found = false;
|
||||
let headers = $("tr.mat-header-row th");
|
||||
for (i = 0; i < headers.length; i++) {
|
||||
if ($(headers[i]).text() == name) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) return -1;
|
||||
return i;
|
||||
}
|
||||
|
||||
function hideColumnByName(name) {
|
||||
let i = getColumnIndex(name);
|
||||
if (i == -1) return;
|
||||
hideColumn(i);
|
||||
}
|
||||
|
||||
function hideColumn(i) {
|
||||
$($("tr.mat-header-row th")[i]).hide();
|
||||
|
||||
$.each($("tr.mat-row"), function(j, row) {
|
||||
let cols = $("td", row);
|
||||
$(cols[i]).hide();
|
||||
});
|
||||
}
|
||||
|
||||
function showColumnByName(name) {
|
||||
let i = getColumnIndex(name);
|
||||
if (i == -1) return;
|
||||
showColumn(i);
|
||||
}
|
||||
|
||||
function showColumn(i) {
|
||||
$($("tr.mat-header-row th")[i]).show();
|
||||
|
||||
$.each($("tr.mat-row"), function(j, row) {
|
||||
let cols = $("td", row);
|
||||
$(cols[i]).show();
|
||||
});
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
// ==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('<button _ngcontent-dae-c11="" class="mat-focus-indicator mat-stroked-button mat-button-base mat-primary" color="primary" mat-stroked-button=""><span class="mat-button-wrapper">Hide Redundant</span><span class="mat-button-ripple mat-ripple" matripple=""></span><span class="mat-button-focus-overlay"></span></button>');
|
||||
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.");
|
Loading…
Reference in New Issue
Block a user