MediaWiki:Common.js

From PsychoactiveWiki
Revision as of 06:13, 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
// Optional dynamic gradient cycling
document.addEventListener("DOMContentLoaded", () => {
  const body = document.body;

  // Array of trippy gradients
  const gradients = [
    "radial-gradient(circle at center, #ff00cc, #3333ff)",
    "radial-gradient(circle at center, #00ffcc, #cc00ff)",
    "radial-gradient(circle at center, #ffcc00, #cc00ff)",
    "radial-gradient(circle at center, #ff0066, #6600ff)"
  ];

  let index = 0;

  setInterval(() => {
    index = (index + 1) % gradients.length;
    body.style.background = gradients[index];
  }, 20000); // switch every 20s
});