MediaWiki:Common.js: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Tag: Manual revert
 
(28 intermediate revisions by the same user not shown)
Line 14:
searchInput.setAttribute('id', 'mediawiki-text-parser-input');
searchInput.setAttribute('placeholder', 'Type to search');
 
// Set the width of the search input field as a percentage
searchInput.style.width = '100%'; // You can adjust the percentage here
 
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 ⟶ 27:
var searchText = this.value.toLowerCase();
 
// Get all paragraphsrows in the content areatable
var paragraphsrows = documenttable.querySelectorAll('#table.wikitable.sortable.mw-datatable.jquery-tablesorter ptr');
 
// Loop through each paragraphrow
for rows.forEach(var i = 0; i < paragraphs.length;function(row, i++index) {
varif paragraph(index === 0) paragraphs[i];{
var paragraphText = paragraph.textContent.toLowerCase // Show the first row (headers); always
paragraphrow.style.display = 'blocktable-row'; // Show the paragraph
 
// Check if the paragraph contains the search text
if (paragraphText.includes(searchText)) {
paragraph.style.display = 'block'; // Show the paragraph
} else {
paragraph.style.displayvar rowCells = 'none'row.cells; // Hide the paragraph
var rowShouldBeVisible = false;
 
// Loop through each cell in the row
Array.from(rowCells).forEach(function(cell) {
var cellText = cell.textContent.toLowerCase();
// Check if theany paragraphcell contains the search text
if (paragraphTextcellText.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 {
row.style.display = 'none';
}
}
});
});
}
Line 40 ⟶ 64:
// Call the initializeTextParser function when the DOM is ready
function initializeTextParserOnLoad() {
var pathname = window.location.pathname;
if (document.readyState === "complete" || (document.readyState !== "loading" && !document.documentElement.doScroll)) {
var pageNames = ['List_of_fan_Nandroids', 'List_of_fan_stories'];
// The DOM has already loaded, so call initializeTextParser immediately
if (pageNames.includes(pathname.substring(pathname.lastIndexOf('/') + 1))) {
initializeTextParser();
} else {
// Wait for the DOMContentLoaded event to call initializeTextParser
document.addEventListener('DOMContentLoaded', initializeTextParser);
}
}