Jump to content

MediaWiki:Common.js

From FC1
Revision as of 19:08, 17 March 2026 by DB (talk | contribs)

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 applyTextEffects($content) {
        $content.find('.text-animation-container').each(function () {
            const $el = $(this);
            if ($el.data('animated')) return; 

            const text = $el.text();
            const chars = text.split('');
            const isWavy = $el.hasClass('wavy');
            const isRainbow = $el.hasClass('rainbow');
            const isJolt = $el.hasClass('jolt'); // Added Jolt check

            const nodes = chars.map((char, i) => {
                const $span = $('<span>').text(char === ' ' ? '\u00A0' : char);
                let delays = [];

                if (isWavy) delays.push((i * -0.15).toFixed(2) + 's');
                if (isRainbow) delays.push((i * -0.15).toFixed(2) + 's');
                
                // Randomized delay for Jolt to make it look "glitchy"
                if (isJolt) {
                    delays.push((Math.random() * -0.5).toFixed(2) + 's');
                }

                if (delays.length) {
                    $span.css('animation-delay', delays.join(', '));
                }
                return $span;
            });

            $el.empty().append(nodes).data('animated', true);
        });
    }

    mw.hook('wikipage.content').add(applyTextEffects);
}());