MediaWiki:Common.js: Difference between revisions
From Emmy The Robot Fandom Wiki
no edit summary
No edit summary |
No edit summary |
||
Line 13:
searchInput.setAttribute('type', 'text');
searchInput.setAttribute('id', 'mediawiki-text-parser-input');
searchInput.setAttribute('placeholder', 'Type to
document.getElementById('mw-content-text').insertBefore(searchInput, document.getElementById('mw-content-text').firstChild);
// Get the table
var table = document.querySelector('table.wikitable.sortable.mw-datatable.jquery-tablesorter');
// Attach an event listener to the search input field
Line 20 ⟶ 23:
var searchText = this.value.toLowerCase();
// Get all
var rows =
// Loop through each row
rows.forEach(function(row, index) {
// Show the first row (headers) always
var rowShouldBeVisible = false;▼
// Loop through each cell in the row▼
Array.from(rowCells).forEach(function(cell) {▼
var cellText = cell.textContent.toLowerCase();▼
// Check if any cell contains the search text▼
if (cellText.includes(searchText)) {▼
rowShouldBeVisible = true;▼
}▼
});▼
if (rowShouldBeVisible) {▼
row.style.display = 'table-row';
} else {▼
▲ var rowShouldBeVisible = false;
▲ // Loop through each cell in the row
Array.from(rowCells).forEach(function(cell) {
▲ // Check if any cell contains the search text
▲ if (cellText.includes(searchText)) {
▲ rowShouldBeVisible = true;
}
});
▲ } else {
▲ if (rowShouldBeVisible) {
row.style.display = 'table-row';
▲ Array.from(rowCells).forEach(function(cell) {
cell.style.display = 'table-cell';
▲ });
} else {
row.style.display = 'none';
▲ }
}
});
|