MediaWiki:Common.js
Appearance
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
(function() {
function applyEffects(el) {
const hasEffect = ['wavy', 'rainbow', 'jolt', 'force-glow', 'force-shadow'].some(cls => el.classList.contains(cls));
if (!hasEffect || el.getAttribute('data-animated') === 'true') return;
const text = el.textContent;
const isJolt = el.classList.contains('jolt');
const isWavy = el.classList.contains('wavy');
const isRainbow = el.classList.contains('rainbow');
el.style.setProperty('animation', 'none', 'important');
const newHTML = text.split('').map((c, i) => {
let delays = [];
if (isWavy) delays.push((i * -0.15).toFixed(2) + 's');
if (isRainbow) delays.push((i * -0.15).toFixed(2) + 's');
if (isJolt) {
// Matches the new 0.3s CSS duration for perfect desync
delays.push((Math.random() * -0.3).toFixed(2) + 's');
}
const content = (c === ' ') ? ' ' : c;
const delayStyle = delays.length > 0 ? `animation-delay: ${delays.join(', ')} !important;` : '';
return `<span style="${delayStyle}">${content}</span>`;
}).join('');
el.innerHTML = newHTML;
el.setAttribute('data-animated', 'true');
}
mw.hook('wikipage.content').add(function($content) {
$content.find('.text-animation-container').each(function() {
applyEffects(this);
});
});
})();