MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 14: | Line 14: | ||
if ($li.children('.fandom-toc-toggle').length === 0) { | if ($li.children('.fandom-toc-toggle').length === 0) { | ||
// Insert a purple clickable arrow before the link | // Insert a purple clickable arrow before the link | ||
$li.prepend(' | $li.prepend(''); | ||
} | } | ||
}); | }); | ||
| Line 33: | Line 33: | ||
}); | }); | ||
mw.hook('wikipage.content').add(function($content) { | mw.hook('wikipage.content').add(function($content) { | ||
var | var glossary = [ | ||
{ regex: /\b(BnB|BNB)s?\b/g, url: 'https://glossary.infil.net/?t=Bread%20and%20Butter' }, | |||
{ regex: /\b(Hyper\s*Armor)\b/gi, url: 'https://glossary.infil.net/?t=Armor' } | |||
]; | |||
$content. | var walker = document.createTreeWalker( | ||
$content.get(0), | |||
NodeFilter.SHOW_TEXT, | |||
{ | |||
acceptNode: function(node) { | |||
var parent = node.parentElement; | |||
if (!parent) return NodeFilter.FILTER_ACCEPT; | |||
if (parent.closest('a, #toc, .toc, .mw-editsection, pre, code')) { | |||
return NodeFilter.FILTER_REJECT; | |||
} | |||
return NodeFilter.FILTER_ACCEPT; | |||
} | |||
}, | |||
false | |||
); | |||
var nodesToProcess = []; | |||
while (walker.nextNode()) { | |||
nodesToProcess.push(walker.currentNode); | |||
} | |||
nodesToProcess.forEach(function(node) { | |||
var text = node.nodeValue; | |||
var newHtml = text; | |||
var modified = false; | |||
glossary.forEach(function(item) { | |||
item.regex.lastIndex = 0; | |||
if (item.regex.test(newHtml)) { | |||
newHtml = newHtml.replace(item.regex, '<a href="' + item.url + '" class="external text" target="_blank" rel="noreferrer noopener">$&</a>'); | |||
if ( | modified = true; | ||
} | } | ||
} | }); | ||
if (modified) { | |||
$(node).replaceWith(newHtml); | $(node).replaceWith(newHtml); | ||
} | } | ||
}); | }); | ||
}); | }); | ||
Latest revision as of 19:49, 11 May 2026
/*PLEASE DON'T MESS WITH*/
$(function() {
var homeTab = document.querySelector('#ca-talk a');
if (homeTab) {
homeTab.setAttribute('href', 'https://wiki.jcraft-eoe.com/index.php?title=Main_Page');
// Ensure the link is physically clickable
homeTab.style.pointerEvents = 'auto';
homeTab.style.display = 'inline-block';
}
});
mw.hook('wikipage.content').add(function($content) {
$content.find('#toc li').has('ul').each(function() {
var $li = $(this);
if ($li.children('.fandom-toc-toggle').length === 0) {
// Insert a purple clickable arrow before the link
$li.prepend('');
}
});
$content.find('.fandom-toc-toggle').off('click').on('click', function(e) {
e.preventDefault();
e.stopPropagation();
var $toggle = $(this);
var $sublist = $toggle.siblings('ul');
$sublist.slideToggle(200, function() {
if ($sublist.is(':visible')) {
$toggle.css('transform', 'rotate(0deg)');
} else {
$toggle.css('transform', 'rotate(-90deg)');
}
});
});
});
mw.hook('wikipage.content').add(function($content) {
var glossary = [
{ regex: /\b(BnB|BNB)s?\b/g, url: 'https://glossary.infil.net/?t=Bread%20and%20Butter' },
{ regex: /\b(Hyper\s*Armor)\b/gi, url: 'https://glossary.infil.net/?t=Armor' }
];
var walker = document.createTreeWalker(
$content.get(0),
NodeFilter.SHOW_TEXT,
{
acceptNode: function(node) {
var parent = node.parentElement;
if (!parent) return NodeFilter.FILTER_ACCEPT;
if (parent.closest('a, #toc, .toc, .mw-editsection, pre, code')) {
return NodeFilter.FILTER_REJECT;
}
return NodeFilter.FILTER_ACCEPT;
}
},
false
);
var nodesToProcess = [];
while (walker.nextNode()) {
nodesToProcess.push(walker.currentNode);
}
nodesToProcess.forEach(function(node) {
var text = node.nodeValue;
var newHtml = text;
var modified = false;
glossary.forEach(function(item) {
item.regex.lastIndex = 0;
if (item.regex.test(newHtml)) {
newHtml = newHtml.replace(item.regex, '<a href="' + item.url + '" class="external text" target="_blank" rel="noreferrer noopener">$&</a>');
modified = true;
}
});
if (modified) {
$(node).replaceWith(newHtml);
}
});
});