Jump to content

MediaWiki:Common.js: Difference between revisions

From FC1
No edit summary
Tag: Reverted
No edit summary
 
(26 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
function applyEffects(el) {
(function() {
  const chars = el.textContent.split('');
    function applyEffects(el) {
  const total = chars.length;
        const hasEffect = ['wavy', 'rainbow', 'jolt', 'pulse', 'force-glow', 'force-shadow'].some(cls => el.classList.contains(cls));
  const isWavy = el.classList.contains('wavy');
        if (!hasEffect || el.getAttribute('data-animated') === 'true') return;
  const isRainbow = el.classList.contains('rainbow');


  el.innerHTML = chars.map((c, i) => {
        const text = el.textContent;
    const hue = Math.round((i / total) * 360);
        const isJolt = el.classList.contains('jolt');
    const rainbowDelay = -((i / total) * 3).toFixed(2);
        const isWavy = el.classList.contains('wavy');
    const waveDelay    = ((i / total) * 1).toFixed(2);
        const isRainbow = el.classList.contains('rainbow');


    let anim = '';
        // Note: Pulse is handled by the container CSS now
    if (isWavy && isRainbow) anim = `wave 1s ease-in-out ${waveDelay}s infinite, hue-cycle 3s linear ${rainbowDelay}s infinite`;
        el.style.setProperty('animation-delay', '0s', 'important');  
    else if (isWavy)         anim = `wave 1s ease-in-out ${waveDelay}s infinite`;
          
    else if (isRainbow)      anim = `hue-cycle 3s linear ${rainbowDelay}s infinite`;
        let lastVariant = -1;


    const color = isRainbow ? `color: hsl(${hue}, 100%, 70%);` : '';
        const newHTML = text.split('').map((c, i) => {
    return `<span style="${color} animation: ${anim};">${c === ' ' ? '&nbsp;' : c}</span>`;
            let delays = [];
  }).join('');
            let classes = [];
}
           
            if (isWavy) delays.push((i * -0.15).toFixed(2) + 's');
            if (isRainbow) delays.push((i * -0.15).toFixed(2) + 's');
           
            if (isJolt) {
                let variant;
                do { variant = Math.floor(Math.random() * 3) + 1; } while (variant === lastVariant);
                lastVariant = variant;
                classes.push(`jolt-v${variant}`);
                delays.push((Math.random() * -0.35).toFixed(2) + 's');
            }


$(document).ready(function() {
            const content = (c === ' ') ? '&nbsp;' : c;
  document.querySelectorAll('.rainbow, .wavy').forEach(applyEffects);
            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);
        });
    });
})();

Latest revision as of 22:29, 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', 'pulse', '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');

        // Note: Pulse is handled by the container CSS now
        el.style.setProperty('animation-delay', '0s', '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) {
                let variant;
                do { variant = Math.floor(Math.random() * 3) + 1; } while (variant === lastVariant);
                lastVariant = variant;
                classes.push(`jolt-v${variant}`);
                delays.push((Math.random() * -0.35).toFixed(2) + 's');
            }

            const content = (c === ' ') ? '&nbsp;' : 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);
        });
    });
})();