MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 11: | Line 11: | ||
el.style.setProperty('animation', 'none', 'important'); | el.style.setProperty('animation', 'none', 'important'); | ||
let lastVariant = -1; | |||
const newHTML = text.split('').map((c, i) => { | const newHTML = text.split('').map((c, i) => { | ||
let delays = []; | let delays = []; | ||
let classes = []; | |||
if (isWavy) delays.push((i * -0.15).toFixed(2) + 's'); | if (isWavy) delays.push((i * -0.15).toFixed(2) + 's'); | ||
| Line 19: | Line 22: | ||
if (isJolt) { | if (isJolt) { | ||
// | // 1. Pick a variant (1-3) different from the previous neighbor | ||
delays.push((Math.random() * -0. | let variant; | ||
do { | |||
variant = Math.floor(Math.random() * 3) + 1; | |||
} while (variant === lastVariant); | |||
lastVariant = variant; | |||
classes.push(`jolt-v${variant}`); | |||
// 2. Add random delay (0-0.35s) to further break synchronization | |||
delays.push((Math.random() * -0.35).toFixed(2) + 's'); | |||
} | } | ||
const content = (c === ' ') ? ' ' : c; | const content = (c === ' ') ? ' ' : c; | ||
const delayStyle = delays.length > 0 ? `animation-delay: ${delays.join(', ')} !important;` : ''; | const delayStyle = delays.length > 0 ? `style="animation-delay: ${delays.join(', ')} !important;"` : ''; | ||
const classAttr = classes.length > 0 ? `class="${classes.join(' ')}"` : ''; | |||
return `<span | return `<span ${classAttr} ${delayStyle}>${content}</span>`; | ||
}).join(''); | }).join(''); | ||
Revision as of 22:05, 17 March 2026
/* 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');
let lastVariant = -1;
const newHTML = text.split('').map((c, i) => {
let delays = [];
let classes = [];
if (isWavy) delays.push((i * -0.15).toFixed(2) + 's');
if (isRainbow) delays.push((i * -0.15).toFixed(2) + 's');
if (isJolt) {
// 1. Pick a variant (1-3) different from the previous neighbor
let variant;
do {
variant = Math.floor(Math.random() * 3) + 1;
} while (variant === lastVariant);
lastVariant = variant;
classes.push(`jolt-v${variant}`);
// 2. Add random delay (0-0.35s) to further break synchronization
delays.push((Math.random() * -0.35).toFixed(2) + 's');
}
const content = (c === ' ') ? ' ' : c;
const delayStyle = delays.length > 0 ? `style="animation-delay: ${delays.join(', ')} !important;"` : '';
const classAttr = classes.length > 0 ? `class="${classes.join(' ')}"` : '';
return `<span ${classAttr} ${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);
});
});
})();