MediaWiki:Common.js: Difference between revisions
From Emmy The Robot Fandom Wiki
Content added Content deleted
No edit summary |
No edit summary |
||
Line 13: | Line 13: | ||
searchInput.setAttribute('type', 'text'); |
searchInput.setAttribute('type', 'text'); |
||
searchInput.setAttribute('id', 'mediawiki-text-parser-input'); |
searchInput.setAttribute('id', 'mediawiki-text-parser-input'); |
||
searchInput.setAttribute('placeholder', 'Type to |
searchInput.setAttribute('placeholder', 'Type to search'); |
||
document.getElementById('mw-content-text').insertBefore(searchInput, document.getElementById('mw-content-text').firstChild); |
document.getElementById('mw-content-text').insertBefore(searchInput, document.getElementById('mw-content-text').firstChild); |
||
Line 21: | Line 21: | ||
// Get all paragraphs in the content area |
// Get all paragraphs in the content area |
||
var |
var rows = document.querySelectorAll('table.wikitable.sortable.mw-datatable.jquery-tablesorter tr:not(:first-child)'); |
||
// Loop through each |
// Loop through each row |
||
rows.forEach(function(row) { |
|||
for (var i = 0; i < paragraphs.length; i++) { |
|||
var |
var rowCells = row.cells; |
||
var |
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; |
|||
} |
|||
}); |
|||
// Set the display property of the row and its cells |
|||
if (rowShouldBeVisible) { |
|||
row.style.display = 'table-row'; |
|||
Array.from(rowCells).forEach(function(cell) { |
|||
cell.style.display = 'table-cell'; |
|||
}); |
|||
} else { |
} else { |
||
row.style.display = 'none'; |
|||
} |
} |
||
} |
}); |
||
}); |
}); |
||
} |
} |