Jump to content
Health NZ Taranaki Lab Manual

MediaWiki:Common.js: Difference between revisions

Created page with "→Any JavaScript here will be loaded for all users on every page load.: // Strip "Tests:" namespace prefix from search result titles function stripTestsPrefix($scope) { $scope.find('a[title^="Tests:"]').each(function() { const currentText = $(this).text(); const newText = currentText.replace(/^Tests:/, ''); $(this).text(newText); }); } // Run on initial page load mw.hook('wikipage.content').add(stripTestsPrefix); // Run again if searc..."
 
No edit summary
 
Line 14: Line 14:
// Run again if search results are loaded dynamically (e.g., infinite scroll)
// Run again if search results are loaded dynamically (e.g., infinite scroll)
mw.hook('searchResultsReady').add(stripTestsPrefix);
mw.hook('searchResultsReady').add(stripTestsPrefix);
// Remove all page text snippets from search results
function stripSearchSnippets($scope) {
    $scope.find('.searchresult').remove(); // Removes the snippet paragraph
    $scope.find('.mw-search-result-data').remove(); // Optional: removes size/date line
}
mw.hook('wikipage.content').add(stripSearchSnippets);
mw.hook('searchResultsReady').add(stripSearchSnippets);

Latest revision as of 15:43, 18 September 2025

/* Any JavaScript here will be loaded for all users on every page load. */
// Strip "Tests:" namespace prefix from search result titles
function stripTestsPrefix($scope) {
    $scope.find('a[title^="Tests:"]').each(function() {
        const currentText = $(this).text();
        const newText = currentText.replace(/^Tests:/, '');
        $(this).text(newText);
    });
}

// Run on initial page load
mw.hook('wikipage.content').add(stripTestsPrefix);

// Run again if search results are loaded dynamically (e.g., infinite scroll)
mw.hook('searchResultsReady').add(stripTestsPrefix);

// Remove all page text snippets from search results
function stripSearchSnippets($scope) {
    $scope.find('.searchresult').remove(); // Removes the snippet paragraph
    $scope.find('.mw-search-result-data').remove(); // Optional: removes size/date line
}

mw.hook('wikipage.content').add(stripSearchSnippets);
mw.hook('searchResultsReady').add(stripSearchSnippets);