MediaWiki:Common.js
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 70s frame – dark mode + white text */
mw.loader.using('jquery', function () {
var body = document.body;
// Turn on the theme
body.classList.add('psy70');
// Grain overlay element
var grain = document.createElement('div');
grain.id = 'psy70-grain';
body.appendChild(grain);
// Color palettes with 70s prog/psych vibes
var palettes = [
{
name: 'Sunburst',
a: '#ff9a00',
b: '#ff005c',
c: '#7b5cff',
d: '#00f0ff'
},
{
name: 'Pastoral',
a: '#ffb347',
b: '#ff6a88',
c: '#48c6ef',
d: '#3fffa8'
},
{
name: 'Cosmic',
a: '#ff4b1f',
b: '#1fddff',
c: '#7f00ff',
d: '#ffe000'
},
{
name: 'Acid',
a: '#fdfc47',
b: '#24fe41',
c: '#ff00aa',
d: '#ff5f6d'
}
];
function applyPalette(p) {
var root = document.documentElement;
root.style.setProperty('--psy70-color-a', p.a);
root.style.setProperty('--psy70-color-b', p.b);
root.style.setProperty('--psy70-color-c', p.c);
root.style.setProperty('--psy70-color-d', p.d);
}
// Start with a random palette
var index = Math.floor(Math.random() * palettes.length);
applyPalette(palettes[index]);
// Slowly rotate palettes
window.setInterval(function () {
index = (index + 1) % palettes.length;
applyPalette(palettes[index]);
}, 70000); // ~70 seconds per switch
// Toggle button
var $btn = $('<button>', {
id: 'psy70-toggle',
text: 'Psy Frame: On'
});
function updateButton() {
if (body.classList.contains('psy70-off')) {
$btn.text('Psy Frame: Off');
} else {
$btn.text('Psy Frame: On');
}
}
$btn.on('click', function () {
body.classList.toggle('psy70-off');
updateButton();
});
$('body').append($btn);
updateButton();
});