MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary Tag: Reverted |
||
Line 22: | Line 22: | ||
} | } | ||
}); | }); | ||
}); | |||
mw.loader.using(['jquery'], function() { | |||
// Listen for new nodes being added to the document | |||
$(document).on('DOMNodeInserted', function(e) { | |||
// Check if the inserted node is a Leaflet popup content element. | |||
if ($(e.target).hasClass('leaflet-popup-content')) { | |||
processPopup($(e.target)); | |||
} | |||
}); | |||
function processPopup($popup) { | |||
var content = $popup.html(); | |||
// Replace all instances of Wiki-link syntax [[Page Name]] with an HTML link. | |||
var newContent = content.replace(/\[\[([^\]]+)\]\]/g, function(match, p1) { | |||
// Convert spaces to underscores (as is common in wiki URLs) | |||
var pageName = p1.replace(/ /g, '_'); | |||
return '<a href="/' + encodeURIComponent(pageName) + '" target="_blank">' + p1 + '</a>'; | |||
}); | |||
$popup.html(newContent); | |||
// Additionally, if the title is in a <strong> tag, convert it to a clickable link. | |||
$popup.find('strong').each(function() { | |||
var titleText = $(this).text(); | |||
// If it’s not already a link, wrap it in an anchor. | |||
if ($(this).find('a').length === 0) { | |||
var link = $('<a>') | |||
.attr('href', '/wiki/' + encodeURIComponent(titleText.replace(/ /g, '_'))) | |||
.attr('target', '_blank') | |||
.text(titleText); | |||
$(this).html(link); | |||
} | |||
}); | |||
} | |||
}); | }); |
Revision as of 03:17, 6 April 2025
$(document).ready(function() {
$('.infoboxTable th').each(function() {
if ($(this).text().trim() === "Image") {
$(this).text(""); // Removes the text but keeps the <th> element
}
});
});
$(document).ready(function() {
$('h2').each(function() {
if ($(this).text().trim() === "Introduction") {
$(this).remove(); // Removes the Introduction header
}
});
});
$(document).ready(function() {
// Remove first empty paragraph (<p><br></p>) if it exists
$('p').first().each(function() {
if ($(this).html().trim() === "<br>") {
$(this).remove();
}
});
});
mw.loader.using(['jquery'], function() {
// Listen for new nodes being added to the document
$(document).on('DOMNodeInserted', function(e) {
// Check if the inserted node is a Leaflet popup content element.
if ($(e.target).hasClass('leaflet-popup-content')) {
processPopup($(e.target));
}
});
function processPopup($popup) {
var content = $popup.html();
// Replace all instances of Wiki-link syntax [[Page Name]] with an HTML link.
var newContent = content.replace(/\[\[([^\]]+)\]\]/g, function(match, p1) {
// Convert spaces to underscores (as is common in wiki URLs)
var pageName = p1.replace(/ /g, '_');
return '<a href="/' + encodeURIComponent(pageName) + '" target="_blank">' + p1 + '</a>';
});
$popup.html(newContent);
// Additionally, if the title is in a <strong> tag, convert it to a clickable link.
$popup.find('strong').each(function() {
var titleText = $(this).text();
// If it’s not already a link, wrap it in an anchor.
if ($(this).find('a').length === 0) {
var link = $('<a>')
.attr('href', '/wiki/' + encodeURIComponent(titleText.replace(/ /g, '_')))
.attr('target', '_blank')
.text(titleText);
$(this).html(link);
}
});
}
});