MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| (6 intermediate revisions by the same user not shown) | |||
| Line 19: | Line 19: | ||
format: 'json' | format: 'json' | ||
}).done(function (data) { | }).done(function (data) { | ||
// | // MediaWiki stores wikitext under ['*'] | ||
textbox.value = data.parse.wikitext['*']; | textbox.value = data.parse.wikitext['*']; | ||
}); | }); | ||
| Line 26: | Line 26: | ||
}); | }); | ||
// | // ========================== | ||
// | // Aesthetic – Psychedelic 70s frame (with saved state) | ||
// ========================== | |||
/* Psychedelic 70s frame – dark mode + white text */ | |||
mw.loader.using('jquery', function () { | |||
var body = document.body; | |||
var STORAGE_KEY = 'psy70-frame-state'; // 'on' or 'off' | |||
// Turn on the theme base class | |||
body.classList.add('psy70'); | |||
// Restore saved on/off state from localStorage (default: ON) | |||
var storedState = null; | |||
try { | |||
storedState = window.localStorage.getItem(STORAGE_KEY); | |||
} catch (e) { | |||
// localStorage not available (privacy mode, etc.) – ignore | |||
} | |||
if (storedState === 'off') { | |||
body.classList.add('psy70-off'); | |||
} | |||
// 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'); | |||
// Save new state | |||
try { | |||
if (body.classList.contains('psy70-off')) { | |||
window.localStorage.setItem(STORAGE_KEY, 'off'); | |||
} else { | |||
window.localStorage.setItem(STORAGE_KEY, 'on'); | |||
} | |||
} catch (e) { | |||
// Ignore if localStorage fails | |||
} | |||
updateButton(); | |||
}); | |||
$('body').append($btn); | |||
updateButton(); | |||
}); | }); | ||
Latest revision as of 08:13, 27 November 2025
/* 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) {
// MediaWiki stores wikitext under ['*']
textbox.value = data.parse.wikitext['*'];
});
}
}
});
// ==========================
// Aesthetic – Psychedelic 70s frame (with saved state)
// ==========================
/* Psychedelic 70s frame – dark mode + white text */
mw.loader.using('jquery', function () {
var body = document.body;
var STORAGE_KEY = 'psy70-frame-state'; // 'on' or 'off'
// Turn on the theme base class
body.classList.add('psy70');
// Restore saved on/off state from localStorage (default: ON)
var storedState = null;
try {
storedState = window.localStorage.getItem(STORAGE_KEY);
} catch (e) {
// localStorage not available (privacy mode, etc.) – ignore
}
if (storedState === 'off') {
body.classList.add('psy70-off');
}
// 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');
// Save new state
try {
if (body.classList.contains('psy70-off')) {
window.localStorage.setItem(STORAGE_KEY, 'off');
} else {
window.localStorage.setItem(STORAGE_KEY, 'on');
}
} catch (e) {
// Ignore if localStorage fails
}
updateButton();
});
$('body').append($btn);
updateButton();
});