MediaWiki:Common.js

From PsychoactiveWiki
Revision as of 06:16, 26 November 2025 by Arzachel (talk | contribs)
Jump to navigation Jump to search

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)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */

// Auto-preload template for Shared_Experiences new story form
mw.hook('wikipage.content').add(function () {
    // Only run on new-section add
    if (
        mw.config.get('wgPageName') === 'Shared_Experiences' &&
        mw.config.get('wgAction') === 'edit' &&
        new URLSearchParams(window.location.search).get('section') === 'new'
    ) {
        var textbox = document.getElementById('wpTextbox1');

        // Only insert if the textbox is empty
        if (textbox && textbox.value.trim() === '') {
            new mw.Api().get({
                action: 'parse',
                page: 'Template:SharedExperience/Preload',
                prop: 'wikitext',
                format: 'json'
            }).done(function (data) {
                // FIX: MediaWiki stores wikitext under ['*']
                textbox.value = data.parse.wikitext['*'];
            });
        }
    }
});

//aesthetic
/* Psychedelic prog-rock background controller
 * Uses CSS variables on :root to swap color palettes.
 */
mw.loader.using('jquery', function () {
    // Enable the psychedelic layout on every page.
    document.body.classList.add('psychedelic-wiki');

    var palettes = [
        {
            // Warm prism / Dark Side of the Moon–ish
            name: 'Dark Side',
            c1: '#ff7a18',
            c2: '#af002d',
            c3: '#00e6ff',
            c4: '#7cff6b',
            grid: 'rgba(255, 255, 255, 0.06)'
        },
        {
            // Hawkwind / Space Ritual neon
            name: 'Space Ritual',
            c1: '#ff008c',
            c2: '#ffcd00',
            c3: '#4af2c5',
            c4: '#7b5cff',
            grid: 'rgba(255, 255, 255, 0.05)'
        },
        {
            // Lava lamp oranges & blues
            name: 'Lava Lamp',
            c1: '#ff5f6d',
            c2: '#ffc371',
            c3: '#36d1dc',
            c4: '#5b86e5',
            grid: 'rgba(255, 255, 255, 0.04)'
        },
        {
            // Foresty / pastoral prog
            name: 'Forest Prog',
            c1: '#00c9ff',
            c2: '#92fe9d',
            c3: '#f5af19',
            c4: '#f12711',
            grid: 'rgba(255, 255, 255, 0.05)'
        }
    ];

    function applyPalette(palette) {
        var root = document.documentElement;
        root.style.setProperty('--psy-color-1', palette.c1);
        root.style.setProperty('--psy-color-2', palette.c2);
        root.style.setProperty('--psy-color-3', palette.c3);
        root.style.setProperty('--psy-color-4', palette.c4);
        root.style.setProperty('--psy-grid-color', palette.grid);
    }

    // Start on a random palette
    var currentIndex = Math.floor(Math.random() * palettes.length);
    applyPalette(palettes[currentIndex]);

    // Slowly cycle palettes (75 seconds per change)
    window.setInterval(function () {
        currentIndex = (currentIndex + 1) % palettes.length;
        applyPalette(palettes[currentIndex]);
    }, 75000);

    // Optional: toggle button to turn background on/off
    var $btn = $('<button>', {
        id: 'psy-bg-toggle',
        text: 'Psychedelic ↑'
    });

    function updateButtonLabel() {
        if (document.body.classList.contains('psychedelic-wiki-off')) {
            $btn.text('Psychedelic ↓');
        } else {
            $btn.text('Psychedelic ↑');
        }
    }

    $btn.on('click', function () {
        document.body.classList.toggle('psychedelic-wiki-off');
        updateButtonLabel();
    });

    $('body').append($btn);
    updateButtonLabel();
});