MediaWiki:Common.js: Difference between revisions

From Emmy The Robot Fandom Wiki
Content added Content deleted
No edit summary
No edit summary
Line 6: Line 6:
document.getElementsByTagName('h1')[0].remove();
document.getElementsByTagName('h1')[0].remove();
}
}

// Function to initialize the text parsing and filtering functionality
function initializeTextParser() {
// Create a search input field
var searchInput = document.createElement('input');
searchInput.setAttribute('type', 'text');
searchInput.setAttribute('id', 'mediawiki-text-parser-input');
searchInput.setAttribute('placeholder', 'Search...');
document.getElementById('mw-content-text').insertBefore(searchInput, document.getElementById('mw-content-text').firstChild);

// Attach an event listener to the search input field
searchInput.addEventListener('input', function() {
var searchText = this.value.toLowerCase();

// Get all paragraphs in the content area
var paragraphs = document.querySelectorAll('#mw-content-text p');

// Loop through each paragraph
for (var i = 0; i < paragraphs.length; i++) {
var paragraph = paragraphs[i];
var paragraphText = paragraph.textContent.toLowerCase();

// Check if the paragraph contains the search text
if (paragraphText.includes(searchText)) {
paragraph.style.display = 'block'; // Show the paragraph
} else {
paragraph.style.display = 'none'; // Hide the paragraph
}
}
});
}

// Call the initializeTextParser function when the DOM is ready
document.addEventListener('DOMContentLoaded', function() {
initializeTextParser();
});

Revision as of 05:27, 9 May 2024

if ( mw.config.get( 'wgPageName' ) === 'Main_Page' ) {
    document.getElementsByTagName('br')[0].remove();
}

if ( mw.config.get( 'wgPageName' ) === 'Main_Page' ) {
    document.getElementsByTagName('h1')[0].remove();
}

// Function to initialize the text parsing and filtering functionality
function initializeTextParser() {
    // Create a search input field
    var searchInput = document.createElement('input');
    searchInput.setAttribute('type', 'text');
    searchInput.setAttribute('id', 'mediawiki-text-parser-input');
    searchInput.setAttribute('placeholder', 'Search...');
    document.getElementById('mw-content-text').insertBefore(searchInput, document.getElementById('mw-content-text').firstChild);

    // Attach an event listener to the search input field
    searchInput.addEventListener('input', function() {
        var searchText = this.value.toLowerCase();

        // Get all paragraphs in the content area
        var paragraphs = document.querySelectorAll('#mw-content-text p');

        // Loop through each paragraph
        for (var i = 0; i < paragraphs.length; i++) {
            var paragraph = paragraphs[i];
            var paragraphText = paragraph.textContent.toLowerCase();

            // Check if the paragraph contains the search text
            if (paragraphText.includes(searchText)) {
                paragraph.style.display = 'block'; // Show the paragraph
            } else {
                paragraph.style.display = 'none'; // Hide the paragraph
            }
        }
    });
}

// Call the initializeTextParser function when the DOM is ready
document.addEventListener('DOMContentLoaded', function() {
    initializeTextParser();
});