MediaWiki:Common.js: Difference between revisions
From Emmy The Robot Fandom Wiki
Content added Content deleted
No edit summary |
No edit summary |
||
Line 14: | Line 14: | ||
searchInput.setAttribute('id', 'mediawiki-text-parser-input'); |
searchInput.setAttribute('id', 'mediawiki-text-parser-input'); |
||
searchInput.setAttribute('placeholder', 'Type to searchmol'); |
searchInput.setAttribute('placeholder', 'Type to searchmol'); |
||
// Set the width of the search input field as a percentage |
|||
searchInput.style.width = '50%'; // You can adjust the percentage here |
|||
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 24: | Line 28: | ||
// Get all rows in the table |
// Get all rows in the table |
||
var rows = table. |
var rows = table.query |
||
// Loop through each row |
|||
rows.forEach(function(row, index) { |
|||
if (index === 0) { |
|||
// Show the first row (headers) always |
|||
row.style.display = 'table-row'; |
|||
} else { |
|||
var rowCells = row.cells; |
|||
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 { |
|||
row.style.display = 'none'; |
|||
} |
|||
} |
|||
}); |
|||
}); |
|||
} |
|||
// Call the initializeTextParser function when the DOM is ready |
|||
function initializeTextParserOnLoad() { |
|||
var pageTitle = document.title; |
|||
if (pageTitle === "List of fan Nandroids" || pageTitle === "List of fan stories") { |
|||
initializeTextParser(); |
|||
} |
|||
} |
|||
// Call the initializeTextParserOnLoad function when the entire page is loaded |
|||
window.onload = initializeTextParserOnLoad; |